Skip to content
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
184 changes: 109 additions & 75 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,91 +1,125 @@
###################################################################################################
# Copyright (c) 2021, Lawrence Livermore National Security, LLC and LvArray contributors.
# All rights reserved.
# See the LICENSE file for details.
# SPDX-License-Identifier: (BSD-3-Clause)
###################################################################################################

cmake_minimum_required( VERSION 3.23.1 )

# Set version number
set( SHIVA_VERSION_MAJOR 0 )
set( SHIVA_VERSION_MINOR 1 )
set( SHIVA_VERSION_PATCHLEVEL 0 )

# check if Shiva is build as a submodule or a separate project
get_directory_property( parent_dir PARENT_DIRECTORY )
if(parent_dir)
set( SHIVA_IS_SUBMODULE ON )
else()
set( SHIVA_IS_SUBMODULE OFF )
cmake_minimum_required(VERSION 3.23.1)
project(Shiva VERSION 0.1.0)

# Portable install dir vars: ${CMAKE_INSTALL_INCLUDEDIR}, ${CMAKE_INSTALL_LIBDIR}, etc.
include(GNUInstallDirs)

# -------- Options (lean) -------------------------------------------------------
option( SHIVA_ENABLE_BLT "Enable BLT integration (testing, packaging, etc.)" OFF )
option( SHIVA_ENABLE_CUDA "Enable CUDA code paths in headers (interface define only)" OFF )
option( SHIVA_ENABLE_HIP "Enable HIP code paths in headers (interface define only)" OFF )
option( SHIVA_ENABLE_UNIT_TESTS "Build unit tests (standalone only)" OFF )
option( SHIVA_ENABLE_CAMP "Link against CAMP if available" OFF )
option( SHIVA_BUILD_OBJ_LIBS "Build object libraries...useful for dependency trees" OFF )
option( SHIVA_ENABLE_BOUNDS_CHECK "Enable bounds checking in shiva::CArray" OFF )

if( ENABLE_CUDA )
set( SHIVA_ENABLE_CUDA ON )
endif()

if( NOT SHIVA_IS_SUBMODULE )
message( "not a submodule")
project( Shiva LANGUAGES CXX C )

set( BLT_CXX_STD "c++17" CACHE STRING "Version of C++ standard" FORCE )
set( ENABLE_WARNINGS_AS_ERRORS "ON" CACHE PATH "" )

option( SHIVA_ENABLE_UNIT_TESTS "Builds tests" ON )
option( SHIVA_ENABLE_EXAMPLES "Builds examples" ON )
option( SHIVA_ENABLE_BENCHMARKS "Builds benchmarks" ON )
option( SHIVA_ENABLE_DOCS "Builds documentation" ON )

option( ENABLE_CUDA "Build with CUDA" OFF )
option( ENABLE_HIP "Build with HIP" OFF )

if( NOT BLT_LOADED )
if( DEFINED BLT_SOURCE_DIR )
if( NOT EXISTS ${BLT_SOURCE_DIR}/SetupBLT.cmake )
message( FATAL_ERROR "Given BLT_SOURCE_DIR does not contain SetupBLT.cmake" )
endif()
else ()
set( BLT_SOURCE_DIR ${PROJECT_SOURCE_DIR}/cmake/blt CACHE PATH "" )

if( NOT EXISTS ${BLT_SOURCE_DIR}/SetupBLT.cmake )
message( FATAL_ERROR "The BLT submodule is not present. If in git repository run the following two commands:\n \
git submodule init\n \
git submodule update" )
endif ()
endif ()

include( ${BLT_SOURCE_DIR}/SetupBLT.cmake )
endif()
if( ENABLE_HIP )
set( SHIVA_ENABLE_HIP ON )
endif()

include( cmake/CMakeBasics.cmake )
#include( cmake/SetupTPL.cmake )
else()
if( NOT BLT_LOADED )
message( FATAL_ERROR "When using Shiva as a submodule you must have already loaded BLT." )
endif()
include( cmake/CMakeBasics.cmake )
if( SHIVA_ENABLE_CUDA AND SHIVA_ENABLE_HIP )
message( FATAL_ERROR "CUDA and HIP are mutually exclusive; enable only one." )
endif()

include( cmake/Macros.cmake )
include( cmake/Config.cmake )

# Top-level or subproject?
set( SHIVA_IS_TOPLEVEL "${PROJECT_IS_TOP_LEVEL}" )

set(SHIVA_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} )
set(SHIVA_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR} )
# Convenience dirs
set( SHIVA_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}" )
set( SHIVA_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}" )

message( STATUS "SHIVA_BINARY_DIR: ${SHIVA_BINARY_DIR}" )
message( STATUS "SHIVA_SOURCE_DIR: ${SHIVA_SOURCE_DIR}" )
# -------- Generate config header ----------------------------------------------
# Expects: include/shiva/ShivaConfig.hpp.in
include( "${CMAKE_CURRENT_LIST_DIR}/cmake/Config.cmake" )

# -------- Header-only target ---------------------------------------------------
add_library(Shiva INTERFACE)
add_library(Shiva::shiva ALIAS Shiva)

