diff --git a/docs/src/get-started/installation.rst b/docs/src/get-started/installation.rst index 62e4571a4..da6bea8f7 100644 --- a/docs/src/get-started/installation.rst +++ b/docs/src/get-started/installation.rst @@ -83,6 +83,13 @@ The build and installation can be configures with a few cmake options, using | FEATOMIC_FETCH_METATENSOR | Automatically fetch, build and install | OFF | | | metatensor (a dependency of featomic) | | +--------------------------------------+-----------------------------------------------+----------------+ +| FEATOMIC_USE_STATIC_METATENSOR | Link against the static version of | OFF | +| | metatensor. You should only use this if you | | +| | know your code will never be loaded with | | +| | together with another library using | | +| | metatensor, for example if you are building | | +| | a fully static executable. | | ++--------------------------------------+-----------------------------------------------+----------------+ Using the Rust library ---------------------- diff --git a/featomic/CMakeLists.txt b/featomic/CMakeLists.txt index f5e334208..1d04698d9 100644 --- a/featomic/CMakeLists.txt +++ b/featomic/CMakeLists.txt @@ -57,6 +57,7 @@ set(PROJECT_VERSION ${FEATOMIC_FULL_VERSION}) # an installed library (see cmake/featomic-config.cmake) option(BUILD_SHARED_LIBS "Use a shared library by default instead of a static one" ON) option(FEATOMIC_INSTALL_BOTH_STATIC_SHARED "Install both shared and static libraries" ON) +option(FEATOMIC_USE_STATIC_METATENSOR "Link featomic with the static metatensor library instead of the shared one" OFF) set(BIN_INSTALL_DIR "bin" CACHE PATH "Path relative to CMAKE_INSTALL_PREFIX where to install binaries/DLL") set(LIB_INSTALL_DIR "lib" CACHE PATH "Path relative to CMAKE_INSTALL_PREFIX where to install libraries") @@ -384,8 +385,14 @@ else() endif() add_dependencies(cargo-build-featomic metatensor) -target_link_libraries(featomic::shared INTERFACE metatensor::shared) -target_link_libraries(featomic::static INTERFACE metatensor::shared) + +if (FEATOMIC_USE_STATIC_METATENSOR) + target_link_libraries(featomic::shared INTERFACE metatensor::static) + target_link_libraries(featomic::static INTERFACE metatensor::static) +else() + target_link_libraries(featomic::shared INTERFACE metatensor::shared) + target_link_libraries(featomic::static INTERFACE metatensor::shared) +endif() #------------------------------------------------------------------------------# # Installation configuration diff --git a/featomic/Cargo.toml b/featomic/Cargo.toml index a6dfe1ff8..cc73b0b9a 100644 --- a/featomic/Cargo.toml +++ b/featomic/Cargo.toml @@ -35,7 +35,8 @@ rayon-core = "=1.12" log = "0.4" once_cell = "1" -indexmap = "2" +# the last version that supports Rust 1.74 +indexmap = "=2.11.4" thread_local = "1.1" time-graph = "0.3.0" @@ -47,6 +48,11 @@ chemfiles = { version = "0.10", optional = true, features = ["build-from-sources approx = "0.5" +# the last versions that supports Rust 1.74 +serde_spanned = "=1.0.1" +toml_datetime = "=0.7.1" +toml_parser = "=1.0.2" + [build-dependencies] cbindgen = { version = "0.29", default-features = false } fs_extra = "1" diff --git a/featomic/cmake/featomic-config.in.cmake b/featomic/cmake/featomic-config.in.cmake index 67db28f3e..5a22e6879 100644 --- a/featomic/cmake/featomic-config.in.cmake +++ b/featomic/cmake/featomic-config.in.cmake @@ -8,6 +8,10 @@ endif() enable_language(CXX) +if(NOT DEFINED FEATOMIC_USE_STATIC_METATENSOR) + set(FEATOMIC_USE_STATIC_METATENSOR OFF CACHE BOOL "Link featomic with static metatensor by default") +endif() + get_filename_component(FEATOMIC_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/@PACKAGE_RELATIVE_PATH@" ABSOLUTE) if (WIN32) @@ -38,7 +42,12 @@ if (@FEATOMIC_INSTALL_BOTH_STATIC_SHARED@ OR @BUILD_SHARED_LIBS@) INTERFACE_INCLUDE_DIRECTORIES ${FEATOMIC_INCLUDE} BUILD_VERSION "@FEATOMIC_FULL_VERSION@" ) - target_link_libraries(featomic::shared INTERFACE metatensor::shared) + + if (FEATOMIC_USE_STATIC_METATENSOR) + target_link_libraries(featomic::shared INTERFACE metatensor::static) + else() + target_link_libraries(featomic::shared INTERFACE metatensor::shared) + endif() target_compile_features(featomic::shared INTERFACE cxx_std_17) @@ -67,7 +76,12 @@ if (@FEATOMIC_INSTALL_BOTH_STATIC_SHARED@ OR NOT @BUILD_SHARED_LIBS@) INTERFACE_LINK_LIBRARIES "@CARGO_DEFAULT_LIBRARIES@" BUILD_VERSION "@FEATOMIC_FULL_VERSION@" ) - target_link_libraries(featomic::static INTERFACE metatensor::shared) + + if (FEATOMIC_USE_STATIC_METATENSOR) + target_link_libraries(featomic::static INTERFACE metatensor::static) + else() + target_link_libraries(featomic::static INTERFACE metatensor::shared) + endif() target_compile_features(featomic::static INTERFACE cxx_std_17) endif() diff --git a/featomic/tests/cmake-project/CMakeLists.txt b/featomic/tests/cmake-project/CMakeLists.txt index d06d82361..679e86aef 100644 --- a/featomic/tests/cmake-project/CMakeLists.txt +++ b/featomic/tests/cmake-project/CMakeLists.txt @@ -11,7 +11,13 @@ string(REGEX REPLACE "([0-9]*)\\.([0-9]*).*" "\\1.\\2" REQUIRED_FEATOMIC_VERSION find_package(featomic ${REQUIRED_FEATOMIC_VERSION} REQUIRED) add_executable(c-main main.c) -target_link_libraries(c-main featomic) +target_link_libraries(c-main featomic::shared) + +add_executable(c-main-static main.c) +target_link_libraries(c-main-static featomic::static) add_executable(cxx-main main.cpp) -target_link_libraries(cxx-main featomic) +target_link_libraries(cxx-main featomic::shared) + +add_executable(cxx-main-static main.cpp) +target_link_libraries(cxx-main-static featomic::static)