diff --git a/CHANGELOG.md b/CHANGELOG.md index 210e3e6914..6232dfc1d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Current develop ### Added (new features/APIs/variables/...) +- [[PR#339]](https://github.com/lanl/singularity-eos/pull/339) Added COMPONENTS to singularity-eos CMake install, allowing to select a minimal subset needed e.g. for Fortran bindings only - [[PR#336]](https://github.com/lanl/singularity-eos/pull/336) Included code and documentation for a full, temperature consistent, Mie-Gruneisen EOS based on a pressure power law expansion in eta = 1-V/V0. PowerMG. ### Fixed (Repair bugs, etc) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4780fcf7ba..86cc96ddab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -135,12 +135,25 @@ include(singularity-eos/kokkos) include(singularity-eos/spiner) include(singularity-eos/ports-of-call) -add_library(singularity-eos) +add_library(singularity-eos INTERFACE) add_library(singularity-eos::singularity-eos ALIAS singularity-eos) -# ? -target_include_directories(singularity-eos - PUBLIC $) +# interface target to collect runtime libraries +add_library(singularity-eos_Common INTERFACE) +add_library(singularity-eos::singularity-eos_Common ALIAS singularity-eos_Common) + +add_library(singularity-eos_Interface INTERFACE) +add_library(singularity-eos::singularity-eos_Interface ALIAS singularity-eos_Interface) +target_link_libraries(singularity-eos_Interface INTERFACE singularity-eos_Common) +target_link_libraries(singularity-eos INTERFACE singularity-eos_Interface) + +if(SINGULARITY_BUILD_CLOSURE) + add_library(singularity-eos_Library) + set_target_properties(singularity-eos_Library PROPERTIES OUTPUT_NAME singularity-eos) + add_library(singularity-eos::singularity-eos_Library ALIAS singularity-eos_Library) + target_link_libraries(singularity-eos_Library INTERFACE singularity-eos_Common) + target_link_libraries(singularity-eos INTERFACE singularity-eos_Library) +endif() # ------------------------------------------------------------------------------# # Compiler & language setup @@ -241,21 +254,21 @@ endif() # defines if(SINGULARITY_USE_SINGLE_LOGS) - target_compile_definitions(singularity-eos PUBLIC SINGULARITY_USE_SINGLE_LOGS) + target_compile_definitions(singularity-eos_Interface INTERFACE SINGULARITY_USE_SINGLE_LOGS) endif() if(SINGULARITY_USE_HIGH_RISK_MATH) - target_compile_definitions(singularity-eos - PUBLIC SINGULARITY_USE_HIGH_RISK_MATH) + target_compile_definitions(singularity-eos_Interface + INTERFACE SINGULARITY_USE_HIGH_RISK_MATH) endif() if(SINGULARITY_TEST_SESAME) - target_compile_definitions(singularity-eos PRIVATE SINGULARITY_TEST_SESAME) + target_compile_definitions(singularity-eos_Interface INTERFACE SINGULARITY_TEST_SESAME) endif() if(SINGULARITY_BUILD_CLOSURE) - target_compile_definitions(singularity-eos PRIVATE SINGULARITY_BUILD_CLOSURE) + target_compile_definitions(singularity-eos_Interface INTERFACE SINGULARITY_BUILD_CLOSURE) endif() if(SINGULARITY_USE_HELMHOLTZ) - target_compile_definitions(singularity-eos PUBLIC SINGULARITY_USE_HELMHOLTZ) + target_compile_definitions(singularity-eos_Interface INTERFACE SINGULARITY_USE_HELMHOLTZ) endif() # ------------------------------------------------------------------------------# @@ -274,12 +287,12 @@ endif() # cases. if(SINGULARITY_USE_SPINER_WITH_HDF5) - singularity_enable_hdf5(singularity-eos) + singularity_enable_hdf5(singularity-eos_Common) endif() if(SINGULARITY_USE_EOSPAC) # NB This will add the `eospac-wrapper` directory. - singularity_enable_eospac(singularity-eos) + singularity_enable_eospac(singularity-eos_Common) endif() if(SINGULARITY_SUBMODULE_MODE) @@ -320,23 +333,23 @@ else() endif() -singularity_enable_mpark_variant(singularity-eos) -singularity_enable_ports_of_call(singularity-eos) +singularity_enable_mpark_variant(singularity-eos_Interface) +singularity_enable_ports_of_call(singularity-eos_Interface) if(SINGULARITY_USE_SPINER) - singularity_enable_spiner(singularity-eos) + singularity_enable_spiner(singularity-eos_Interface) # if(SINGULARITY_USE_SPINER_WITH_HDF5) - # singularity_enable_hdf5(singularity-eos) endif() + # singularity_enable_hdf5(singularity-eos_Interface) endif() endif() if(SINGULARITY_USE_KOKKOS) - singularity_enable_kokkos(singularity-eos) + singularity_enable_kokkos(singularity-eos_Interface) if(SINGULARITY_USE_KOKKOSKERNELS) - singularity_enable_kokkoskernels(singularity-eos) + singularity_enable_kokkoskernels(singularity-eos_Interface) endif() endif() if(SINGULARITY_USE_EIGEN) - singularity_enable_eigen(singularity-eos) + singularity_enable_eigen(singularity-eos_Interface) endif() # ----------------------------------------------------------------------------# @@ -387,49 +400,51 @@ endforeach() # TODO(JMM): Kind of nice to have? get_property(eos_headers GLOBAL PROPERTY EOS_HEADERS) -get_property(eos_srcs GLOBAL PROPERTY EOS_SRCS) +target_sources(singularity-eos_Interface PRIVATE ${eos_headers}) message(VERBOSE "EOS Headers:\n\t${eos_headers}") -message(VERBOSE "EOS Sources:\n\t${eos_srcs}") -target_sources(singularity-eos PRIVATE ${eos_srcs} ${eos_headers}) +if(SINGULARITY_BUILD_CLOSURE) + get_property(eos_srcs GLOBAL PROPERTY EOS_SRCS) + target_sources(singularity-eos_Library PRIVATE ${eos_srcs}) + message(VERBOSE "EOS Library Sources:\n\t${eos_srcs}") +endif() if(SINGULARITY_USE_FORTRAN) # Turn on preprocessor for fortran files - set_target_properties(singularity-eos PROPERTIES Fortran_PREPROCESS ON) + set_target_properties(singularity-eos_Library PROPERTIES Fortran_PREPROCESS ON) # make sure .mods are placed in build path, and installed along with includes - set_target_properties(singularity-eos PROPERTIES Fortran_MODULE_DIRECTORY + set_target_properties(singularity-eos_Library PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/fortran) target_include_directories( - singularity-eos INTERFACE $ + singularity-eos_Library INTERFACE $ $) - set_target_properties(singularity-eos PROPERTIES Fortran_PREPROCESS ON) endif() # SINGULARITY_USE_FORTRAN -target_include_directories( - singularity-eos PUBLIC $ - $) -target_include_directories( - singularity-eos PUBLIC $) +target_include_directories(singularity-eos_Interface INTERFACE + $ + $ + $ +) get_property(plugin_include_paths GLOBAL PROPERTY PLUGIN_INCLUDE_PATHS) foreach(path ${plugin_include_paths}) - target_include_directories(singularity-eos PUBLIC $) + target_include_directories(singularity-eos_Interface INTERFACE $) endforeach() # plug in collected includes/libs/definitions target_include_directories( - singularity-eos + singularity-eos_Interface PUBLIC ${SINGULARITY_PUBLIC_INCS} PRIVATE ${SINGULARITY_PRIVATE_INCS}) target_link_libraries( - singularity-eos + singularity-eos_Interface PUBLIC ${SINGULARITY_PUBLIC_LIBS} PRIVATE ${SINGULARITY_PRIVATE_LIBS}) target_compile_definitions( - singularity-eos + singularity-eos_Interface PUBLIC ${SINGULARITY_PUBLIC_DEFINES} PRIVATE ${SINGULARITY_PRIVATE_DEFINES}) @@ -448,9 +463,8 @@ set(with_better_flags "$") set(xlfix "$<${with_xlcxx}:-std=c++1y;-qxflag=disable__cplusplusOverride>") target_compile_options( - singularity-eos - PRIVATE ${xlfix} - PUBLIC $<${with_cuda}: + singularity-eos_Interface + INTERFACE $<${with_cuda}: $<${with_cxx}: --expt-relaxed-constexpr $<${with_warnings}: @@ -468,7 +482,26 @@ target_compile_options( > # cuda ) -target_link_options(singularity-eos PRIVATE ${xlfix}) +if(SINGULARITY_BUILD_CLOSURE) + target_compile_options(singularity-eos_Library PRIVATE ${xlfix}) + target_link_options(singularity-eos_Library PRIVATE ${xlfix}) + + # target_link_libraries(singularity-eos_Library PRIVATE singularity-eos_Interface) + # + # Can not use PRIVATE, since it would add singularity-eos_Interface as LINK_ONLY + # in the singularity-eos_Library export + # + # CMake 3.26 gives us $, for now we need to do this workaround + if(CMAKE_VERSION VERSION_LESS "3.26.0") + target_link_options(singularity-eos_Library PRIVATE $) + target_include_directories(singularity-eos_Library PRIVATE $) + target_compile_options(singularity-eos_Library PRIVATE $) + target_compile_definitions(singularity-eos_Library PRIVATE $) + target_sources(singularity-eos_Library PRIVATE $) + else() + target_link_libraries(singularity-eos_Library PRIVATE $) + endif() +endif() # ----------------------------------------------------------------------------# # Export/install diff --git a/cmake/install.cmake b/cmake/install.cmake index 6656af37b0..dbfd0ac482 100644 --- a/cmake/install.cmake +++ b/cmake/install.cmake @@ -55,27 +55,49 @@ install(FILES ${PROJECT_SOURCE_DIR}/cmake/FindEOSPAC.cmake # install export target # ----------------------------------------------------------------------------# install( - TARGETS singularity-eos - EXPORT singularity-eosTargets + TARGETS singularity-eos_Common + EXPORT singularity-eos_Common DESTINATION ${CMAKE_INSTALL_LIBDIR}) install( - EXPORT singularity-eosTargets - FILE singularity-eosTargets.cmake + EXPORT singularity-eos_Common + FILE singularity-eos_Common.cmake NAMESPACE "singularity-eos::" DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/singularity-eos) +install( + TARGETS singularity-eos_Interface + EXPORT singularity-eos_Interface + DESTINATION ${CMAKE_INSTALL_LIBDIR}) + +install( + EXPORT singularity-eos_Interface + FILE singularity-eos_Interface.cmake + NAMESPACE "singularity-eos::" + COMPONENT singularity-eos_Interface + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/singularity-eos) + +if(SINGULARITY_BUILD_CLOSURE) + install( + TARGETS singularity-eos_Library + EXPORT singularity-eos_Library + DESTINATION ${CMAKE_INSTALL_LIBDIR}) + + install( + EXPORT singularity-eos_Library + FILE singularity-eos_Library.cmake + NAMESPACE "singularity-eos::" + COMPONENT singularity-eos_Library + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/singularity-eos) +endif() + # ----------------------------------------------------------------------------# # Install headers # ----------------------------------------------------------------------------# # install singularity-eos headers -get_property(install_headers GLOBAL PROPERTY _install_headers) -list(LENGTH install_headers length) -math(EXPR max_index "${length} - 1") -foreach(index RANGE ${max_index}) - list(GET eos_headers ${index} src) - list(GET install_headers ${index} dst) +get_property(install_headers GLOBAL PROPERTY EOS_INSTALL_HEADERS) +foreach(src dst IN ZIP_LISTS eos_headers install_headers) get_filename_component(DIR ${dst} DIRECTORY) install(FILES ${src} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${DIR}) endforeach() # file @@ -97,10 +119,22 @@ endif() # same as install step, but just places the file in the build tree. useful for # downstream projects that use the source directly export( - EXPORT singularity-eosTargets - FILE ${CMAKE_CURRENT_BINARY_DIR}/singularity-eosTargets.cmake + EXPORT singularity-eos_Common + FILE ${CMAKE_CURRENT_BINARY_DIR}/singularity-eos_Common.cmake NAMESPACE singularity-eos::) +export( + EXPORT singularity-eos_Interface + FILE ${CMAKE_CURRENT_BINARY_DIR}/singularity-eos_Interface.cmake + NAMESPACE singularity-eos::) + +if(SINGULARITY_BUILD_CLOSURE) + export( + EXPORT singularity-eos_Library + FILE ${CMAKE_CURRENT_BINARY_DIR}/singularity-eos_Library.cmake + NAMESPACE singularity-eos::) +endif() + # ----------------------------------------------------------------------------# # Data files # ----------------------------------------------------------------------------# diff --git a/cmake/plugins.cmake b/cmake/plugins.cmake index 5b23f2476d..74d0c188e0 100644 --- a/cmake/plugins.cmake +++ b/cmake/plugins.cmake @@ -12,15 +12,19 @@ # publicly and display publicly, and to permit others to do so. #------------------------------------------------------------------------------# +set_property(GLOBAL PROPERTY EOS_SRCS "") set_property(GLOBAL PROPERTY EOS_HEADERS "") -set_property(GLOBAL PROPERTY _install_headers "") +set_property(GLOBAL PROPERTY EOS_INSTALL_HEADERS "") +set_property(GLOBAL PROPERTY PLUGIN_TESTS "") +set_property(GLOBAL PROPERTY PLUGIN_INCLUDE_PATHS "") + function(register_headers) set(keyword_args PLUGIN) cmake_parse_arguments(ARG "" "${keyword_args}" "" ${ARGN}) set(variadic_args ${ARG_UNPARSED_ARGUMENTS}) get_property(eos_headers GLOBAL PROPERTY EOS_HEADERS) - get_property(install_headers GLOBAL PROPERTY _install_headers) + get_property(install_headers GLOBAL PROPERTY EOS_INSTALL_HEADERS) foreach(arg IN LISTS variadic_args) file(RELATIVE_PATH relative_path ${PROJECT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) @@ -33,10 +37,9 @@ function(register_headers) endif() endforeach() set_property(GLOBAL PROPERTY EOS_HEADERS "${eos_headers}") - set_property(GLOBAL PROPERTY _install_headers "${install_headers}") + set_property(GLOBAL PROPERTY EOS_INSTALL_HEADERS "${install_headers}") endfunction() -set_property(GLOBAL PROPERTY EOS_SRCS "") function(register_srcs) get_property(eos_srcs GLOBAL PROPERTY EOS_SRCS) foreach(arg IN LISTS ARGN) @@ -46,8 +49,6 @@ function(register_srcs) set_property(GLOBAL PROPERTY EOS_SRCS "${eos_srcs}") endfunction() -set(PLUGIN_TESTS "") -set_property(GLOBAL PROPERTY PLUGIN_TESTS "") function(register_tests) get_property(plugin_tests GLOBAL PROPERTY PLUGIN_TESTS) foreach(arg IN LISTS ARGN) @@ -56,7 +57,6 @@ function(register_tests) set_property(GLOBAL PROPERTY PLUGIN_TESTS "${plugin_tests}") endfunction() -set_property(GLOBAL PROPERTY PLUGIN_INCLUDE_PATHS "") macro(export_plugin) get_property(plugin_include_paths GLOBAL PROPERTY PLUGIN_INCLUDE_PATHS) list(APPEND plugin_include_paths ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/cmake/singularity-eos/Eigen3.cmake b/cmake/singularity-eos/Eigen3.cmake index 04fbf99d38..c8dd72a855 100644 --- a/cmake/singularity-eos/Eigen3.cmake +++ b/cmake/singularity-eos/Eigen3.cmake @@ -19,5 +19,5 @@ macro(singularity_find_eigen) endmacro() macro(singularity_enable_eigen target) - target_link_libraries(${target} PUBLIC Eigen3::Eigen) + target_link_libraries(${target} INTERFACE Eigen3::Eigen) endmacro() diff --git a/cmake/singularity-eos/eospac.cmake b/cmake/singularity-eos/eospac.cmake index 42d1b160f8..ce7d6933de 100644 --- a/cmake/singularity-eos/eospac.cmake +++ b/cmake/singularity-eos/eospac.cmake @@ -2,11 +2,11 @@ macro(singularity_enable_eospac target) if(NOT TARGET EOSPAC::eospac) find_package(EOSPAC REQUIRED) endif() - target_link_libraries(${target} PUBLIC EOSPAC::eospac) - target_compile_definitions(${target} PUBLIC SINGULARITY_USE_EOSPAC) + target_link_libraries(${target} INTERFACE EOSPAC::eospac) + target_compile_definitions(${target} INTERFACE SINGULARITY_USE_EOSPAC) add_subdirectory(${PROJECT_SOURCE_DIR}/eospac-wrapper) - target_link_libraries(${target} PUBLIC eospac-wrapper) + target_link_libraries(${target} INTERFACE eospac-wrapper) endmacro() diff --git a/cmake/singularity-eos/hdf5.cmake b/cmake/singularity-eos/hdf5.cmake index 81aa58d8dc..7e05283447 100644 --- a/cmake/singularity-eos/hdf5.cmake +++ b/cmake/singularity-eos/hdf5.cmake @@ -71,24 +71,24 @@ macro(singularity_enable_hdf5 target) endif() endif() - target_include_directories(${target} SYSTEM PUBLIC ${HDF5_INCLUDE_DIRS}) - target_link_libraries(${target} PUBLIC ${HDF5_LIBRARIES} ${HDF5_HL_LIBRARIES}) + target_include_directories(${target} SYSTEM INTERFACE ${HDF5_INCLUDE_DIRS}) + target_link_libraries(${target} INTERFACE ${HDF5_LIBRARIES} ${HDF5_HL_LIBRARIES}) if(HDF5_IS_PARALLEL) # find_package(MPI COMPONENTS C CXX REQUIRED) - # target_link_libraries(${target} PUBLIC MPI::MPI_C MPI::MPI_CXX) + # target_link_libraries(${target} INTERFACE MPI::MPI_C MPI::MPI_CXX) enable_language(C) find_package( MPI COMPONENTS C CXX REQUIRED) - target_link_libraries(${target} PUBLIC MPI::MPI_CXX) + target_link_libraries(${target} INTERFACE MPI::MPI_CXX) set(SINGULARITY_USE_SPINER_WITH_PARALLEL_HDF5 ON CACHE BOOL "" FORCE) endif() endif() # in tree cray - target_compile_definitions(${target} PUBLIC SINGULARITY_USE_HDF5) + target_compile_definitions(${target} INTERFACE SINGULARITY_USE_HDF5) endmacro() diff --git a/cmake/singularity-eos/kokkos.cmake b/cmake/singularity-eos/kokkos.cmake index fb782a028e..6d56a8be32 100644 --- a/cmake/singularity-eos/kokkos.cmake +++ b/cmake/singularity-eos/kokkos.cmake @@ -23,9 +23,9 @@ endmacro() macro(singularity_enable_kokkos target) - target_link_libraries(${target} PUBLIC Kokkos::kokkos) + target_link_libraries(${target} INTERFACE Kokkos::kokkos) - target_compile_definitions(${target} PUBLIC PORTABILITY_STRATEGY_KOKKOS) + target_compile_definitions(${target} INTERFACE PORTABILITY_STRATEGY_KOKKOS) # #TODO: shouldn't be needed target_compile_definitions(${target} PUBLIC # SPINER_USE_KOKKOS) @@ -108,6 +108,6 @@ macro(singularity_find_kokkoskernels) endmacro() macro(singularity_enable_kokkoskernels target) - target_compile_definitions(${target} PUBLIC SINGULARITY_USE_KOKKOSKERNELS) - target_link_libraries(${target} PUBLIC Kokkos::kokkoskernels) + target_compile_definitions(${target} INTERFACE SINGULARITY_USE_KOKKOSKERNELS) + target_link_libraries(${target} INTERFACE Kokkos::kokkoskernels) endmacro() diff --git a/cmake/singularity-eos/mpark_variant.cmake b/cmake/singularity-eos/mpark_variant.cmake index ca67972a4b..3a5776d4ee 100644 --- a/cmake/singularity-eos/mpark_variant.cmake +++ b/cmake/singularity-eos/mpark_variant.cmake @@ -21,5 +21,5 @@ macro(singularity_find_mpark_variant) endmacro() macro(singularity_enable_mpark_variant target) - target_link_libraries(${target} PUBLIC mpark_variant) + target_link_libraries(${target} INTERFACE mpark_variant) endmacro() diff --git a/cmake/singularity-eos/ports-of-call.cmake b/cmake/singularity-eos/ports-of-call.cmake index c38d85aabb..6d1e1424e1 100644 --- a/cmake/singularity-eos/ports-of-call.cmake +++ b/cmake/singularity-eos/ports-of-call.cmake @@ -9,5 +9,5 @@ macro(singularity_find_ports_of_call) endmacro() macro(singularity_enable_ports_of_call target) - target_link_libraries(${target} PUBLIC ports-of-call::ports-of-call) + target_link_libraries(${target} INTERFACE ports-of-call::ports-of-call) endmacro() diff --git a/cmake/singularity-eos/spiner.cmake b/cmake/singularity-eos/spiner.cmake index 3d5de88237..c8c6568f61 100644 --- a/cmake/singularity-eos/spiner.cmake +++ b/cmake/singularity-eos/spiner.cmake @@ -35,9 +35,9 @@ macro(singularity_enable_spiner target) target_compile_definitions( ${target} - PUBLIC + INTERFACE $<$:SINGULARITY_USE_SPINER> $<$:SINGULARITY_USE_SPINER_WITH_HDF5> ) - target_link_libraries(${target} PUBLIC spiner::spiner) + target_link_libraries(${target} INTERFACE spiner::spiner) endmacro() diff --git a/config/singularity-eosCMakeConfig.cmake.in b/config/singularity-eosCMakeConfig.cmake.in deleted file mode 100644 index 1ed10cc04f..0000000000 --- a/config/singularity-eosCMakeConfig.cmake.in +++ /dev/null @@ -1,15 +0,0 @@ -#------------------------------------------------------------------------------# -# © 2021-2023. Triad National Security, LLC. All rights reserved. This -# program was produced under U.S. Government contract 89233218CNA000001 -# for Los Alamos National Laboratory (LANL), which is operated by Triad -# National Security, LLC for the U.S. Department of Energy/National -# Nuclear Security Administration. All rights in the program are -# reserved by Triad National Security, LLC, and the U.S. Department of -# Energy/National Nuclear Security Administration. The Government is -# granted for itself and others acting on its behalf a nonexclusive, -# paid-up, irrevocable worldwide license in this material to reproduce, -# prepare derivative works, distribute copies to the public, perform -# publicly and display publicly, and to permit others to do so. -#------------------------------------------------------------------------------# - -set(singularity-eosCMake_PREFIX @CMAKE_INSTALL_PREFIX@/share/singularity-eos/cmake) diff --git a/config/singularity-eosConfig.cmake.in b/config/singularity-eosConfig.cmake.in index 7557387ab2..351c768f73 100644 --- a/config/singularity-eosConfig.cmake.in +++ b/config/singularity-eosConfig.cmake.in @@ -20,27 +20,51 @@ # ------------------------------------------------------------------------------# # add singularity-eos cmake files # ------------------------------------------------------------------------------# -get_filename_component(singularity-eos_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" - PATH) if(NOT SINGULARITY_EOS_CMAKE) - get_filename_component(singularity-eos_CMAKE_BASE_DIR - "${singularity-eos_CMAKE_DIR}" DIRECTORY) message( STATUS "Found singularity-eos CMake Modules (appending CMAKE_MODULE_PATH): " - ${singularity-eos_CMAKE_BASE_DIR}) - list(APPEND CMAKE_MODULE_PATH ${singularity-eos_CMAKE_BASE_DIR}) + ${CMAKE_CURRENT_LIST_DIR}) + list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}) set(SINGULARITY_EOS_CMAKE TRUE) endif() +# ------------------------------------------------------------------------------# +# check for selected components +# ------------------------------------------------------------------------------# +if(${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS) + set(${CMAKE_FIND_PACKAGE_NAME}_known_components Interface Library) + foreach(comp IN LISTS ${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS) + if(NOT comp IN_LIST ${CMAKE_FIND_PACKAGE_NAME}_known_components) + set(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE "singularity-eos unknown component: ${comp}") + set(${CMAKE_FIND_PACKAGE_NAME}_FOUND FALSE) + return() + endif() + endforeach() + set(${CMAKE_FIND_PACKAGE_NAME}_comps ${${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS}) +else() + set(${CMAKE_FIND_PACKAGE_NAME}_comps Interface Library) +endif() + +foreach(comp IN LISTS ${CMAKE_FIND_PACKAGE_NAME}_comps) + if(${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED_${comp} AND NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/singularity-eos_${comp}.cmake) + set(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE "singularity-eos missing required component: ${comp}") + set(${CMAKE_FIND_PACKAGE_NAME}_FOUND FALSE) + return() + endif() +endforeach() + + # ------------------------------------------------------------------------------# # library dependencies # ------------------------------------------------------------------------------# include(CMakeFindDependencyMacro) -find_dependency(ports-of-call) - -find_dependency(mpark_variant) +# header-only dependencies +if("Interface" IN_LIST ${CMAKE_FIND_PACKAGE_NAME}_comps) + find_dependency(ports-of-call) + find_dependency(mpark_variant) +endif() if(@SINGULARITY_USE_SPINER@) find_dependency(spiner) @@ -75,9 +99,24 @@ if(@SINGULARITY_USE_EOSPAC@) endif() endif() +include(${CMAKE_CURRENT_LIST_DIR}/singularity-eos_Common.cmake) + +foreach(comp IN LISTS ${CMAKE_FIND_PACKAGE_NAME}_comps) + include(${CMAKE_CURRENT_LIST_DIR}/singularity-eos_${comp}.cmake OPTIONAL) +endforeach() + # ------------------------------------------------------------------------------# -# singularity-eos imported targets +# singularity-eos convenience target # ------------------------------------------------------------------------------# if(NOT TARGET singularity-eos AND NOT singularity-eos_BINARY_DIR) - include(${singularity-eos_CMAKE_DIR}/singularity-eosTargets.cmake) + add_library(singularity-eos INTERFACE) + add_library(singularity-eos::singularity-eos ALIAS singularity-eos) + + if("Interface" IN_LIST ${CMAKE_FIND_PACKAGE_NAME}_comps) + target_link_libraries(singularity-eos INTERFACE singularity-eos::singularity-eos_Interface) + endif() + + if("Library" IN_LIST ${CMAKE_FIND_PACKAGE_NAME}_comps) + target_link_libraries(singularity-eos INTERFACE singularity-eos::singularity-eos_Library) + endif() endif() diff --git a/doc/sphinx/index.rst b/doc/sphinx/index.rst index 29daf0763d..16a8b2448e 100644 --- a/doc/sphinx/index.rst +++ b/doc/sphinx/index.rst @@ -17,6 +17,7 @@ Documentation approved for unlimited release. LA-UR-21-31131. src/getting-started src/philosophy src/building + src/integration src/using-eos src/models src/modifiers diff --git a/doc/sphinx/src/integration.rst b/doc/sphinx/src/integration.rst new file mode 100644 index 0000000000..495b85a07d --- /dev/null +++ b/doc/sphinx/src/integration.rst @@ -0,0 +1,47 @@ +Integrating `singularity-eos` into a CMake project +================================================== + +Installing singularity-eos into a prefix, either manually or via Spack gives +you an installation that can be used in other projects via CMake. Assuming +your installation is visible to CMake, either by installing in a known prefix +or setting ``CMAKE_PREFIX_PATH`` manually, a CMake project can integrate +Singularity-EOS via ``find_package(singularity-eos)`` and using the provided +targets to link to it. + +.. code:: cmake + + find_package(singularity-eos) + ... + target_link_libraries(yourTarget PRIVATE singularity-eos::singularity-eos) + +The ``singularity-eos`` config module provides the following targets: + +``singularity-eos::singularity-eos_Interface``: + The C++ header-only library, adding the necessary include directories and + other dependencies such as mpark-variant and ports-of-call. + +``singularity-eos::singularity-eos_Library``: + The static or shared library installed when building with + ``SINGULARITY_BUILD_CLOSURE=on``. If ``SINGULARITY_USE_FORTRAN=on``, this also includes the + Fortran bindings and adds include path for its Fortran module. + +``singularity-eos::singularity-eos`` + Convenience target that contains either + ``singularity-eos::singularity-eos_Interface``, + ``singularity-eos::singularity-eos_Library``, or both, depending on the + COMPONENTS selection during ``find_package``. By default, if no COMPONENTS + are specified both are included. + +Example: Integrating singularity-eos into a Fortran code +-------------------------------------------------------- + +Fortran projects do not require the C++ header-only library and its +dependencies, but only the compiled Fortran bindings provided by +Singularity-EOS. To avoid unnecessary dependency checks by CMake, a Fortran +project would integrate Singularity-EOS as follows: + +.. code:: cmake + + find_package(singularity-eos COMPONENTS Library) + ... + target_link_libraries(yourTarget PRIVATE singularity-eos::singularity-eos) diff --git a/eospac-wrapper/CMakeLists.txt b/eospac-wrapper/CMakeLists.txt index fc5c7fabec..a832dce41f 100644 --- a/eospac-wrapper/CMakeLists.txt +++ b/eospac-wrapper/CMakeLists.txt @@ -21,6 +21,7 @@ list(APPEND EOSWRAPPER_SRCS eospac_wrapper.cpp) add_library(eospac-wrapper ${EOSWRAPPER_SRCS} ${EOSWRAPPER_HEADERS} ) +add_library(singularity-eos::singularity-eos_EospacWrapper ALIAS eospac-wrapper) target_include_directories(eospac-wrapper PUBLIC @@ -47,5 +48,5 @@ install( ) install( - TARGETS eospac-wrapper EXPORT singularity-eosTargets DESTINATION ${CMAKE_INSTALL_LIBDIR} + TARGETS eospac-wrapper EXPORT singularity-eos_Common DESTINATION ${CMAKE_INSTALL_LIBDIR} ) diff --git a/example/plugin/tst/test_dust.cpp b/example/plugin/tst/test_dust.cpp index 0bcdca83b5..f8ea0ddf50 100644 --- a/example/plugin/tst/test_dust.cpp +++ b/example/plugin/tst/test_dust.cpp @@ -22,10 +22,6 @@ #include #include -#ifdef SINGULARITY_BUILD_CLOSURE -#include -#endif - #ifndef CATCH_CONFIG_FAST_COMPILE #define CATCH_CONFIG_FAST_COMPILE #include diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index e2f0a4e3cc..6111edb399 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -23,7 +23,7 @@ pybind11_add_module(singularity_eos modifier_relativistic.cpp modifier_bilinear_ramp.cpp ) -target_link_libraries(singularity_eos PRIVATE singularity-eos) +target_link_libraries(singularity_eos PRIVATE singularity-eos_Interface) include(GNUInstallDirs) diff --git a/singularity-eos/CMakeLists.txt b/singularity-eos/CMakeLists.txt index e652ef465a..ae5dee1bed 100644 --- a/singularity-eos/CMakeLists.txt +++ b/singularity-eos/CMakeLists.txt @@ -35,7 +35,6 @@ register_headers( eos/default_variant.hpp base/hermite.hpp eos/eos_variant.hpp - eos/singularity_eos.hpp eos/eos_stellar_collapse.hpp eos/eos_ideal.hpp eos/eos_models.hpp @@ -58,8 +57,6 @@ register_headers( eos/eos_stiff.hpp ) -register_srcs(eos/eos.cpp) - if (SINGULARITY_BUILD_CLOSURE) register_headers(closure/mixed_cell_models.hpp) if (SINGULARITY_USE_FORTRAN) diff --git a/test/eos_unit_test_helpers.hpp b/test/eos_unit_test_helpers.hpp index 1d00b2e606..b5bf7bde90 100644 --- a/test/eos_unit_test_helpers.hpp +++ b/test/eos_unit_test_helpers.hpp @@ -82,7 +82,7 @@ inline void array_compare(int num, X &&x, Y &&y, Z &&z, ZT &&ztrue, XN xname, YN } template -inline void compare_two_eoss(const E1 &&test_e, const E2 &&ref_e) { +inline void compare_two_eoss(const E1 &test_e, const E2 &ref_e) { // compare all individual member functions with 1 as inputs, // this function is meant to catch mis-implementations of // modifiers that can be initialized in such a way as to diff --git a/test/test_eos_ideal.cpp b/test/test_eos_ideal.cpp index a8d3a6ac6a..211ef6b3ba 100644 --- a/test/test_eos_ideal.cpp +++ b/test/test_eos_ideal.cpp @@ -22,10 +22,6 @@ #include #include -#ifdef SINGULARITY_BUILD_CLOSURE -#include -#endif - #ifndef CATCH_CONFIG_FAST_COMPILE #define CATCH_CONFIG_FAST_COMPILE #include diff --git a/test/test_eos_modifiers.cpp b/test/test_eos_modifiers.cpp index 2cc1a72d00..09c52ecdfc 100644 --- a/test/test_eos_modifiers.cpp +++ b/test/test_eos_modifiers.cpp @@ -20,6 +20,10 @@ #include #include +#ifdef SINGULARITY_BUILD_CLOSURE +#include +#endif + #ifndef CATCH_CONFIG_FAST_COMPILE #define CATCH_CONFIG_FAST_COMPILE #include @@ -41,6 +45,7 @@ using singularity::ScaledEOS; using singularity::ShiftedEOS; using singularity::UnitSystem; +#ifndef SINGULARITY_BUILD_CLOSURE // recreate variadic list template using tl = variadic_utils::type_list; @@ -93,6 +98,7 @@ static constexpr const auto ramped_all = static constexpr const auto combined_list = variadic_utils::concat(combined_list_1, ramped_all); using EOS = typename decltype(tl_to_Variant(combined_list))::vt; +#endif SCENARIO("EOS Builder and Modifiers", "[EOSBuilder][Modifiers][IdealGas]") {