Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ofeli: migrate to Conan v2, add v5.1.0 #18952

Merged
merged 10 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
82 changes: 82 additions & 0 deletions recipes/ofeli/4.x/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import os

from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import check_min_cppstd
from conan.tools.files import chdir, copy, get
from conan.tools.gnu import Autotools, AutotoolsToolchain
from conan.tools.layout import basic_layout

required_conan_version = ">=1.53.0"


class OfeliConan(ConanFile):
name = "ofeli"
description = "An Object Finite Element Library"
license = "LGPL-3.0-or-later"
url = "https://github.com/conan-io/conan-center-index"
homepage = "http://ofeli.org/index.html"
topics = ("finite-element", "finite-element-library", "finite-element-analysis", "finite-element-solver")

package_type = "static-library"
settings = "os", "arch", "compiler", "build_type"
options = {
"fPIC": [True, False],
}
default_options = {
"fPIC": True,
}

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def layout(self):
basic_layout(self, src_folder="src")

def validate(self):
if self.settings.os not in ["Linux", "FreeBSD"]:
raise ConanInvalidConfiguration("Ofeli only supports Linux")
if self.settings.compiler != "gcc":
raise ConanInvalidConfiguration("Ofeli only supports GCC")
if self.settings.compiler.cppstd:
check_min_cppstd(self, 11)
if self.settings.compiler.libcxx != "libstdc++11":
raise ConanInvalidConfiguration("Ofeli only supports libstdc++'s new ABI")

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def generate(self):
tc = AutotoolsToolchain(self)
config = 'release' if self.settings.build_type == 'Release' else 'debug'
tc.configure_args.append(f"--enable-{config}")
tc.generate()

def build(self):
with chdir(self, self.source_folder):
autotools = Autotools(self)
autotools.configure()
autotools.make()

def package(self):
copy(self, "*.h",
dst=os.path.join(self.package_folder, "include"),
src=os.path.join(self.source_folder, "include"))
copy(self, "*libofeli.a",
dst=os.path.join(self.package_folder, "lib"),
src=os.path.join(self.source_folder, "src"))
copy(self, "*.md",
dst=os.path.join(self.package_folder, "res"),
src=os.path.join(self.source_folder, "material"))
copy(self, "COPYING",
dst=os.path.join(self.package_folder, "licenses"),
src=os.path.join(self.source_folder, "doc"))

def package_info(self):
self.cpp_info.libs = ["ofeli"]
res_path = os.path.join(self.package_folder, "res")
self.runenv_info.define("OFELI_PATH_MATERIAL", res_path)

# TODO: Legacy, to be removed on Conan 2.0
self.env_info.OFELI_PATH_MATERIAL.append(res_path)
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
cmake_minimum_required(VERSION 3.4)
cmake_minimum_required(VERSION 3.15)
project(test_package LANGUAGES CXX)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

find_package(ofeli CONFIG REQUIRED)
find_package(ofeli REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} ofeli::ofeli)
Expand Down
26 changes: 26 additions & 0 deletions recipes/ofeli/4.x/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
test_type = "explicit"

def requirements(self):
self.requires(self.tested_reference_str)

def layout(self):
cmake_layout(self)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindir, "test_package")
self.run(bin_path, env="conanrun")
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
==============================================================================

Copyright (C) 1998 - 2015 Rachid Touzani

This file is part of OFELI.

OFELI is free software: you can redistribute it and/or modify
Expand Down
8 changes: 8 additions & 0 deletions recipes/ofeli/4.x/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.15)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/
${CMAKE_CURRENT_BINARY_DIR}/test_package/)
4 changes: 4 additions & 0 deletions recipes/ofeli/5.x/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"5.1.0":
url: "https://github.com/rtouzani/ofeli/archive/0e66d0e5a38b209ee79eab0daf7686562b753536.tar.gz"
sha256: "a2e4e62d912d05e55001a9be7c5c4741a7b8773a399acbbe558bdca0d60d430b"
88 changes: 88 additions & 0 deletions recipes/ofeli/5.x/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import os

