Skip to content

Commit

Permalink
Merge pull request #358 from PrincetonUniversity/issue-357
Browse files Browse the repository at this point in the history
Issue 357 - Fix Boost installation to remove non-official dependency
  • Loading branch information
lsawade authored Jan 3, 2025
2 parents 74fc842 + 57b2c03 commit f7d4465
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 57 deletions.
148 changes: 91 additions & 57 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/archive)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

# For external modules that need to be built suppress build output
set(FETCHCONTENT_QUIET TRUE)

if (SPECFEMPP_ENABLE_PYTHON)
message("-- Adding -fPIC flag for Python binding.")
Expand Down Expand Up @@ -54,40 +56,43 @@ else(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
endif()

if (DEFINED Kokkos_ENABLE_CUDA)
if (Kokkos_ENABLE_CUDA)
# message("Setting CUDA variables")
set(Kokkos_ENABLE_CUDA_LAMBDA ON CACHE BOOL "Using CUDA Lambda by default")
set(Kokkos_ENABLE_CUDA_RELOCATABLE_DEVICE_CODE ON CACHE BOOL "Using CUDA Relocatable device by default")
endif()
if (Kokkos_ENABLE_CUDA)
# message("Setting CUDA variables")
set(Kokkos_ENABLE_CUDA_LAMBDA ON CACHE BOOL "Using CUDA Lambda by default")
set(Kokkos_ENABLE_CUDA_RELOCATABLE_DEVICE_CODE ON CACHE BOOL "Using CUDA Relocatable device by default")
endif()
endif()


# Install Kokkos as a dependency
## TODO: Add options for on utilizing in house builds
include(FetchContent)
FetchContent_Declare(
kokkos
URL https://github.com/kokkos/kokkos/archive/refs/tags/4.3.01.zip
kokkos
URL https://github.com/kokkos/kokkos/archive/refs/tags/4.3.01.zip
DOWNLOAD_EXTRACT_TIMESTAMP FALSE
)
FetchContent_MakeAvailable(kokkos)

FetchContent_Declare(
yaml
URL https://github.com/jbeder/yaml-cpp/archive/refs/tags/0.8.0.tar.gz
DOWNLOAD_EXTRACT_TIMESTAMP FALSE
)
FetchContent_MakeAvailable(yaml)

include_directories(BEFORE SYSTEM ${yaml_BINARY_DIR} ${yaml_SOURCE_DIR}/include)

find_package(VTK COMPONENTS
CommonColor
CommonCore
FiltersSources
InteractionStyle
RenderingContextOpenGL2
RenderingCore
RenderingFreeType
RenderingGL2PSOpenGL2
RenderingOpenGL2
CommonColor
CommonCore
FiltersSources
InteractionStyle
RenderingContextOpenGL2
RenderingCore
RenderingFreeType
RenderingGL2PSOpenGL2
RenderingOpenGL2
)


Expand All @@ -102,26 +107,56 @@ endif()
# Try finding boost and if not found install.
find_package(Boost 1.73.0 COMPONENTS program_options filesystem system)


if (NOT ${Boost_FOUND})
add_subdirectory(boost-cmake)
else ()
message(STATUS " LIB: ${Boost_LIBRARY_DIRS}")
message(STATUS " INC: ${Boost_INCLUDE_DIRS}")
message(STATUS " LIBSO: ${Boost_LIBRARIES}")
# Add boost lib sources
set(BOOST_INCLUDE_LIBRARIES program_options filesystem system algorithm tokenizer)
set(BOOST_LIBS Boost::program_options Boost::filesystem Boost::system Boost::algorithm Boost::tokenizer)
set(BOOST_ENABLE_CMAKE ON)
set(BOOST_ENABLE_MPI OFF CACHE INTERNAL "Boost MPI Switch") # Assume outer variable
set(BOOST_ENABLE_PYTHON OFF CACHE INTERNAL "Boost Python Switch") # Assume outer variable
set(BOOST_BUILD_TESTING OFF CACHE BOOL INTERNAL "Boost Test Switch") # Disable testing for boost
# The test flag is not really working... added it for completeness

# Download and extract the boost library from GitHub
set(BOOST_VERSION 1.87.0)
message(STATUS "Downloading and extracting boost (${BOOST_VERSION}) library sources. This will take <1 min.")
include(FetchContent)

# Fetch boost from the Github release zip file to reduce download time
FetchContent_Declare(
Boost
URL https://github.com/boostorg/boost/releases/download/boost-${BOOST_VERSION}/boost-${BOOST_VERSION}-cmake.tar.gz # downloading a zip release speeds up the download
USES_TERMINAL_DOWNLOAD True
GIT_PROGRESS TRUE
DOWNLOAD_NO_EXTRACT FALSE
DOWNLOAD_EXTRACT_TIMESTAMP FALSE
)
FetchContent_MakeAvailable(Boost)

else()
# Check which boost LIBRARY_DIRS to use
set(BOOST_LIBS Boost::boost Boost::program_options Boost::filesystem Boost::system)
message(STATUS "Boost libs/ and incs/:")
message(STATUS " LIB: ${Boost_LIBRARY_DIRS}")
message(STATUS " INC: ${Boost_INCLUDE_DIRS}")
message(STATUS " LIBSO: ${Boost_LIBRARIES}")
endif()

# Install HDF5 as a dependency if not found
find_package(HDF5 COMPONENTS CXX)

if (NOT ${HDF5_FOUND})
message("-- HDF5 not found. Building without HDF5.")
set(HDF5_CXX_BUILD OFF)
else ()
message(STATUS " LIB: ${HDF5_LIBRARIES}")
message(STATUS " INC: ${HDF5_INCLUDE_DIRS}")
message(STATUS " LIBSO: ${HDF5_CXX_LIBRARIES}")
message("-- HDF5 not found. Building without HDF5.")
set(HDF5_CXX_BUILD OFF)
else()
message("HDF5 libs/ and incs/:.")
message(STATUS " LIB: ${HDF5_LIBRARIES}")
message(STATUS " INC: ${HDF5_INCLUDE_DIRS}")
message(STATUS " LIBSO: ${HDF5_CXX_LIBRARIES}")
endif()


configure_file(constants.hpp.in constants.hpp)

include_directories(include)
Expand All @@ -131,13 +166,13 @@ add_subdirectory(fortran/meshfem2d)
add_subdirectory(fortran/meshfem3d)

if (ENABLE_SIMD)
message("-- Enabling SIMD")
add_definitions(-DENABLE_SIMD)
message("-- Enabling SIMD")
add_definitions(-DENABLE_SIMD)
endif()

if (ENABLE_PROFILING)
message("-- Enabling profiling")
add_definitions(-DENABLE_PROFILING)
message("-- Enabling profiling")
add_definitions(-DENABLE_PROFILING)
endif()

# Build specfem2d libraries
Expand Down Expand Up @@ -172,31 +207,30 @@ add_library(
)

if (NOT HDF5_CXX_BUILD)
target_compile_definitions(
IO
PUBLIC -DNO_HDF5
)
target_compile_definitions(
IO
PUBLIC -DNO_HDF5
)

target_link_libraries(
IO
Boost::boost
Kokkos::kokkos
)
target_link_libraries(
IO
mesh
source_class
receiver_class
${BOOST_LIBS}
Kokkos::kokkos)
else()
target_link_libraries(
IO
${HDF5_LIBRARIES}
Boost::boost
Kokkos::kokkos
)
target_link_libraries(
IO
mesh
source_class
receiver_class

Kokkos::kokkos
${HDF5_LIBRARIES}
)
endif()

target_link_libraries(
IO
mesh
source_class
receiver_class
)

add_library(
point
Expand Down Expand Up @@ -365,7 +399,7 @@ target_link_libraries(
yaml-cpp
point
algorithms
Boost::boost
${BOOST_LIBS}
)

add_library(
Expand All @@ -380,7 +414,7 @@ target_link_libraries(
# utilities
quadrature
yaml-cpp
Boost::boost
${BOOST_LIBS}
)

add_library(
Expand Down Expand Up @@ -583,7 +617,7 @@ target_link_libraries(
kernels
domain
solver
Boost::filesystem
${BOOST_LIBS}
)

add_executable(
Expand All @@ -610,7 +644,7 @@ target_link_libraries(
coupled_interface
kernels
solver
Boost::program_options
${BOOST_LIBS}
)

# Include tests
Expand Down Expand Up @@ -673,7 +707,7 @@ if (SPECFEMPP_ENABLE_PYTHON)
coupled_interface
kernels
solver
Boost::program_options
${BOOST_LIBS}
pybind11::headers
)
target_compile_definitions(_core PRIVATE SPECFEMPP_ENABLE_PYTHON)
Expand Down
1 change: 1 addition & 0 deletions tests/unit-tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip
DOWNLOAD_EXTRACT_TIMESTAMP FALSE
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
Expand Down

0 comments on commit f7d4465

Please sign in to comment.