diff --git a/recipes/cantera/all/FindCantera.cmake b/recipes/cantera/all/FindCantera.cmake new file mode 100644 index 00000000000000..f5ed973e28bf33 --- /dev/null +++ b/recipes/cantera/all/FindCantera.cmake @@ -0,0 +1,60 @@ +# cantera-conan-wrapper +# +# SPDX-FileCopyrightText: Copyright 2023 German Aerospace Center (DLR) +# SPDX-FileContributor: David Nelles + +#Variable definition as proposed in +#https://cmake.org/cmake/help/book/mastering-cmake/chapter/Finding%20Packages.html#built-in-find-modules + +set(Cantera_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}) +mark_as_advanced(Cantera_ROOT_DIR) + +# Look for the header file. +find_path(Cantera_INCLUDE_DIRS NAMES cantera/thermo.h) +mark_as_advanced(Cantera_INCLUDE_DIRS) + +# Look for the library +find_library(Cantera_LIBRARIES NAMES + cantera_shared + HINTS "${CMAKE_CURRENT_LIST_DIR}/bin" + ) +mark_as_advanced(Cantera_LIBRARIES) + +# Look for the shared library +# Since Cantera is a library and not a executable, this contains the shared labrary files (so and dll) +find_file(Cantera_EXECUTABLE NAMES + cantera_shared.dll + libcantera_shared.so.3 + HINTS "${CMAKE_CURRENT_LIST_DIR}/bin" "${CMAKE_CURRENT_LIST_DIR}/lib" + ) +mark_as_advanced(Cantera_EXECUTABLE) + +# Look vor version number +if(Cantera_INCLUDE_DIRS) + set(CANTERA_VERSION_FILE "${Cantera_INCLUDE_DIRS}/cantera/base/config.h") + if(EXISTS "${CANTERA_VERSION_FILE}") + file(STRINGS "${CANTERA_VERSION_FILE}" cantera_version_str REGEX "^#define[\r\n\t ]+CANTERA_VERSION[\r\n\t ]+\".*\"") + string(REGEX REPLACE "^#define[\r\n\t ]+CANTERA_VERSION[\r\n\t ]+\"([^\"]*)\".*" "\\1" Cantera_VERSION "${cantera_version_str}") + unset(cantera_version_str) + endif() +endif() + +set(Cantera_VERSION_${Cantera_VERSION} TRUE) +mark_as_advanced(Cantera_VERSION_${Cantera_VERSION}) + +# handle the QUIETLY and REQUIRED arguments and set CANTERA_FOUND to TRUE if +# all listed variables are TRUE +include(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(Cantera + REQUIRED_VARS Cantera_LIBRARIES Cantera_INCLUDE_DIRS + VERSION_VAR Cantera_VERSION + ) + +if(Cantera_FOUND) + add_library(Cantera::cantera SHARED IMPORTED) + set_target_properties(Cantera::cantera PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${Cantera_INCLUDE_DIRS} + IMPORTED_LOCATION ${Cantera_EXECUTABLE} + IMPORTED_IMPLIB ${Cantera_LIBRARIES} + ) +endif(Cantera_FOUND) diff --git a/recipes/cantera/all/conandata.yml b/recipes/cantera/all/conandata.yml new file mode 100644 index 00000000000000..2f4efb5f5e56cd --- /dev/null +++ b/recipes/cantera/all/conandata.yml @@ -0,0 +1,4 @@ +sources: + "3.0.0": + url: "https://github.com/Cantera/cantera/archive/refs/tags/v3.0.0.tar.gz" + sha256: "6d17cdef21dae9deaf91351260b68ccf7e264c37c6030c9d4bf26a2cefb2b905" diff --git a/recipes/cantera/all/conanfile.py b/recipes/cantera/all/conanfile.py new file mode 100644 index 00000000000000..d59f4c2bbb5ad5 --- /dev/null +++ b/recipes/cantera/all/conanfile.py @@ -0,0 +1,89 @@ +from conan import ConanFile +from conan.tools.files import get + +class canteraRecipe(ConanFile): + name = "cantera" + tool_requires="scons/4.3.0" + + # Metadata + author = ("David G. Goodwin", "Harry K. Moffat", "Ingmar Schoegl", "Raymond L. Speth", "Bryan W. Weber") + url = "https://github.com/Cantera/cantera" + description = "Cantera is an open-source collection of object-oriented software tools for problems involving chemical kinetics, thermodynamics, and transport processes." + license = "LicenseRef-Cantera" + + # Binary configuration + settings = "os", "compiler", "build_type", "arch" + + # Sources are located in the same place as this recipe, copy them to the recipe + exports_sources = "cantera/SConstruct", "cantera/src/*", "cantera/include/*", "cantera/site_scons/*", "cantera/interfaces/*", "cantera/platform/*", "cantera/ext/*", "cantera/data/*", "cantera/License.txt", "FindCantera.cmake", "Kerosine5Step.yaml" + + @property + def _min_cppstd(self): + return 17 + + def requirements(self): + self.requires("boost/1.83.0", headers=True, libs=False, build=False, visible=False) + self.requires("fmt/10.1.1") + self.requires("yaml-cpp/0.7.0") + self.requires("eigen/3.4.0") + self.requires("sundials/5.4.0") + + def source(self): + get(self, **self.conan_data["sources"][self.version], destination=self.source_folder, strip_root=True) + + def generate(self): + self.scons_extra_inc_dirs = \ + self.dependencies["fmt"].cpp_info.includedirs +\ + self.dependencies["yaml-cpp"].cpp_info.includedirs +\ + self.dependencies["eigen"].cpp_info.includedirs + + self.scons_extra_lib_dirs = \ + self.dependencies["fmt"].cpp_info.libdirs +\ + self.dependencies["yaml-cpp"].cpp_info.libdirs +\ + self.dependencies["eigen"].cpp_info.libdirs + + self.scons_sundials_include = self.dependencies["sundials"].cpp_info.includedirs[0] + self.scons_sundials_libdir = self.dependencies["sundials"].cpp_info.libdirs[0] + + self.scons_boost_inc_dir = self.dependencies["boost"].cpp_info.includedirs[0] + + def layout(self): + self.folders.source = "." + self.folders.build = "build" + self.cpp.source.includedirs = ["include"] + + def build(self): + + opt = "build -j4 " \ + "prefix={} ".format(self.package_folder) +\ + "libdirname=lib " \ + "python_package=none " \ + "f90_interface=n " \ + "googletest=none " \ + "versioned_shared_library=yes " \ + "extra_inc_dirs={} ".format(';'.join(self.scons_extra_inc_dirs)) +\ + "extra_lib_dirs={} ".format(';'.join(self.scons_extra_lib_dirs)) +\ + "boost_inc_dir={} ".format(self.scons_boost_inc_dir) +\ + "sundials_include={} ".format(self.scons_sundials_include) +\ + "sundials_libdir={} ".format(self.scons_sundials_libdir) + + if self.settings.os == "Windows": + opt = opt + "toolchain=msvc " + cd_modifier = "/d" + else: + cd_modifier = "" + + if self.settings.build_type == "Debug": + opt = opt + "optimize=no " + else: + opt = opt + "debug=no " + + self.run("cd {} {} && scons {}".format(cd_modifier, self.source_folder, opt)) + + def package(self): + if self.settings.os == "Windows": + cd_modifier = "/d" + else: + cd_modifier = "" + + self.run("cd {} {} && scons install".format(cd_modifier, self.source_folder)) diff --git a/recipes/cantera/all/test_package/CMakeLists.txt b/recipes/cantera/all/test_package/CMakeLists.txt new file mode 100644 index 00000000000000..8bb21a3cd9c1ec --- /dev/null +++ b/recipes/cantera/all/test_package/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.8) +project(test_package CXX) + +find_package(cantera REQUIRED) + +add_executable(test_package test_package.cpp) +target_link_libraries(test_package PUBLIC cantera::cantera) +target_compile_features(test_package PRIVATE cxx_std_11) diff --git a/recipes/cantera/all/test_package/conanfile.py b/recipes/cantera/all/test_package/conanfile.py new file mode 100644 index 00000000000000..d94ba2fb11ca88 --- /dev/null +++ b/recipes/cantera/all/test_package/conanfile.py @@ -0,0 +1,27 @@ +import os + +from conan import ConanFile +from conan.tools.build import can_run +from conan.tools.cmake import CMake, cmake_layout + + +class TestPackage(ConanFile): + settings = "os", "compiler", "build_type", "arch" + generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv" + test_type = "explicit" + + def layout(self): + cmake_layout(self) + + def requirements(self): + self.requires(self.tested_reference_str) + + 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.bindirs[0], "test_package") + self.run(bin_path, env="conanrun") diff --git a/recipes/cantera/all/test_package/test_package.cpp b/recipes/cantera/all/test_package/test_package.cpp new file mode 100644 index 00000000000000..fdf23ea1c97ce7 --- /dev/null +++ b/recipes/cantera/all/test_package/test_package.cpp @@ -0,0 +1,10 @@ +#include +#include + +int main() +{ + const auto canteraVersion = Cantera::version() + std::cout << "Cantera version: " << canteraVersion << "\n"; + + return 0; +} diff --git a/recipes/cantera/all/test_v1_package/CMakeLists.txt b/recipes/cantera/all/test_v1_package/CMakeLists.txt new file mode 100644 index 00000000000000..2a5d8d4bb4f8b8 --- /dev/null +++ b/recipes/cantera/all/test_v1_package/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.8) +project(test_package CXX) + +find_package(canary REQUIRED) + +add_executable(test_package test_package.cpp) +target_link_libraries(test_package PUBLIC cantera::cantera) +target_compile_features(test_package PRIVATE cxx_std_11) diff --git a/recipes/cantera/all/test_v1_package/conanfile.py b/recipes/cantera/all/test_v1_package/conanfile.py new file mode 100644 index 00000000000000..f8bae5c00ce0a3 --- /dev/null +++ b/recipes/cantera/all/test_v1_package/conanfile.py @@ -0,0 +1,18 @@ +import os + +from conans import CMake, ConanFile, tools + + +class TestPackage(ConanFile): + settings = "os", "compiler", "build_type", "arch" + generators = "cmake", "cmake_find_package" + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def test(self): + if not tools.cross_building(self): + bin_path = os.path.join(".", "test_package") + self.run(bin_path, run_environment=True) diff --git a/recipes/cantera/all/test_v1_package/test_package.cpp b/recipes/cantera/all/test_v1_package/test_package.cpp new file mode 100644 index 00000000000000..fdf23ea1c97ce7 --- /dev/null +++ b/recipes/cantera/all/test_v1_package/test_package.cpp @@ -0,0 +1,10 @@ +#include +#include + +int main() +{ + const auto canteraVersion = Cantera::version() + std::cout << "Cantera version: " << canteraVersion << "\n"; + + return 0; +} diff --git a/recipes/cantera/config.yml b/recipes/cantera/config.yml new file mode 100644 index 00000000000000..05ef112e8081d4 --- /dev/null +++ b/recipes/cantera/config.yml @@ -0,0 +1,3 @@ +versions: + "v3.0.0": + folder: all