From 05c51204730757d3878842bd09ef03fc51f13034 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Fri, 9 Feb 2024 13:02:59 -0700 Subject: [PATCH] Fixup components install --- CMakeLists.txt | 28 +++++++++++++++++++++++---- cmake/install.cmake | 16 +++++++++++++++ config/singularity-eosConfig.cmake.in | 9 ++++++--- eospac-wrapper/CMakeLists.txt | 3 ++- 4 files changed, 48 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 16009b8483c..c7f69ff62ab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -137,17 +137,21 @@ include(singularity-eos/ports-of-call) add_library(singularity-eos INTERFACE) add_library(singularity-eos::singularity-eos ALIAS singularity-eos) -add_library(singularity-eos_Interface INTERFACE) +# 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) - target_link_libraries(singularity-eos_Library PRIVATE singularity-eos_Interface) 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() @@ -283,12 +287,12 @@ endif() # cases. if(SINGULARITY_USE_SPINER_WITH_HDF5) - singularity_enable_hdf5(singularity-eos_Interface) + singularity_enable_hdf5(singularity-eos_Common) endif() if(SINGULARITY_USE_EOSPAC) # NB This will add the `eospac-wrapper` directory. - singularity_enable_eospac(singularity-eos_Interface) + singularity_enable_eospac(singularity-eos_Common) endif() if(SINGULARITY_SUBMODULE_MODE) @@ -481,6 +485,22 @@ target_compile_options( 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() # ----------------------------------------------------------------------------# diff --git a/cmake/install.cmake b/cmake/install.cmake index 88c22902736..dbfd0ac482e 100644 --- a/cmake/install.cmake +++ b/cmake/install.cmake @@ -54,6 +54,17 @@ install(FILES ${PROJECT_SOURCE_DIR}/cmake/FindEOSPAC.cmake # ----------------------------------------------------------------------------# # install export target # ----------------------------------------------------------------------------# +install( + TARGETS singularity-eos_Common + EXPORT singularity-eos_Common + DESTINATION ${CMAKE_INSTALL_LIBDIR}) + +install( + 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 @@ -107,6 +118,11 @@ 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-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 diff --git a/config/singularity-eosConfig.cmake.in b/config/singularity-eosConfig.cmake.in index 494d1c92178..351c768f739 100644 --- a/config/singularity-eosConfig.cmake.in +++ b/config/singularity-eosConfig.cmake.in @@ -32,14 +32,15 @@ endif() # check for selected components # ------------------------------------------------------------------------------# if(${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS) - foreach(comp IN LISTS ${CMAKE_FIND_PACKAGE_NAME}_comps) - if(NOT comp IN_LIST "Interface;Library") + 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_COMPONENT}) + set(${CMAKE_FIND_PACKAGE_NAME}_comps ${${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS}) else() set(${CMAKE_FIND_PACKAGE_NAME}_comps Interface Library) endif() @@ -98,6 +99,8 @@ 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() diff --git a/eospac-wrapper/CMakeLists.txt b/eospac-wrapper/CMakeLists.txt index fc5c7fabecf..a832dce41ff 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} )