from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout
from conan.tools.env import VirtualBuildEnv
from conan.tools.files import copy, get, rmdir, replace_in_file, rename
from conan.tools.microsoft import is_msvc

required_conan_version = ">=1.53.0"


class OfeliConan(ConanFile):
name = "ofeli"
description = "An Object Finite Element Library"
license = "LGPL-3.0-or-later"
url = "https://github.com/conan-io/conan-center-index"
homepage = "http://ofeli.org/index.html"
topics = ("finite-element", "finite-element-library", "finite-element-analysis", "finite-element-solver")

package_type = "static-library"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not find a reference offering only static library: https://github.com/rtouzani/ofeli/blob/master/src/CMakeLists.txt

Please, point where you found it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A shared build fails with:

ofelia3f8f09b1f9b5/p/lib/libofeli.so: undefined reference to `OFELI::LocalVect<unsigned long, 3ul>::~LocalVect()'
ofelia3f8f09b1f9b5/p/lib/libofeli.so: undefined reference to `OFELI::LocalVect<unsigned long, 2ul>::~LocalVect()'
ofelia3f8f09b1f9b5/p/lib/libofeli.so: undefined reference to `OFELI::Muscl::setReconstruction(OFELI::Vect<double> const&, OFELI::Vect<double>&, OFELI::Vect<double>&, unsigned long)'
ofelia3f8f09b1f9b5/p/lib/libofeli.so: undefined reference to `virtual thunk to OFELI::LaplaceDG2DP1::build()'
ofelia3f8f09b1f9b5/p/lib/libofeli.so: undefined reference to `OFELI::LocalVect<double, 2ul>::get()'
ofelia3f8f09b1f9b5/p/lib/libofeli.so: undefined reference to `OFELI::LocalVect<double, 3ul>::LocalVect()'
ofelia3f8f09b1f9b5/p/lib/libofeli.so: undefined reference to `OFELI::LocalVect<unsigned long, 3ul>::LocalVect()'
ofelia3f8f09b1f9b5/p/lib/libofeli.so: undefined reference to `OFELI::LocalVect<unsigned long, 2ul>::LocalVect()'
ofelia3f8f09b1f9b5/p/lib/libofeli.so: undefined reference to `OFELI::LocalVect<double, 3ul>::operator()(unsigned long)'
ofelia3f8f09b1f9b5/p/lib/libofeli.so: undefined reference to `OFELI::LocalVect<double, 2ul>::operator=(double const&)'
ofelia3f8f09b1f9b5/p/lib/libofeli.so: undefined reference to `OFELI::LocalVect<double, 3ul>::get()'
ofelia3f8f09b1f9b5/p/lib/libofeli.so: undefined reference to `OFELI::LocalVect<double, 3ul>::~LocalVect()'
ofelia3f8f09b1f9b5/p/lib/libofeli.so: undefined reference to `OFELI::LaplaceDG2DP1::build()'
ofelia3f8f09b1f9b5/p/lib/libofeli.so: undefined reference to `OFELI::LocalVect<double, 1ul>::get()'
ofelia3f8f09b1f9b5/p/lib/libofeli.so: undefined reference to `OFELI::LocalVect<double, 2ul>::operator()(unsigned long)'
ofelia3f8f09b1f9b5/p/lib/libofeli.so: undefined reference to `OFELI::LocalVect<double, 3ul>::operator=(double const&)'

on GCC.

settings = "os", "arch", "compiler", "build_type"
options = {
"fPIC": [True, False],
}
default_options = {
"fPIC": True,
}

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def layout(self):
cmake_layout(self, src_folder="src")

