This repository has been archived by the owner on Mar 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 187
/
CMakeLists.txt
232 lines (187 loc) · 7.58 KB
/
CMakeLists.txt
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# 3.15 is the minimum.
# 3.17 for NVC++.
# 3.18 for C++17 + CUDA.
cmake_minimum_required(VERSION 3.15)
# Determine whether libcudacxx is the top-level project or included into
# another project via add_subdirectory().
if ("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_LIST_DIR}")
set(LIBCUDACXX_TOPLEVEL_PROJECT ON)
else()
set(LIBCUDACXX_TOPLEVEL_PROJECT OFF)
endif()
set(PACKAGE_NAME libcudacxx)
set(PACKAGE_VERSION 11.0)
set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
project(libcudacxx NONE)
include(cmake/libcudacxxInstallRules.cmake)
if (NOT LIBCUDACXX_TOPLEVEL_PROJECT)
include(cmake/libcudacxxAddSubdir.cmake)
return()
endif()
# Note that this currently returns and skips the rest of the build
# system.
option(libcudacxx_ENABLE_CMAKE_TESTS "Enable ctest-based testing." OFF)
if (libcudacxx_ENABLE_CMAKE_TESTS)
# Might be able to lower this, but would need to do some testing:
cmake_minimum_required(VERSION 3.20.1)
include(CTest)
enable_testing() # Must be called in root CMakeLists.txt
add_subdirectory(cmake/test/)
return()
endif()
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
set(LLVM_PATH "${CMAKE_SOURCE_DIR}" CACHE STRING "" FORCE)
# Configuration options.
option(LIBCUDACXX_ENABLE_CUDA "Enable the CUDA language support." ON)
set(_libcudacxx_enable_static_library OFF)
if ("${CMAKE_CUDA_COMPILER_ID}" STREQUAL "NVCXX")
set(_libcudacxx_enable_static_library ON)
endif ()
option(LIBCUDACXX_ENABLE_STATIC_LIBRARY "Enable building the full C++ stdlib static library build."
${_libcudacxx_enable_static_library})
option(LIBCUDACXX_ENABLE_LIBCUDACXX_TESTS "Enable libcu++ tests." ON)
option(LIBCUDACXX_ENABLE_LIBCXX_TESTS "Enable upstream libc++ tests." OFF)
option(LIBCUDACXX_ENABLE_LIBCXXABI_TESTS "Enable upstream libc++abi tests." OFF)
option(LIBCUDACXX_ENABLE_LIBUNWIND_TESTS "Enable upstream libunwind tests." OFF)
# This must be done before any languages are enabled:
if (LIBCUDACXX_TOPLEVEL_PROJECT)
include(cmake/libcudacxxCompilerHacks.cmake)
endif()
# This must appear after our Compiler Hacks or else CMake will delete the cache
# and reconfigure from scratch.
# This must also appear before the installation rules, as it is required by the
# GNUInstallDirs CMake module.
enable_language(CXX)
if (LIBCUDACXX_ENABLE_CUDA)
enable_language(CUDA)
endif ()
set(_libcudacxx_enable_upstream_tests OFF)
if (LIBCUDACXX_ENABLE_LIBCXX_TESTS
OR LIBCUDACXX_ENABLE_LIBCXXABI_TESTS
OR LIBCUDACXX_ENABLE_LIBUNWIND_TESTS)
set(_libcudacxx_enable_upstream_tests ON)
endif ()
set(_libcudacxx_enable_tests OFF)
if (_libcudacxx_enable_upstream_tests OR LIBCUDACXX_ENABLE_LIBCUDACXX_TESTS)
set(_libcudacxx_enable_tests ON)
endif ()
if (LIBCUDACXX_ENABLE_STATIC_LIBRARY OR _libcudacxx_enable_upstream_tests)
enable_language(C ASM)
endif ()
if (_libcudacxx_enable_tests OR LIBCUDACXX_ENABLE_STATIC_LIBRARY)
include(FindPythonInterp)
if (NOT PYTHONINTERP_FOUND)
message(FATAL_ERROR
"Failed to find python interpreter, which is required for running tests and "
"building a libcu++ static library.")
endif ()
endif ()
# Determine the host triple to avoid invoking `${CXX} -dumpmachine`.
include(GetHostTriple)
get_host_triple(LLVM_INFERRED_HOST_TRIPLE)
set(LLVM_HOST_TRIPLE "${LLVM_INFERRED_HOST_TRIPLE}" CACHE STRING
"Host on which LLVM binaries will run")
# By default, we target the host, but this can be overridden at CMake
# invocation time.
set(LLVM_DEFAULT_TARGET_TRIPLE "${LLVM_HOST_TRIPLE}" CACHE STRING
"Default target for which LLVM will generate code." )
set(TARGET_TRIPLE "${LLVM_DEFAULT_TARGET_TRIPLE}")
message(STATUS "LLVM host triple: ${LLVM_HOST_TRIPLE}")
message(STATUS "LLVM default target triple: ${LLVM_DEFAULT_TARGET_TRIPLE}")
# Determine which of the components we need to add to the build.
# By default, none.
# These variables are overriden later on if they are determined to be needed.
set(_libcudacxx_add_libcxx OFF)
set(_libcudacxx_add_libcxxabi OFF)
set(_libcudacxx_add_libunwind OFF)
# Configure options needed to build the standalone static library.
if (LIBCUDACXX_ENABLE_STATIC_LIBRARY)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "NVHPC")
option(LIBUNWIND_ENABLE_PEDANTIC OFF)
add_definitions(-D__USER_LABEL_PREFIX__=)
endif()
option(LIBUNWIND_ENABLE_STATIC "" ON)
option(LIBUNWIND_ENABLE_SHARED "" OFF)
#set(HAVE_LIBUNWIND ON CACHE BOOL "")
option(LIBCXXABI_USE_LLVM_UNWINDER "" ON)
option(LIBCXXABI_ENABLE_STATIC "" ON)
option(LIBCXXABI_ENABLE_SHARED "" OFF)
option(LIBCXXABI_ENABLE_STATIC_UNWINDER "" ON)
option(LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY "" ON)
option(LIBCXX_ENABLE_STATIC "" ON)
option(LIBCXX_ENABLE_STATIC_ABI_LIBRARY "" ON)
option(LIBCXX_ENABLE_SHARED "" OFF)
option(LIBCXX_ENABLE_SHARED_ABI_LIBRARY "" OFF)
option(LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY "" ON)
if (NOT "${LIBCXX_CXX_ABI}" STREQUAL "" AND NOT "${LIBCXX_CXX_ABI}" STREQUAL "libcxxabi")
unset(LIBCXX_CXX_ABI CACHE)
message(FATAL_ERROR
"When building a standalone libcu++ static library, manually setting the "
"C++ ABI library is not supported. Please unset the LIBCXX_CXX_ABI variable.")
endif ()
set(LIBCXX_CXX_ABI "libcxxabi" CACHE STRING "")
set(LIBCXX_CXX_ABI_INCLUDE_PATHS "${CMAKE_CURRENT_SOURCE_DIR}/libcxxabi/include" CACHE STRING "")
set(LIBCXX_CXX_ABI_INTREE 1)
set(_libcudacxx_add_libcxx ON)
set(_libcudacxx_add_libcxxabi ON)
set(_libcudacxx_add_libunwind ON)
endif ()
if ("${LIBCXX_CXX_ABI}" STREQUAL "")
set(LIBCXX_CXX_ABI "libstdc++" CACHE STRING "")
endif ()
# Configure options needed to run tests.
if (_libcudacxx_enable_tests)
enable_testing()
set(LIT_EXTRA_ARGS "" CACHE STRING "Use for additional options (e.g. -j12)")
find_program(LLVM_DEFAULT_EXTERNAL_LIT lit)
set(LLVM_LIT_ARGS "-sv ${LIT_EXTRA_ARGS}")
if (LIBCUDACXX_ENABLE_LIBCUDACXX_TESTS)
set(LIBCUDACXX_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
add_subdirectory(test)
endif ()
if (LIBCUDACXX_ENABLE_LIBCXX_TESTS)
option(LIBCXX_INCLUDE_TESTS "" ON)
set(_libcudacxx_add_libcxx ON)
endif ()
if (LIBCUDACXX_ENABLE_LIBCXXABI_TESTS)
message(FATAL_ERROR "Running libc++abi tests is not supported yet.")
set(_libcudacxx_add_libcxxabi ON)
endif ()
if (LIBCUDACXX_ENABLE_LIBUNWIND_TESTS)
message(FATAL_ERROR "Running libunwind tests is not supported yet.")
set(_libcudacxx_add_libunwind ON)
endif ()
endif ()
# Configure the common options for the subdirections and add them.
if (_libcudacxx_add_libunwind)
add_subdirectory(libunwind)
endif ()
if (_libcudacxx_add_libcxxabi)
add_subdirectory(libcxxabi)
endif ()
if (_libcudacxx_add_libcxx)
option(LIBCXX_INCLUDE_BENCHMARKS "" OFF)
option(LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY "" OFF)
set(LIBCXX_HAVE_CXX_ATOMICS_WITHOUT_LIB ON)
add_subdirectory(libcxx)
endif ()
# Add a global check rule now that all subdirectories have been traversed
# and we know the total set of lit testsuites.
if (_libcudacxx_enable_tests)
include(AddLLVM)
get_property(LLVM_LIT_TESTSUITES GLOBAL PROPERTY LLVM_LIT_TESTSUITES)
get_property(LLVM_LIT_PARAMS GLOBAL PROPERTY LLVM_LIT_PARAMS)
get_property(LLVM_LIT_DEPENDS GLOBAL PROPERTY LLVM_LIT_DEPENDS)
get_property(LLVM_LIT_EXTRA_ARGS GLOBAL PROPERTY LLVM_LIT_EXTRA_ARGS)
get_property(LLVM_ADDITIONAL_TEST_TARGETS
GLOBAL PROPERTY LLVM_ADDITIONAL_TEST_TARGETS)
get_property(LLVM_ADDITIONAL_TEST_DEPENDS
GLOBAL PROPERTY LLVM_ADDITIONAL_TEST_DEPENDS)
add_lit_target(check-all
"Running all regression tests"
${LLVM_LIT_TESTSUITES}
PARAMS ${LLVM_LIT_PARAMS}
DEPENDS ${LLVM_LIT_DEPENDS} ${LLVM_ADDITIONAL_TEST_TARGETS}
ARGS ${LLVM_LIT_EXTRA_ARGS}
)
endif ()