-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
304 lines (281 loc) · 10.7 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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
# See www/CMake.html for instructions on how to build libcxx with CMake.
#===============================================================================
# Setup Project
#===============================================================================
project(libcxx CXX C)
cmake_minimum_required(VERSION 2.8)
set(PACKAGE_NAME libcxx)
set(PACKAGE_VERSION trunk-svn)
set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
set(PACKAGE_BUGREPORT "[email protected]")
# Add path for custom modules
set(CMAKE_MODULE_PATH
${CMAKE_MODULE_PATH}
"${CMAKE_CURRENT_SOURCE_DIR}/cmake"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules"
)
# Require out of source build.
include(MacroEnsureOutOfSourceBuild)
MACRO_ENSURE_OUT_OF_SOURCE_BUILD(
"${PROJECT_NAME} requires an out of source build. Please create a separate
build directory and run 'cmake /path/to/${PROJECT_NAME} [options]' there."
)
#===============================================================================
# Setup CMake Options
#===============================================================================
# Define options.
option(LIBCXX_ENABLE_EXCEPTIONS "Use exceptions." ON)
option(LIBCXX_ENABLE_RTTI "Use run time type information." ON)
option(LIBCXX_ENABLE_ASSERTIONS "Enable assertions independent of build mode." ON)
option(LIBCXX_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
option(LIBCXX_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
option(LIBCXX_ENABLE_CXX0X "Enable -std=c++0x and use of c++0x language features if the compiler supports it." ON)
option(LIBCXX_ENABLE_SHARED "Build libc++ as a shared library." ON)
set(CXXABIS none libcxxabi libcxxrt libsupc++)
if (NOT DEFINED LIBCXX_CXX_ABI)
set(LIBCXX_CXX_ABI "none")
endif()
set(LIBCXX_CXX_ABI "${LIBCXX_CXX_ABI}" CACHE STRING
"Specify C++ ABI library to use." FORCE)
set_property(CACHE LIBCXX_CXX_ABI PROPERTY STRINGS "";${CXXABIS})
#===============================================================================
# Configure System
#===============================================================================
# Get triples.
include(GetTriple)
get_host_triple(LIBCXX_HOST_TRIPLE
LIBCXX_HOST_ARCH
LIBCXX_HOST_VENDOR
LIBCXX_HOST_OS
)
set(LIBCXX_HOST_TRIPLE ${LIBCXX_HOST_TRIPLE} CACHE STRING "Host triple.")
get_target_triple(LIBCXX_TARGET_TRIPLE
LIBCXX_TARGET_ARCH
LIBCXX_TARGET_VENDOR
LIBCXX_TARGET_OS
)
set(LIBCXX_TARGET_TRIPLE ${LIBCXX_TARGET_TRIPLE} CACHE STRING "Target triple.")
if ("${LIBCXX_CXX_ABI}" STREQUAL "libsupc++")
add_definitions(-D__GLIBCXX__)
set(LIBCXX_LIBSUPCXX_INCLUDE_PATHS "${LIBCXX_LIBSUPCXX_INCLUDE_PATHS}"
CACHE STRINGS
"Paths to libsupc++ include directories separate by ';'.")
set(LIBCXX_CXX_ABI_LIBRARIES supc++)
set(LIBCXX_LIBSUPCXX_FILES
cxxabi.h
bits/c++config.h
bits/os_defines.h
bits/cpu_defines.h
bits/cxxabi_tweaks.h
bits/cxxabi_forced.h
)
# Create include directories.
file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/include")
file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/include/bits")
set(LIBCXX_LIBSUPCXX_FILE_PATHS)
foreach(path ${LIBCXX_LIBSUPCXX_FILES})
set(found FALSE)
foreach(incpath ${LIBCXX_LIBSUPCXX_INCLUDE_PATHS})
if (EXISTS "${incpath}/${path}")
set(found TRUE)
get_filename_component(dstdir ${path} PATH)
get_filename_component(file ${path} NAME)
add_custom_command(
OUTPUT "${CMAKE_BINARY_DIR}/include/${dstdir}/${file}"
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${incpath}/${path}"
"${CMAKE_BINARY_DIR}/include/${dstdir}"
MAIN_DEPENDENCY "${incpath}/${path}"
)
list(APPEND LIBCXX_CXX_ABI_DEPS
"${CMAKE_BINARY_DIR}/include/${dstdir}/${file}")
endif()
endforeach()
if (NOT found)
message(FATAL_ERROR "Failed to find ${path}")
endif()
endforeach()
add_custom_target(supcxx_headers DEPENDS ${LIBCXX_CXX_ABI_DEPS})
set(LIBCXX_CXX_ABI_DEPS supcxx_headers)
include_directories("${CMAKE_BINARY_DIR}/include")
install(DIRECTORY "${CMAKE_BINARY_DIR}/include/"
DESTINATION include/c++/v1
FILES_MATCHING
PATTERN "*"
)
elseif ("${LIBCXX_CXX_ABI}" STREQUAL "libcxxabi")
set(LIBCXX_LIBCXXABI_INCLUDE_PATHS "${LIBCXX_LIBCXXABI_INCLUDE_PATHS}"
CACHE STRINGS
"Paths to libc++abi include directories separate by ';'.")
set(LIBCXX_CXX_ABI_LIBRARIES c++abi)
set(LIBCXX_LIBCXXABI_FILES
cxxabi.h
cxa_demangle.h
)
file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/include")
set(LIBCXX_LIBCXXABI_FILE_PATHS)
foreach(path ${LIBCXX_LIBCXXABI_FILES})
set(found FALSE)
foreach(incpath ${LIBCXX_LIBCXXABI_INCLUDE_PATHS})
if (EXISTS "${incpath}/${path}")
set(found TRUE)
get_filename_component(file ${path} NAME)
add_custom_command(
OUTPUT "${CMAKE_BINARY_DIR}/include/${file}"
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${incpath}/${path}"
"${CMAKE_BINARY_DIR}/include"
MAIN_DEPENDENCY "${incpath}/${path}"
)
list(APPEND LIBCXX_CXX_ABI_DEPS
"${CMAKE_BINARY_DIR}/include/${file}")
endif()
endforeach()
if (NOT found)
message(FATAL_ERROR "Failed to find ${path}")
endif()
endforeach()
add_custom_target(cxxabi_headers DEPENDS ${LIBCXX_CXX_ABI_DEPS})
set(LIBCXX_CXX_ABI_DEPS cxxabi_headers)
include_directories("${CMAKE_BINARY_DIR}/include")
install(DIRECTORY "${CMAKE_BINARY_DIR}/include/"
DESTINATION include/c++/v1
FILES_MATCHING
PATTERN "*"
)
elseif ("${LIBCXX_CXX_ABI}" STREQUAL "libcxxrt")
set(LIBCXX_LIBCXXRT_INCLUDE_PATHS "${LIBCXX_LIBCXXRT_INCLUDE_PATHS}"
CACHE STRINGS
"Paths to libcxxrt include directories separate by ';'.")
set(LIBCXX_CXX_ABI_LIBRARIES cxxrt)
set(LIBCXX_LIBCXXRT_FILES
cxxabi.h
unwind.h
unwind-arm.h
unwind-itanium.h
)
file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/include")
set(LIBCXX_LIBCXXRT_FILE_PATHS)
foreach(path ${LIBCXX_LIBCXXRT_FILES})
set(found FALSE)
foreach(incpath ${LIBCXX_LIBCXXRT_INCLUDE_PATHS})
if (EXISTS "${incpath}/${path}")
set(found TRUE)
get_filename_component(file ${path} NAME)
add_custom_command(
OUTPUT "${CMAKE_BINARY_DIR}/include/${file}"
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${incpath}/${path}"
"${CMAKE_BINARY_DIR}/include"
MAIN_DEPENDENCY "${incpath}/${path}"
)
list(APPEND LIBCXX_CXX_ABI_DEPS
"${CMAKE_BINARY_DIR}/include/${file}")
endif()
endforeach()
if (NOT found)
message(FATAL_ERROR "Failed to find ${path}")
endif()
endforeach()
add_custom_target(cxxrt_headers DEPENDS ${LIBCXX_CXX_ABI_DEPS})
set(LIBCXX_CXX_ABI_DEPS cxxrt_headers)
include_directories("${CMAKE_BINARY_DIR}/include")
install(DIRECTORY "${CMAKE_BINARY_DIR}/include/"
DESTINATION include/c++/v1
FILES_MATCHING
PATTERN "*"
)
list(APPEND LIBCXX_CXX_FEATURE_FLAGS -DLIBCXXRT)
elseif (NOT "${LIBCXX_CXX_ABI}" STREQUAL "none")
message(FATAL_ERROR
"Currently only none and libsupc++ are supported for c++ abi.")
endif ()
# Configure compiler.
include(config-ix)
#===============================================================================
# Setup Compiler Flags
#===============================================================================
# Get required flags.
# On all systems the system c++ standard library headers need to be excluded.
if (MSVC)
# MSVC only has -X, which disables all default includes; including the crt.
# Thus, we do nothing and hope we don't accidentally include any of the C++
# headers.
else()
if (LIBCXX_HAS_NOSTDINCXX_FLAG)
set(LIBCXX_CXX_REQUIRED_FLAGS -nostdinc++)
endif()
if (LIBCXX_ENABLE_CXX0X AND LIBCXX_HAS_STDCXX0X_FLAG)
list(APPEND LIBCXX_CXX_REQUIRED_FLAGS -std=c++0x)
endif()
endif()
macro(append_if list condition var)
if (${condition})
list(APPEND ${list} ${var})
endif()
endmacro()
# Get warning flags
append_if(LIBCXX_CXX_WARNING_FLAGS LIBCXX_HAS_WALL_FLAG -Wall)
append_if(LIBCXX_CXX_WARNING_FLAGS LIBCXX_HAS_W_FLAG -W)
append_if(LIBCXX_CXX_WARNING_FLAGS LIBCXX_HAS_WNO_UNUSED_PARAMETER_FLAG -Wno-unused-parameter)
append_if(LIBCXX_CXX_WARNING_FLAGS LIBCXX_HAS_WWRITE_STRINGS_FLAG -Wwrite-strings)
append_if(LIBCXX_CXX_WARNING_FLAGS LIBCXX_HAS_WNO_LONG_LONG_FLAG -Wno-long-long)
if (LIBCXX_ENABLE_WERROR)
append_if(LIBCXX_CXX_WARNING_FLAGS LIBCXX_HAS_WERROR_FLAG -Werror)
append_if(LIBCXX_CXX_WARNING_FLAGS LIBCXX_HAS_WX_FLAG -WX)
endif()
if (LIBCXX_ENABLE_PEDANTIC)
append_if(LIBCXX_CXX_WARNING_FLAGS LIBCXX_HAS_PEDANTIC_FLAG -pedantic)
endif()
# Get feature flags.
# Exceptions
if (LIBCXX_ENABLE_EXCEPTIONS)
# Catches C++ exceptions only and tells the compiler to assume that extern C
# functions never throw a C++ exception.
append_if(LIBCXX_CXX_FEATURE_FLAGS LIBCXX_HAS_EHSC_FLAG -EHsc)
else()
list(APPEND LIBCXX_CXX_FEATURE_FLAGS -D_LIBCPP_NO_EXCEPTIONS)
append_if(LIBCXX_CXX_FEATURE_FLAGS LIBCXX_HAS_NO_EHS_FLAG -EHs-)
append_if(LIBCXX_CXX_FEATURE_FLAGS LIBCXX_HAS_NO_EHA_FLAG -EHa-)
append_if(LIBCXX_CXX_FEATURE_FLAGS LIBCXX_HAS_FNO_EXCEPTIONS_FLAG -fno-exceptions)
endif()
# RTTI
if (NOT LIBCXX_ENABLE_RTTI)
list(APPEND LIBCXX_CXX_FEATURE_FLAGS -D_LIBCPP_NO_RTTI)
append_if(LIBCXX_CXX_FEATURE_FLAGS LIBCXX_HAS_NO_GR_FLAG -GR-)
append_if(LIBCXX_CXX_FEATURE_FLAGS LIBCXX_HAS_FNO_RTTI_FLAG -fno-rtti)
endif()
# Assert
string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
if (LIBCXX_ENABLE_ASSERTIONS)
# MSVC doesn't like _DEBUG on release builds. See PR 4379.
if (NOT MSVC)
list(APPEND LIBCXX_CXX_FEATURE_FLAGS -D_DEBUG)
endif()
# On Release builds cmake automatically defines NDEBUG, so we
# explicitly undefine it:
if (uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE")
list(APPEND LIBCXX_CXX_FEATURE_FLAGS -UNDEBUG)
endif()
else()
if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE")
list(APPEND LIBCXX_CXX_FEATURE_FLAGS -DNDEBUG)
endif()
endif()
# This is the _ONLY_ place where add_definitions is called.
add_definitions(
${LIBCXX_CXX_REQUIRED_FLAGS}
${LIBCXX_CXX_WARNING_FLAGS}
${LIBCXX_CXX_FEATURE_FLAGS}
)
#===============================================================================
# Setup Source Code
#===============================================================================
include_directories(include)
# Add source code. This also contains all of the logic for deciding linker flags
# soname, etc...
add_subdirectory(lib)
#===============================================================================
# Setup Tests
#===============================================================================
add_subdirectory(test)