add_subdirectory( src )
target_include_directories( Shiva INTERFACE
"$<BUILD_INTERFACE:${SHIVA_SOURCE_DIR}/include>" # include/shiva/...
"$<BUILD_INTERFACE:${SHIVA_BINARY_DIR}/include>" # build/include/shiva/ShivaConfig.hpp
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>" )

if( SHIVA_ENABLE_CAMP )
add_subdirectory( tpl/camp )
target_compile_options( camp PRIVATE "-Wno-shadow")
target_compile_features(Shiva INTERFACE cxx_std_17)

configure_file(tpl/camp/include/camp/config.in.hpp
${PROJECT_BINARY_DIR}/include/camp/config.hpp)
endif()
# -------- BLT (optional; usable as top-level or submodule) ---------------------
if( SHIVA_ENABLE_BLT )
set( BLT_CXX_STD "c++17" )
# Load BLT if Shiva is standalone
if( SHIVA_IS_TOPLEVEL )
set(BLT_SOURCE_DIR "${PROJECT_SOURCE_DIR}/cmake/blt" CACHE PATH "Path to BLT")
if (NOT EXISTS "${BLT_SOURCE_DIR}/SetupBLT.cmake")
message(FATAL_ERROR "BLT not found at '${BLT_SOURCE_DIR}'.")
endif()
include("${BLT_SOURCE_DIR}/SetupBLT.cmake")
else()

endif( SHIVA_IS_TOPLEVEL )

if( SHIVA_ENABLE_DOCS )
add_subdirectory( docs )
endif()

if( BLT_LOADED )
message( STATUS "BLT loaded successfully." )
else()
message( FATAL_ERROR "BLT requested but failed to load." )
endif( BLT_LOADED )



if( SHIVA_ENABLE_CAMP )
add_subdirectory(tpl/camp) # vendored fallback when standalone
target_link_libraries(Shiva INTERFACE camp)
endif()

if( SHIVA_ENABLE_UNIT_TESTS )
# Enable GPU languages **only** for tests/examples at the top level
if ( SHIVA_ENABLE_CUDA AND NOT CMAKE_CUDA_COMPILER )
enable_language ( CUDA )
endif ()
if ( SHIVA_ENABLE_HIP AND NOT CMAKE_HIP_COMPILER )
enable_language ( HIP )
endif ()
message( STATUS "Building unit tests." )
add_subdirectory(tests)
else()
message( STATUS "Skipping unit tests." )
endif()

include( "${CMAKE_CURRENT_LIST_DIR}/cmake/Macros.cmake" )
shiva_add_code_checks( PREFIX shiva
EXCLUDES build* blt/* camp/* )

endif( SHIVA_ENABLE_BLT)


# -------- Install & package ----------------------------------------------------
install(TARGETS Shiva EXPORT ShivaTargets)

# Install public headers and generated config header tree
install( DIRECTORY "${SHIVA_SOURCE_DIR}/include/"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" )
install( DIRECTORY "${SHIVA_BINARY_DIR}/include/"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
OPTIONAL )

include( CMakePackageConfigHelpers )

write_basic_package_version_file( "${CMAKE_CURRENT_BINARY_DIR}/ShivaConfigVersion.cmake"
VERSION "${PROJECT_VERSION}"
COMPATIBILITY SameMajorVersion )

configure_package_config_file( "${CMAKE_CURRENT_LIST_DIR}/cmake/ShivaConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/ShivaConfig.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Shiva" )

install( FILES "${CMAKE_CURRENT_BINARY_DIR}/ShivaConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/ShivaConfigVersion.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Shiva" )
install( EXPORT ShivaTargets
FILE ShivaTargets.cmake
NAMESPACE Shiva::
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Shiva" )
46 changes: 0 additions & 46 deletions cmake/CMakeBasics.cmake

This file was deleted.

91 changes: 31 additions & 60 deletions cmake/Config.cmake
Original file line number Diff line number Diff line change
@@ -1,65 +1,36 @@
#
set( PREPROCESSOR_DEFINES CUDA
HIP
CAMP
BOUNDS_CHECK
)

set( USE_CONFIGFILE ON CACHE BOOL "" )
foreach( DEP in ${PREPROCESSOR_DEFINES})
if( ${DEP}_FOUND OR ENABLE_${DEP} OR SHIVA_ENABLE_${DEP} )
set( SHIVA_USE_${DEP} TRUE )
endif()
endforeach()

if( ENABLE_ADDR2LINE )
if ( NOT DEFINED ADDR2LINE_EXEC )
set( ADDR2LINE_EXEC /usr/bin/addr2line CACHE PATH "" )
endif()

if ( NOT EXISTS ${ADDR2LINE_EXEC} )
message( FATAL_ERROR "The addr2line executable does not exist: ${ADDR2LINE_EXEC}" )
endif()

set( SHIVA_ADDR2LINE_EXEC ${ADDR2LINE_EXEC} )
# cmake/Config.cmake
include_guard(DIRECTORY)

# ---------- Version numbers expected by the header ----------
# Your header expects *_PATCHLEVEL; map from project() version.
set(SHIVA_VERSION_MAJOR "${PROJECT_VERSION_MAJOR}")
set(SHIVA_VERSION_MINOR "${PROJECT_VERSION_MINOR}")
set(SHIVA_VERSION_PATCHLEVEL "${PROJECT_VERSION_PATCH}")


# ---------- CUDA version numbers (if available) ----------
set(SHIVA_CUDA_MAJOR 0)
set(SHIVA_CUDA_MINOR 0)
if (SHIVA_ENABLE_CUDA AND DEFINED CMAKE_CUDA_COMPILER_VERSION)
# CMAKE_CUDA_COMPILER_VERSION like "12.4"
string(REPLACE "." ";" _cuda_ver_list "${CMAKE_CUDA_COMPILER_VERSION}")
list(GET _cuda_ver_list 0 SHIVA_CUDA_MAJOR)
list(LENGTH _cuda_ver_list _cuda_len)
if (_cuda_len GREATER 1)
list(GET _cuda_ver_list 1 SHIVA_CUDA_MINOR)
endif()
endif()


configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/src/ShivaConfig.hpp.in
${CMAKE_BINARY_DIR}/include/ShivaConfig.hpp )

configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/src/ShivaConfig.hpp.in
${CMAKE_CURRENT_SOURCE_DIR}/docs/doxygen/ShivaConfig.hpp )

# Install the generated header.
install( FILES ${CMAKE_BINARY_DIR}/include/ShivaConfig.hpp
DESTINATION include )

# Configure and install the CMake config

# Set up cmake package config file

set(SHIVA_INSTALL_INCLUDE_DIR "include" CACHE STRING "")
set(SHIVA_INSTALL_CONFIG_DIR "lib" CACHE STRING "")
set(SHIVA_INSTALL_LIB_DIR "lib" CACHE STRING "")
set(SHIVA_INSTALL_BIN_DIR "bin" CACHE STRING "")
set(SHIVA_INSTALL_CMAKE_MODULE_DIR "${SHIVA_INSTALL_CONFIG_DIR}/cmake" CACHE STRING "")
set(SHIVA_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX} CACHE STRING "" FORCE)


include(CMakePackageConfigHelpers)
configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/shiva-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/shiva-config.cmake
INSTALL_DESTINATION
${SHIVA_INSTALL_CONFIG_DIR}
PATH_VARS
SHIVA_INSTALL_INCLUDE_DIR
SHIVA_INSTALL_LIB_DIR
SHIVA_INSTALL_BIN_DIR
SHIVA_INSTALL_CMAKE_MODULE_DIR
)
# ---------- Emit the generated header(s) ----------
set(_shiva_gen_inc "${SHIVA_BINARY_DIR}/include/shiva")
file(MAKE_DIRECTORY "${_shiva_gen_inc}")

configure_file( "${SHIVA_SOURCE_DIR}/include/shiva/ShivaConfig.hpp.in"
"${_shiva_gen_inc}/ShivaConfig.hpp" )

install( FILES ${CMAKE_CURRENT_BINARY_DIR}/shiva-config.cmake
DESTINATION share/shiva/cmake/)
# Optional: a copy for Doxygen without touching the source tree
set(_shiva_gen_doc "${SHIVA_BINARY_DIR}/docs/doxygen")
file(MAKE_DIRECTORY "${_shiva_gen_doc}")
configure_file( "${SHIVA_SOURCE_DIR}/include/shiva/ShivaConfig.hpp.in"
"${_shiva_gen_doc}/ShivaConfig.hpp" )
2 changes: 1 addition & 1 deletion cmake/Macros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ macro(shiva_add_code_checks)
if (ENABLE_COVERAGE)
blt_add_code_coverage_target(NAME ${arg_PREFIX}_coverage
RUNNER ctest -E 'blt_gtest_smoke|testCppCheck|testClangTidy|testUncrustifyCheck|testDoxygenCheck|testCppCheck|testClangTidy'
SOURCE_DIRECTORIES ${PROJECT_SOURCE_DIR}/src )
SOURCE_DIRECTORIES ${PROJECT_SOURCE_DIR}/include )
endif()
endmacro(shiva_add_code_checks)
12 changes: 12 additions & 0 deletions cmake/ShivaConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# cmake/ShivaConfig.cmake.in
@PACKAGE_INIT@ # sets up PACKAGE_PREFIX_DIR etc.

# If Shiva has installed-time deps, find them here (optional):
include(CMakeFindDependencyMacro)
# find_dependency(camp CONFIG) # uncomment if you install+use camp externally

# Import the exported targets for this package
include("${CMAKE_CURRENT_LIST_DIR}/ShivaTargets.cmake")

# (Optional) convenience vars
set(Shiva_INCLUDE_DIRS "${PACKAGE_PREFIX_DIR}/@CMAKE_INSTALL_INCLUDEDIR@")
2 changes: 1 addition & 1 deletion cmake/blt
Submodule blt updated 611 files
11 changes: 0 additions & 11 deletions cmake/shiva-config.cmake.in

This file was deleted.

Loading