Skip to content

Commit

Permalink
Fixup components install
Browse files Browse the repository at this point in the history
  • Loading branch information
rbberger committed Feb 9, 2024
1 parent d68f357 commit 05c5120
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 8 deletions.
28 changes: 24 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 $<BUILD_LOCAL_INTERFACE:...>, for now we need to do this workaround
if(CMAKE_VERSION VERSION_LESS "3.26.0")
target_link_options(singularity-eos_Library PRIVATE $<TARGET_PROPERTY:singularity-eos_Interface,INTERFACE_LINK_OPTIONS>)
target_include_directories(singularity-eos_Library PRIVATE $<TARGET_PROPERTY:singularity-eos_Interface,INTERFACE_INCLUDE_DIRECTORIES>)
target_compile_options(singularity-eos_Library PRIVATE $<TARGET_PROPERTY:singularity-eos_Interface,INTERFACE_COMPILE_OPTIONS>)
target_compile_definitions(singularity-eos_Library PRIVATE $<TARGET_PROPERTY:singularity-eos_Interface,INTERFACE_COMPILE_DEFINITIONS>)
target_sources(singularity-eos_Library PRIVATE $<TARGET_PROPERTY:singularity-eos_Interface,INTERFACE_SOURCES>)
else()
target_link_libraries(singularity-eos_Library PRIVATE $<BUILD_LOCAL_INTERFACE:singularity-eos_Interface>)
endif()
endif()

# ----------------------------------------------------------------------------#
Expand Down
16 changes: 16 additions & 0 deletions cmake/install.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions config/singularity-eosConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion eospac-wrapper/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}
)

0 comments on commit 05c5120

Please sign in to comment.