Skip to content

Commit

Permalink
cmake: add Interface and Library components
Browse files Browse the repository at this point in the history
  • Loading branch information
rbberger committed Jan 31, 2024
1 parent 0461dff commit 261f02d
Show file tree
Hide file tree
Showing 13 changed files with 154 additions and 90 deletions.
91 changes: 52 additions & 39 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,21 @@ 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)
add_library(singularity-eos_Interface INTERFACE)

# ?
target_include_directories(singularity-eos
PUBLIC $<BUILD_INTERFACE:${CMAKE_BINARY_DIR}>)

add_library(singularity-eos::singularity-eos_Interface ALIAS singularity-eos_Interface)
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 INTERFACE singularity-eos_Library)
endif()

# ------------------------------------------------------------------------------#
# Compiler & language setup
Expand Down Expand Up @@ -241,21 +250,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()

# ------------------------------------------------------------------------------#
Expand All @@ -274,12 +283,12 @@ endif()
# cases.

if(SINGULARITY_USE_SPINER_WITH_HDF5)
singularity_enable_hdf5(singularity-eos)
singularity_enable_hdf5(singularity-eos_Interface)
endif()

if(SINGULARITY_USE_EOSPAC)
# NB This will add the `eospac-wrapper` directory.
singularity_enable_eospac(singularity-eos)
singularity_enable_eospac(singularity-eos_Interface)
endif()

if(SINGULARITY_SUBMODULE_MODE)
Expand Down Expand Up @@ -320,23 +329,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()

# ----------------------------------------------------------------------------#
Expand Down Expand Up @@ -387,49 +396,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 $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/fortran>
singularity-eos_Library INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/fortran>
$<INSTALL_INTERFACE:include/singularity-eos/eos>)
set_target_properties(singularity-eos PROPERTIES Fortran_PREPROCESS ON)
endif() # SINGULARITY_USE_FORTRAN

target_include_directories(
singularity-eos PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>)
target_include_directories(
singularity-eos PUBLIC $<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/generated>)
target_include_directories(singularity-eos_Interface INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/generated>
$<INSTALL_INTERFACE:include>
)

get_property(plugin_include_paths GLOBAL PROPERTY PLUGIN_INCLUDE_PATHS)
foreach(path ${plugin_include_paths})
target_include_directories(singularity-eos PUBLIC $<BUILD_INTERFACE:${path}>)
target_include_directories(singularity-eos_Interface INTERFACE $<BUILD_INTERFACE:${path}>)
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})

Expand All @@ -448,9 +459,8 @@ set(with_better_flags "$<BOOL:${SINGULARITY_BETTER_DEBUG_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}:
Expand All @@ -468,7 +478,10 @@ 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})
endif()

# ----------------------------------------------------------------------------#
# Export/install
Expand Down
42 changes: 30 additions & 12 deletions cmake/install.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,38 @@ install(FILES ${PROJECT_SOURCE_DIR}/cmake/FindEOSPAC.cmake
# install export target
# ----------------------------------------------------------------------------#
install(
TARGETS singularity-eos
EXPORT singularity-eosTargets
TARGETS singularity-eos_Interface
EXPORT singularity-eos_Interface
DESTINATION ${CMAKE_INSTALL_LIBDIR})

install(
EXPORT singularity-eosTargets
FILE singularity-eosTargets.cmake
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
Expand All @@ -97,10 +108,17 @@ 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_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
# ----------------------------------------------------------------------------#
Expand Down
14 changes: 7 additions & 7 deletions cmake/plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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 ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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})
Expand Down
2 changes: 1 addition & 1 deletion cmake/singularity-eos/Eigen3.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
6 changes: 3 additions & 3 deletions cmake/singularity-eos/eospac.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()


10 changes: 5 additions & 5 deletions cmake/singularity-eos/hdf5.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,23 @@ 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()

target_compile_definitions(${target} PUBLIC SINGULARITY_USE_HDF5)
target_compile_definitions(${target} INTERFACE SINGULARITY_USE_HDF5)

endmacro()
8 changes: 4 additions & 4 deletions cmake/singularity-eos/kokkos.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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()
2 changes: 1 addition & 1 deletion cmake/singularity-eos/mpark_variant.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
2 changes: 1 addition & 1 deletion cmake/singularity-eos/ports-of-call.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Loading

0 comments on commit 261f02d

Please sign in to comment.