Skip to content

Commit

Permalink
Merge pull request #238 from LLNL/feature/cmake_export_targets
Browse files Browse the repository at this point in the history
Feature/cmake export targets
  • Loading branch information
ldowen authored Oct 2, 2023
2 parents ae60eeb + b2a4f13 commit daece81
Show file tree
Hide file tree
Showing 48 changed files with 345 additions and 309 deletions.
19 changes: 19 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
Version vYYYY.MM.p -- Release date YYYY-MM-DD
==============================================
* Important Notes:
* The PolyClipper and PYB11Generator submodules have been modified. Be sure to recursively update the submodules.

Notable changes include:

* New features/ API changes:


* Build changes / improvements:
* Spheral now provides First Class CMake support (using the BLT nomenclature). Spheral and its dependencies are now exported to simplify importing the project. To import Spheral into another project using CMake, use
```
find_package(Spheral_CXX <path_to_spheral_installation>)
```
* CMake variables have a more consistent naming convention. Unused variables are removed.
* Bug Fixes / improvements:
Version v2023-06-0 -- Release date 2023-06-20
==============================================
Expand Down
99 changes: 51 additions & 48 deletions cmake/InstallTPLs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,88 +5,91 @@
# Do NOT add any TPLs to the clean target
set_directory_properties(PROPERTIES CLEAN_NO_CUSTOM 1)

# Set the location of the <tpl>.cmake files
set(TPL_SPHERAL_CMAKE_DIR ${SPHERAL_ROOT_DIR}/cmake/tpl)

#-----------------------------------------------------------------------------------
# Submodules
#-----------------------------------------------------------------------------------

# Things all Spheral packages have in their include path
set(SPHERAL_EXTERN_INCLUDES )

# PolyClipper
if (NOT polyclipper_DIR)
set(polyclipper_DIR "${SPHERAL_ROOT_DIR}/extern/PolyClipper" CACHE PATH "")
endif()
set(polyclipper_INCLUDES "${polyclipper_DIR}/src")

list(APPEND SPHERAL_EXTERN_INCLUDES ${polyclipper_INCLUDES})


if (NOT ENABLE_CXXONLY)
# Find the appropriate Python
set(Python3_ROOT_DIR ${python_DIR})
find_package(Python3 COMPONENTS Interpreter Development)
set(PYTHON_EXE ${Python3_EXECUTABLE})
list(APPEND SPHERAL_BLT_DEPENDS Python3::Python)

# Set the PYB11Generator path
if (NOT PYB11GENERATOR_ROOT_DIR)
set(PYB11GENERATOR_ROOT_DIR "${SPHERAL_ROOT_DIR}/extern/PYB11Generator" CACHE PATH "")
endif()
include(${PYB11GENERATOR_ROOT_DIR}/cmake/PYB11Generator.cmake)

# Set the pybind11 path
if (NOT PYBIND11_ROOT_DIR)
set(PYBIND11_ROOT_DIR "${PYB11GENERATOR_ROOT_DIR}/extern/pybind11" CACHE PATH "")
endif()
include(${PYB11GENERATOR_ROOT_DIR}/cmake/PYB11Generator.cmake)
list(APPEND SPHERAL_BLT_DEPENDS pybind11_headers)
install(TARGETS pybind11_headers
EXPORT spheral_cxx-targets
DESTINATION lib/cmake)
set_target_properties(pybind11_headers PROPERTIES EXPORT_NAME spheral::pybind11_headers)
endif()

list(APPEND SPHERAL_EXTERN_INCLUDES ${PYBIND11_ROOT_DIR}/include)
# This is currently unfilled in spheral
set_property(GLOBAL PROPERTY SPHERAL_SUBMOD_INCLUDES "${SPHERAL_SUBMOD_INCLUDES}")

