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 updates #46

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 4 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ jobs:
- name: Checkout code
uses: actions/checkout@v2
with:
submodules: true
submodules: recursive
- name: Set system to non-interactive mode
run: export DEBIAN_FRONTEND=noninteractive
- name: install dependencies
run: sudo apt-get install -y --force-yes -qq build-essential libhdf5-serial-dev
run: |
sudo apt-get update -y -qq
sudo apt-get install -y --allow-downgrades --allow-remove-essential --allow-change-held-packages -qq build-essential libhdf5-serial-dev
- name: build and run tests
run: |
mkdir -p bin
Expand Down
5 changes: 4 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[submodule "utils/spiner"]
path = utils/spiner
url = https://github.com/lanl/spiner.git
url = https://github.com/lanl/spiner.git
[submodule "utils/variant"]
path = utils/variant
url = https://github.com/mpark/variant.git
Expand All @@ -10,3 +10,6 @@
[submodule "utils/kokkos"]
path = utils/kokkos
url = https://github.com/kokkos/kokkos.git
[submodule "utils/ports-of-call"]
path = utils/ports-of-call
url = https://github.com/lanl/ports-of-call.git
128 changes: 51 additions & 77 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,62 +1,63 @@
# © 2021. Triad National Security, LLC. All rights reserved. This
# program was produced under U.S. Government contract
# 89233218CNA000001 for Los Alamos National Laboratory (LANL), which
# is operated by Triad National Security, LLC for the U.S. Department
# of Energy/National Nuclear Security Administration. All rights in
# the program are reserved by Triad National Security, LLC, and the
# U.S. Department of Energy/National Nuclear Security
# Administration. The Government is granted for itself and others
# acting on its behalf a nonexclusive, paid-up, irrevocable worldwide
# license in this material to reproduce, prepare derivative works,
# distribute copies to the public, perform publicly and display
# publicly, and to permit others to do so.

cmake_minimum_required(VERSION 3.14)

project("singularity-opac"
VERSION 0.0.1
DESCRIPTION
""
HOMEPAGE_URL "https://github.com/lanl/singularity-opac/"
)
# © 2021. Triad National Security, LLC. All rights reserved. This program was
# produced under U.S. Government contract 89233218CNA000001 for Los Alamos
# National Laboratory (LANL), which is operated by Triad National Security, LLC
# for the U.S. Department of Energy/National Nuclear Security Administration.
# All rights in the program are reserved by Triad National Security, LLC, and
# the U.S. Department of Energy/National Nuclear Security Administration. The
# Government is granted for itself and others acting on its behalf a
# nonexclusive, paid-up, irrevocable worldwide license in this material to
# reproduce, prepare derivative works, distribute copies to the public, perform
# publicly and display publicly, and to permit others to do so.

cmake_minimum_required(VERSION 3.19)

project(
"singularity-opac"
VERSION 0.0.1
DESCRIPTION ""
HOMEPAGE_URL "https://github.com/lanl/singularity-opac/")

# Don't allow in-source builds
file(TO_CMAKE_PATH "${PROJECT_BINARY_DIR}/CMakeLists.txt" LOC_PATH)
if(EXISTS "${LOC_PATH}")
message(FATAL_ERROR
"You cannot build in a source directory (or any directory with a CMakeLists.txt file). "
"Please make a build subdirectory. Feel free to remove CMakeCache.txt and CMakeFiles.")
message(
FATAL_ERROR
"You cannot build in a source directory (or any directory with a CMakeLists.txt file). "
"Please make a build subdirectory. Feel free to remove CMakeCache.txt and CMakeFiles."
)
endif()

# If the user doesn't specify a build type, prefer RelWithDebInfo
set(default_build_type "RelWithDebInfo")
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to '${default_build_type}' as none was specified.")
set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE
STRING "Choose the type of build." FORCE)
message(
STATUS
"Setting build type to '${default_build_type}' as none was specified.")
set(CMAKE_BUILD_TYPE
"${default_build_type}"
CACHE STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
"Debug" "Release" "MinSizeRel" "RelWithDebInfo")
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
"MinSizeRel" "RelWithDebInfo")
endif()

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake)

# simplier interface, but note it may make things more convoluted
# as the project grows in size. For now, this is fine, but may
# want to split flags if more source is added.
add_library(${PROJECT_NAME} INTERFACE IMPORTED GLOBAL)
# simplier interface, but note it may make things more convoluted as the project
# grows in size. For now, this is fine, but may want to split flags if more
# source is added.
add_library(singularity-opac INTERFACE)
# so we can use with add_subdirectory
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
add_library(singularity-opac::singularity-opac ALIAS singularity-opac)

