-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
125 lines (96 loc) · 4.67 KB
/
CMakeLists.txt
File metadata and controls
125 lines (96 loc) · 4.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
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( ENABLE_HIP )
set( SHIVA_ENABLE_HIP ON )
endif()
if( SHIVA_ENABLE_CUDA AND SHIVA_ENABLE_HIP )
message( FATAL_ERROR "CUDA and HIP are mutually exclusive; enable only one." )
endif()
# Top-level or subproject?
set( SHIVA_IS_TOPLEVEL "${PROJECT_IS_TOP_LEVEL}" )
# Convenience dirs
set( SHIVA_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}" )
set( SHIVA_BINARY_DIR "${CMAKE_CURRENT_BINARY_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)
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}>" )
target_compile_features(Shiva INTERFACE cxx_std_17)
# -------- 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( 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" )