# PolyClipper
if (NOT polyclipper_DIR)
set(polyclipper_DIR "${SPHERAL_ROOT_DIR}/extern/PolyClipper" CACHE PATH "")
endif()
# Must set this so PolyClipper doesn't include unnecessary python scripts
set(POLYCLIPPER_MODULE_GEN OFF)
set(POLYCLIPPER_ENABLE_DOCS OFF)
set(POLYCLIPPER_INSTALL_DIR "PolyClipper/include")
add_subdirectory(${polyclipper_DIR})
# Treat includes as system to prevent warnings
blt_patch_target(NAME PolyClipperAPI TREAT_INCLUDES_AS_SYSTEM ON)
list(APPEND SPHERAL_BLT_DEPENDS PolyClipperAPI)
install(TARGETS PolyClipperAPI
EXPORT spheral_cxx-targets
DESTINATION lib/cmake)
set_target_properties(PolyClipperAPI PROPERTIES EXPORT_NAME spheral::PolyClipperAPI)

#-----------------------------------------------------------------------------------
# Find pre-compiled TPLs
#-----------------------------------------------------------------------------------

# Use find_package to get axom (which brings in fmt) and patch fmt
list(APPEND SPHERAL_BLT_DEPENDS axom)
find_package(axom REQUIRED QUIET NO_DEFAULT_PATH PATHS ${axom_DIR}/lib/cmake)
# Add fmt library to external library list
list(APPEND SPHERAL_BLT_DEPENDS fmt)
blt_patch_target(NAME fmt TREAT_INCLUDES_AS_SYSTEM ON)

# Initialize TPL options
include(${SPHERAL_ROOT_DIR}/cmake/spheral/SpheralHandleTPL.cmake)

# These libs are always needed
Spheral_Handle_TPL(zlib spheral_depends cxx)
Spheral_Handle_TPL(boost spheral_depends cxx)
Spheral_Handle_TPL(eigen spheral_depends cxx)
Spheral_Handle_TPL(qhull spheral_depends cxx)
Spheral_Handle_TPL(silo spheral_depends cxx)
# TPLs that must be imported
list(APPEND SPHERAL_EXTERN_LIBS zlib boost eigen qhull silo hdf5 polytope)

# AXOM PUlls in HDF5 and Conduit for us
#Spheral_Handle_TPL(conduit spheral_depends cxx)
find_package(axom REQUIRED QUIET NO_DEFAULT_PATH PATHS ${axom_DIR}/lib/cmake)
if(axom_FOUND)
list(APPEND spheral_blt_cxx_depends axom fmt)
blt_patch_target(NAME fmt TREAT_INCLUDES_AS_SYSTEM On)
message(STATUS "Found axom: ${axom_DIR} (found version ${axom_VERSION})")
endif()

# Axom imports hdf5 lib but Spheral also requires hdf5_hl
Spheral_Handle_TPL(hdf5 spheral_depends cxx)

# Some libraries are optional
if (ENABLE_ANEOS)
Spheral_Handle_TPL(aneos spheral_depends cxx)
if(ENABLE_ANEOS)
list(APPEND SPHERAL_EXTERN_LIBS aneos)
endif()
if (ENABLE_OPENSUBDIV)
Spheral_Handle_TPL(opensubdiv spheral_depends cxx)
if(ENABLE_OPENSUBDIV)
list(APPEND SPHERAL_EXTERN_LIBS opensubdiv)
endif()
if(ENABLE_TIMER)
Spheral_Handle_TPL(caliper spheral_depends cxx)
endif()

# Only needed when building the python interface of spheral
if(NOT ENABLE_CXXONLY)
Spheral_Handle_TPL(python spheral_depends cxx)
#Spheral_Handle_TPL(pyb11generator spheral_depends py)
#Spheral_Handle_TPL(pybind11 spheral_depends py)
list(APPEND SPHERAL_EXTERN_LIBS caliper)
endif()

Spheral_Handle_TPL(polytope spheral_depends cxx)
#Spheral_Handle_TPL(polyclipper spheral_depends cxx)
# Create and install target library for each external library
foreach(lib ${SPHERAL_EXTERN_LIBS})
Spheral_Handle_TPL(${lib} ${TPL_SPHERAL_CMAKE_DIR})
list(APPEND SPHERAL_BLT_DEPENDS ${lib})
endforeach()
# Note: SPHERAL_BLT_DEPENDS is made global after this in SetupSpheral.cmake