add_library (singularity-opac::flags INTERFACE IMPORTED GLOBAL)
target_include_directories(singularity-opac::flags
INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>)
target_include_directories(
singularity-opac INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>)

include (SetupDeps)
include (SetupOptions)
include (SetupCompilers)
include (SetupFlags)
include(SetupDeps)
include(SetupOptions)
include(SetupCompilers)
include(SetupFlags)

include(GNUInstallDirs)
include(CTest)
Expand All @@ -67,49 +68,22 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
set(IS_TOPLEVEL_PROJECT TRUE)
endif()


set(CMAKE_EXPORT_COMPILE_COMMANDS On)

# Patches variant to be compatible with cuda
# Assumes "patch" is present on system
# Patches variant to be compatible with cuda Assumes "patch" is present on
# system
message(STATUS "Patching mpark::variant to support GPUs")
execute_process(COMMAND patch -N -s -V never
${CMAKE_CURRENT_SOURCE_DIR}/utils/variant/include/mpark/variant.hpp
${CMAKE_CURRENT_SOURCE_DIR}/utils/cuda_compatibility.patch)

# xl fix
target_compile_options(singularity-opac::flags INTERFACE
$<$<COMPILE_LANG_AND_ID:CXX,XL>:-std=c++1y;-qxflag=disable__cplusplusOverride>)
target_link_options(singularity-opac::flags INTERFACE
$<$<COMPILE_LANG_AND_ID:CXX,XL>:-std=c++1y;-qxflag=disable__cplusplusOverride>)

if(CMAKE_BUILD_TYPE STREQUAL "Release")
target_compile_options(singularity-opac::flags INTERFACE
-use_fast_math)
elseif(CMAKE_BUILD_TYPE STREQUAL "Debug" AND SINGULARITY_BETTER_DEBUG_FLAGS)
target_compile_options(
singularity-opac::flags
INTERFACE
"$<$<COMPILE_LANGUAGE:CXX>:-G;-lineinfo;>"
)
endif()
execute_process(
COMMAND
patch -N -s -V never
${CMAKE_CURRENT_SOURCE_DIR}/utils/variant/include/mpark/variant.hpp
${CMAKE_CURRENT_SOURCE_DIR}/utils/cuda_compatibility.patch)

# Invoke CMake scripts for setup
if(SINGULARITY_INSTALL_LIBRARY)
include (SetupInstall)
include(SetupInstall)
endif()

if(SINGULARITY_BUILD_TESTS)
add_subdirectory(test)
endif()

set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")

include(CPack)

include(FeatureSummary)
feature_summary(WHAT ALL
INCLUDE_QUIET_PACKAGES
DESCRIPTION "Enabled Features:"
VAR enabledFeaturesText)
message(STATUS "${enabledFeaturesText}")
128 changes: 71 additions & 57 deletions cmake/SetupDeps.cmake
Original file line number Diff line number Diff line change
@@ -1,76 +1,90 @@
include(FeatureSummary)
#=======================================
# Setup CUDAToolkit
# - provideds CUDA::toolkit
#=======================================
if (NOT TARGET CUDA::toolkit)
# =======================================
# Setup CUDAToolkit - provideds CUDA::toolkit
# =======================================
if(NOT TARGET CUDA::toolkit)
find_package(CUDAToolkit QUIET)
else()
message(status "CUDA::toolkit provided by parent package")
endif()

#=======================================
# Setup ports of call
# - provides PortsofCall::PortsofCall
#=======================================
find_package(PortsofCall REQUIRED)
target_link_libraries(singularity-opac::flags INTERFACE PortsofCall::PortsofCall)
if(NOT TARGET mpark_variant)
add_subdirectory(utils/variant)
endif()
target_link_libraries(singularity-opac INTERFACE mpark_variant)
# =======================================
# Setup ports of call - provides PortsofCall::PortsofCall
# =======================================
find_package(ports-of-call QUIET)
if(NOT ports-of-call_FOUND)
add_subdirectory(utils/ports-of-call)
endif()
target_link_libraries(singularity-opac INTERFACE ports-of-call::ports-of-call)

find_package(spiner QUIET)
if(NOT spiner_FOUND)
add_subdirectory(utils/spiner)
endif()
target_link_libraries(singularity-opac INTERFACE spiner::spiner)