def validate(self):
if self.settings.compiler.cppstd:
check_min_cppstd(self, 11)
if self.settings.compiler in ["clang", "apple-clang"] or is_msvc(self):
# Clang fails with
# include/linear_algebra/LocalVect_impl.h:251:42: error: cannot initialize return object of type 'OFELI::Element *' with an lvalue of type 'const OFELI::Element *'
# MSVC fails with a lot of errors
# https://c3i.jfrog.io/c3i/misc/summary.html?json=https://c3i.jfrog.io/c3i/misc/logs/pr/18952/12-windows-visual_studio/ofeli/5.1.0/summary.json
raise ConanInvalidConfiguration(f"{self.settings.compiler} is not supported due to compilation errors")

def build_requirements(self):
self.tool_requires("cmake/[>=3.16 <4]")

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def generate(self):
env = VirtualBuildEnv(self)
env.generate()
tc = CMakeToolchain(self)
tc.generate()

def _patch_sources(self):
cmakelists = os.path.join(self.source_folder, "CMakeLists.txt")
replace_in_file(self, cmakelists, "add_subdirectory (demos)", "")
replace_in_file(self, cmakelists, "add_subdirectory (util)", "")
# Fix incorrect use of add_definitions() for build flags
replace_in_file(self, cmakelists, "add_definitions", "add_compile_options")
# Fix -fPIC support
replace_in_file(self, cmakelists, " -fPIE", "")

def build(self):
self._patch_sources()
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
copy(self, "COPYING", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
cmake = CMake(self)
cmake.install()
rename(self, os.path.join(self.package_folder, "share", "ofeli", "material"),
os.path.join(self.package_folder, "res"))
rmdir(self, os.path.join(self.package_folder, "share"))


def package_info(self):
self.cpp_info.libs = ["ofeli"]
self.cpp_info.includedirs = [os.path.join("include", "ofeli")]
res_path = os.path.join(self.package_folder, "res")
self.runenv_info.define_path("OFELI_PATH_MATERIAL", res_path)
8 changes: 8 additions & 0 deletions recipes/ofeli/5.x/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.15)
project(test_package LANGUAGES CXX)

find_package(ofeli REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} ofeli::ofeli)
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 11)
26 changes: 26 additions & 0 deletions recipes/ofeli/5.x/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
test_type = "explicit"

def requirements(self):
self.requires(self.tested_reference_str)

def layout(self):
cmake_layout(self)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindir, "test_package")
self.run(bin_path, env="conanrun")
76 changes: 76 additions & 0 deletions recipes/ofeli/5.x/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*==============================================================================

O F E L I

Object Finite Element Library

==============================================================================

Copyright (C) 1998 - 2015 Rachid Touzani

This file is part of OFELI.

OFELI is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

OFELI is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with OFELI. If not, see <http://www.gnu.org/licenses/>.

==============================================================================

An example of a Finite Element Code using OFELI

Solution of a 1-D Elliptic problem using P1 Finite elements

==============================================================================*/

#include "OFELI.h"
using namespace OFELI;

int main(int argc, char *argv[])
{
double L=1;
int N=10;

/// Read and output mesh data
banner();
if (argc>1)
N = atoi(argv[1]);
Mesh ms(L,N);
int NbN = N+1;

// Declare problem data (matrix, rhs, boundary conditions, body forces)
TrMatrix<double> A(NbN);
Vect<double> b(ms);
b.set("16*pi*pi*sin(4*pi*x)");

// Build matrix and R.H.S.
double h = L/double(N);
b *= h;
for (int i=2; i<NbN; i++) {
A(i,i ) = 2./h;
A(i,i+1) = -1./h;
A(i,i-1) = -1./h;
}

// Impose boundary conditions
A(1,1) = 1.; A(1,2) = 0.; b(1) = 0;
A(NbN,NbN) = 1.; A(NbN-1,NbN) = 0.; b(NbN) = 0;

// Solve the linear system of equations
A.solve(b);

// Output solution and error
cout << "\nSolution:\n" << b;
Vect<double> sol(ms);
sol.set("sin(4*pi*x)");
cout << "Error = " << (b-sol).getNormMax() << endl;
return 0;
}
7 changes: 0 additions & 7 deletions recipes/ofeli/all/CMakeLists.txt

This file was deleted.

Loading