Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake components #339

Merged
merged 8 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
111 changes: 72 additions & 39 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 $<BUILD_INTERFACE:${CMAKE_BINARY_DIR}>)
# 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
Expand Down Expand Up @@ -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()

# ------------------------------------------------------------------------------#
Expand All @@ -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)
Expand Down Expand Up @@ -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()

# ----------------------------------------------------------------------------#
Expand Down Expand Up @@ -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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be best to have variable like BUILD_LIBRARY that (for now) automatically is set by BUILD_CLOSURE so that we can extend in the future if needed.

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 +463,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 +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 $<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()

# ----------------------------------------------------------------------------#
# Export/install
Expand Down
58 changes: 46 additions & 12 deletions cmake/install.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
# ----------------------------------------------------------------------------#
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 ${PROJECT_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()


Loading
Loading