#=======================================
# Setup Kokkos
# - provides Kokkos::kokkos
#=======================================
if (NOT TARGET Kokkos::kokkos)
# =======================================
# Setup Kokkos - provides Kokkos::kokkos
# =======================================
if(NOT TARGET Kokkos::kokkos)
find_package(Kokkos QUIET)
else()
message(status "Kokkos::kokkos provided by parent package")
message(STATUS "Kokkos::kokkos provided by parent package")
endif()

if(NOT TARGET Kokkos::kokkos OR Kokkos_NOTFOUND)
message(STATUS "Kokkos not found, will not include in build requirements")
else()
target_link_libraries(singularity-opac INTERFACE Kokkos::kokkos)
endif()

#=======================================
# Find HDF5
# - [email protected]+ provides HDF5::HDF5, but
# prior versions do not
#=======================================
# Can't play the target games above unless using
# cmake 3.20+, so leave this one for now.
find_package(HDF5 COMPONENTS C HL QUIET)
# =======================================
# Find HDF5 - [email protected]+ provides HDF5::HDF5, but prior versions do not
# =======================================
# Can't play the target games above unless using cmake 3.20+, so leave this one
# for now.
find_package(
HDF5
COMPONENTS C HL
QUIET)

# findpackage doesnt export an interface for HDF5,
# so create one
if (HDF5_FOUND)
target_compile_definitions(singularity-opac::flags INTERFACE SPINER_USE_HDF)
add_library(${PROJECT_NAME}::hdf5 INTERFACE IMPORTED)
set_target_properties(${PROJECT_NAME}::hdf5
PROPERTIES
INTERFACE_LINK_LIBRARIES "${HDF5_LIBRARIES};${HDF5_HL_LIBRARIES}"
INTERFACE_COMPILE_DEFINITIONS "SINGULARITY_USE_HDF5;SPINER_USE_HDF"
INTERFACE_INCLUDE_DIRECTORIES "${HDF5_INCLUDE_DIRS}"
)
# findpackage doesnt export an interface for HDF5, so create one
if(HDF5_FOUND)
target_compile_definitions(singularity-opac
INTERFACE "SINGULARITY_USE_HDF5;SPINER_USE_HDF")
target_include_directories(singularity-opac INTERFACE "${HDF5_INCLUDE_DIRS}")
target_link_libraries(singularity-opac
INTERFACE "${HDF5_LIBRARIES};${HDF5_HL_LIBRARIES}")

# if HDF5 is parallel, also get MPI libraries
if (HDF5_IS_PARALLEL)
message(status "Parallel HDF5 found. Looking for MPI")
# Provides MPI::MPI_CXX
if (NOT TARGET MPI::MPI_CXX)
find_package(MPI COMPONENTS)# CXX REQUIRED)
if (NOT MPI_FOUND)
message(FATAL_ERROR
"HDF5 parallel found, but could not find MPI! "
"Try specifying a path to an MPI directory or MPI compiler "
" via -DMPI_HOME=/path or -DMPI_CXX_COMPILER=/path, "
"or set CMAKE_PREFIX_PATH to your preferred HDF5 directory "
"via -DCMAKE_PREFIX_PATH=/path.")
endif()
else()
message("MPI::MPI_CXX provided by parent package")
# if HDF5 is parallel, also get MPI libraries
if(HDF5_IS_PARALLEL)
message(status "Parallel HDF5 found. Looking for MPI")
# Provides MPI::MPI_CXX
if(NOT TARGET MPI::MPI_CXX)
find_package(MPI COMPONENTS) # CXX REQUIRED)
if(NOT MPI_FOUND)
message(
FATAL_ERROR
"HDF5 parallel found, but could not find MPI! "
"Try specifying a path to an MPI directory or MPI compiler "
" via -DMPI_HOME=/path or -DMPI_CXX_COMPILER=/path, "
"or set CMAKE_PREFIX_PATH to your preferred HDF5 directory "
"via -DCMAKE_PREFIX_PATH=/path.")
endif()
else()
message("MPI::MPI_CXX provided by parent package")
endif()
target_link_libraries(singularity-opac INTERFACE MPI::MPI_CXX)
endif()
endif()

#=======================================
# Setup Catch2
# - provides Catch2::Catch2
#=======================================
if (NOT TARGET Catch2::Catch2)
# =======================================
# Setup Catch2 - provides Catch2::Catch2
# =======================================
if(NOT TARGET Catch2::Catch2)
find_package(Catch2 QUIET)
endif()
Loading