# This calls LLNLSpheralInstallTPLs.cmake
if (EXISTS ${EXTERNAL_SPHERAL_TPL_CMAKE})
include(${EXTERNAL_SPHERAL_TPL_CMAKE})
endif()
19 changes: 9 additions & 10 deletions cmake/SetupSpheral.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ endif()

if(ENABLE_MPI)
set(BLT_MPI_COMPILE_FLAGS -DUSE_MPI -DMPICH_SKIP_MPICXX -ULAM_WANT_MPI2CPP -DOMPI_SKIP_MPICXX)
list(APPEND spheral_blt_depends mpi)
list(APPEND SPHERAL_BLT_DEPENDS mpi)
endif()

if(ENABLE_OPENMP)
list(APPEND spheral_blt_depends openmp)
list(APPEND SPHERAL_BLT_DEPENDS openmp)
endif()

if(ENABLE_CUDA)
Expand Down Expand Up @@ -117,15 +117,12 @@ set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

#-------------------------------------------------------------------------------
# We need the set of Spheral C++ libraries globally
# Set global variables used for dependencies
#-------------------------------------------------------------------------------
set_property(GLOBAL PROPERTY SPHERAL_CXX_LIBS)

#-------------------------------------------------------------------------------
# Also globally set the variable for the list we accumulate the obj files from
# each library into
#-------------------------------------------------------------------------------
set_property(GLOBAL PROPERTY SPHERAL_OBJ_LIBS)
# List of external dependencies
set_property(GLOBAL PROPERTY SPHERAL_BLT_DEPENDS "${SPHERAL_BLT_DEPENDS}")
# List of compiler dependencies
set_property(GLOBAL PROPERTY SPHERAL_CXX_DEPENDS "${SPHERAL_CXX_DEPENDS}")

#-------------------------------------------------------------------------------
# Prepare to build the src
Expand Down Expand Up @@ -178,3 +175,5 @@ if (ENABLE_TESTS)
SOURCE ${SPHERAL_ROOT_DIR}
DESTINATION ${SPHERAL_TEST_INSTALL_PREFIX})
endif()

include(${SPHERAL_ROOT_DIR}/cmake/SpheralConfig.cmake)
28 changes: 28 additions & 0 deletions cmake/SpheralConfig.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

message(STATUS "Configuring Spheral version ${SPHERAL_VERSION}")

set(SPHERAL_INSTALL_INCLUDE_DIR "include" CACHE STRING "")
set(SPHERAL_INSTALL_CONFIG_DIR "lib" CACHE STRING "")
set(SPHERAL_INSTALL_LIB_DIR "lib" CACHE STRING "")
set(SPHERAL_INSTALL_BIN_DIR "bin" CACHE STRING "")
set(SPHERAL_INSTALL_CMAKE_MODULE_DIR "${SPHERAL_INSTALL_CONFIG_DIR}/cmake" CACHE STRING "")
set(SPHERAL_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX} CACHE STRING "" FORCE)
set(SPHERAL_INSTALL_SPHERAL "Spheral" CACHE STRING "")

include(CMakePackageConfigHelpers)

configure_package_config_file(
${SPHERAL_ROOT_DIR}/cmake/spheral_cxx-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/spheral_cxx-config.cmake
INSTALL_DESTINATION ${SPHERAL_INSTALL_CONFIG_DIR}
PATH_VARS
SPHERAL_INSTALL_INCLUDE_DIR
SPHERAL_INSTALL_LIB_DIR
SPHERAL_INSTALL_BIN_DIR
SPHERAL_INSTALL_CMAKE_MODULE_DIR
SPHERAL_INSTALL_SPHERAL
)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/spheral_cxx-config.cmake
DESTINATION ${SPHERAL_INSTALL_CMAKE_MODULE_DIR}
)

Loading

0 comments on commit daece81

Please sign in to comment.