1 # This CMake module is responsible for interpreting the user defined LLVM_
2 # options and executing the appropriate CMake commands to realize the users'
5 # This is commonly needed so make sure it's defined before we include anything
7 string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
9 include(CheckCompilerVersion)
10 include(CheckProblematicConfigurations)
11 include(HandleLLVMStdlib)
12 include(CheckCCompilerFlag)
13 include(CheckCXXCompilerFlag)
14 include(CheckSymbolExists)
15 include(CMakeDependentOption)
16 include(LLVMProcessSources)
18 if(CMAKE_LINKER MATCHES ".*lld" OR (LLVM_USE_LINKER STREQUAL "lld" OR LLVM_ENABLE_LLD))
19 set(LINKER_IS_LLD TRUE)
21 set(LINKER_IS_LLD FALSE)
24 if(CMAKE_LINKER MATCHES "lld-link" OR (MSVC AND (LLVM_USE_LINKER STREQUAL "lld" OR LLVM_ENABLE_LLD)))
25 set(LINKER_IS_LLD_LINK TRUE)
27 set(LINKER_IS_LLD_LINK FALSE)
30 set(LLVM_ENABLE_LTO OFF CACHE STRING "Build LLVM with LTO. May be specified as Thin or Full to use a particular kind of LTO")
31 string(TOUPPER "${LLVM_ENABLE_LTO}" uppercase_LLVM_ENABLE_LTO)
33 # Ninja Job Pool support
34 # The following only works with the Ninja generator in CMake >= 3.0.
35 set(LLVM_PARALLEL_COMPILE_JOBS "" CACHE STRING
36 "Define the maximum number of concurrent compilation jobs (Ninja only).")
37 if(LLVM_PARALLEL_COMPILE_JOBS)
38 if(NOT CMAKE_GENERATOR MATCHES "Ninja")
39 message(WARNING "Job pooling is only available with Ninja generators.")
41 set_property(GLOBAL APPEND PROPERTY JOB_POOLS compile_job_pool=${LLVM_PARALLEL_COMPILE_JOBS})
42 set(CMAKE_JOB_POOL_COMPILE compile_job_pool)
46 set(LLVM_PARALLEL_LINK_JOBS "" CACHE STRING
47 "Define the maximum number of concurrent link jobs (Ninja only).")
48 if(CMAKE_GENERATOR MATCHES "Ninja")
49 if(NOT LLVM_PARALLEL_LINK_JOBS AND uppercase_LLVM_ENABLE_LTO STREQUAL "THIN")
50 message(STATUS "ThinLTO provides its own parallel linking - limiting parallel link jobs to 2.")
51 set(LLVM_PARALLEL_LINK_JOBS "2")
53 if(LLVM_PARALLEL_LINK_JOBS)
54 set_property(GLOBAL APPEND PROPERTY JOB_POOLS link_job_pool=${LLVM_PARALLEL_LINK_JOBS})
55 set(CMAKE_JOB_POOL_LINK link_job_pool)
57 elseif(LLVM_PARALLEL_LINK_JOBS)
58 message(WARNING "Job pooling is only available with Ninja generators.")
61 if( LLVM_ENABLE_ASSERTIONS )
62 # MSVC doesn't like _DEBUG on release builds. See PR 4379.
64 add_definitions( -D_DEBUG )
66 # On non-Debug builds cmake automatically defines NDEBUG, so we
67 # explicitly undefine it:
68 if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
69 # NOTE: use `add_compile_options` rather than `add_definitions` since
70 # `add_definitions` does not support generator expressions.
71 add_compile_options($<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:-UNDEBUG>)
73 # Also remove /D NDEBUG to avoid MSVC warnings about conflicting defines.
74 foreach (flags_var_to_scrub
75 CMAKE_CXX_FLAGS_RELEASE
76 CMAKE_CXX_FLAGS_RELWITHDEBINFO
77 CMAKE_CXX_FLAGS_MINSIZEREL
79 CMAKE_C_FLAGS_RELWITHDEBINFO
80 CMAKE_C_FLAGS_MINSIZEREL)
81 string (REGEX REPLACE "(^| )[/-]D *NDEBUG($| )" " "
82 "${flags_var_to_scrub}" "${${flags_var_to_scrub}}")
88 if(LLVM_ENABLE_EXPENSIVE_CHECKS)
89 add_definitions(-DEXPENSIVE_CHECKS)
91 # In some libstdc++ versions, std::min_element is not constexpr when
92 # _GLIBCXX_DEBUG is enabled.
93 CHECK_CXX_SOURCE_COMPILES("
94 #define _GLIBCXX_DEBUG
96 int main(int argc, char** argv) {
97 static constexpr int data[] = {0, 1};
98 constexpr const int* min_elt = std::min_element(&data[0], &data[2]);
100 }" CXX_SUPPORTS_GLIBCXX_DEBUG)
101 if(CXX_SUPPORTS_GLIBCXX_DEBUG)
102 add_definitions(-D_GLIBCXX_DEBUG)
104 add_definitions(-D_GLIBCXX_ASSERTIONS)
108 if (LLVM_ENABLE_STRICT_FIXED_SIZE_VECTORS)
109 add_definitions(-DSTRICT_FIXED_SIZE_VECTORS)
112 string(TOUPPER "${LLVM_ABI_BREAKING_CHECKS}" uppercase_LLVM_ABI_BREAKING_CHECKS)
114 if( uppercase_LLVM_ABI_BREAKING_CHECKS STREQUAL "WITH_ASSERTS" )
115 if( LLVM_ENABLE_ASSERTIONS )
116 set( LLVM_ENABLE_ABI_BREAKING_CHECKS 1 )
118 elseif( uppercase_LLVM_ABI_BREAKING_CHECKS STREQUAL "FORCE_ON" )
119 set( LLVM_ENABLE_ABI_BREAKING_CHECKS 1 )
120 elseif( uppercase_LLVM_ABI_BREAKING_CHECKS STREQUAL "FORCE_OFF" )
121 # We don't need to do anything special to turn off ABI breaking checks.
122 elseif( NOT DEFINED LLVM_ABI_BREAKING_CHECKS )
123 # Treat LLVM_ABI_BREAKING_CHECKS like "FORCE_OFF" when it has not been
126 message(FATAL_ERROR "Unknown value for LLVM_ABI_BREAKING_CHECKS: \"${LLVM_ABI_BREAKING_CHECKS}\"!")
129 if( LLVM_REVERSE_ITERATION )
130 set( LLVM_ENABLE_REVERSE_ITERATION 1 )
134 set(LLVM_HAVE_LINK_VERSION_SCRIPT 0)
146 if(APPLE OR ${CMAKE_SYSTEM_NAME} MATCHES "AIX")
147 set(LLVM_HAVE_LINK_VERSION_SCRIPT 0)
149 set(LLVM_HAVE_LINK_VERSION_SCRIPT 1)
151 else(FUCHSIA OR UNIX)
152 MESSAGE(SEND_ERROR "Unable to determine platform")
153 endif(FUCHSIA OR UNIX)
156 if (CMAKE_SYSTEM_NAME MATCHES "OS390")
157 set(LLVM_HAVE_LINK_VERSION_SCRIPT 0)
160 set(EXEEXT ${CMAKE_EXECUTABLE_SUFFIX})
161 set(LTDL_SHLIB_EXT ${CMAKE_SHARED_LIBRARY_SUFFIX})
163 # We use *.dylib rather than *.so on darwin, but we stick with *.so on AIX.
164 if(${CMAKE_SYSTEM_NAME} MATCHES "AIX")
165 set(LLVM_PLUGIN_EXT ${CMAKE_SHARED_MODULE_SUFFIX})
167 set(LLVM_PLUGIN_EXT ${CMAKE_SHARED_LIBRARY_SUFFIX})
171 # Darwin-specific linker flags for loadable modules.
172 set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-flat_namespace -Wl,-undefined -Wl,suppress")
175 if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
176 # RHEL7 has ar and ranlib being non-deterministic by default. The D flag forces determinism,
177 # however only GNU version of ar and ranlib (2.27) have this option.
178 # RHEL DTS7 is also affected by this, which uses GNU binutils 2.28
179 execute_process(COMMAND ${CMAKE_AR} rD t.a
180 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
181 RESULT_VARIABLE AR_RESULT
185 if(${AR_RESULT} EQUAL 0)
186 execute_process(COMMAND ${CMAKE_RANLIB} -D t.a
187 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
188 RESULT_VARIABLE RANLIB_RESULT
192 if(${RANLIB_RESULT} EQUAL 0)
193 set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> Dqc <TARGET> <LINK_FLAGS> <OBJECTS>"
194 CACHE STRING "archive create command")
195 set(CMAKE_C_ARCHIVE_APPEND "<CMAKE_AR> Dq <TARGET> <LINK_FLAGS> <OBJECTS>")
196 set(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> -D <TARGET>" CACHE STRING "ranlib command")
198 set(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> Dqc <TARGET> <LINK_FLAGS> <OBJECTS>"
199 CACHE STRING "archive create command")
200 set(CMAKE_CXX_ARCHIVE_APPEND "<CMAKE_AR> Dq <TARGET> <LINK_FLAGS> <OBJECTS>")
201 set(CMAKE_CXX_ARCHIVE_FINISH "<CMAKE_RANLIB> -D <TARGET>" CACHE STRING "ranlib command")
203 file(REMOVE ${CMAKE_BINARY_DIR}/t.a)
207 if(${CMAKE_SYSTEM_NAME} MATCHES "AIX")
208 # -fPIC does not enable the large code model for GCC on AIX but does for XL.
209 if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
210 append("-mcmodel=large" CMAKE_CXX_FLAGS CMAKE_C_FLAGS)
211 elseif(CMAKE_CXX_COMPILER_ID MATCHES "XL")
212 # XL generates a small number of relocations not of the large model, -bbigtoc is needed.
213 append("-Wl,-bbigtoc"
214 CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
215 # The default behaviour on AIX processes dynamic initialization of non-local variables with
216 # static storage duration even for archive members that are otherwise unreferenced.
217 # Since `--whole-archive` is not used by the LLVM build to keep such initializations for Linux,
218 # we can limit the processing for archive members to only those that are otherwise referenced.
219 append("-bcdtors:mbr"
220 CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
222 if(BUILD_SHARED_LIBS)
223 # See rpath handling in AddLLVM.cmake
224 # FIXME: Remove this warning if this rpath is no longer hardcoded.
225 message(WARNING "Build and install environment path info may be exposed; binaries will also be unrelocatable.")
229 # Pass -Wl,-z,defs. This makes sure all symbols are defined. Otherwise a DSO
230 # build might work on ELF but fail on MachO/COFF.
231 if(NOT (CMAKE_SYSTEM_NAME MATCHES "Darwin|FreeBSD|OpenBSD|DragonFly|AIX|OS390" OR
233 NOT LLVM_USE_SANITIZER)
234 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,defs")
237 # Pass -Wl,-z,nodelete. This makes sure our shared libraries are not unloaded
238 # by dlclose(). We need that since the CLI API relies on cross-references
239 # between global objects which became horribly broken when one of the libraries
241 if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
242 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,nodelete")
243 set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-z,nodelete")
247 function(append value)
248 foreach(variable ${ARGN})
249 set(${variable} "${${variable}} ${value}" PARENT_SCOPE)
253 function(append_if condition value)
255 foreach(variable ${ARGN})
256 set(${variable} "${${variable}} ${value}" PARENT_SCOPE)
261 macro(add_flag_if_supported flag name)
262 check_c_compiler_flag("-Werror ${flag}" "C_SUPPORTS_${name}")
263 append_if("C_SUPPORTS_${name}" "${flag}" CMAKE_C_FLAGS)
264 check_cxx_compiler_flag("-Werror ${flag}" "CXX_SUPPORTS_${name}")
265 append_if("CXX_SUPPORTS_${name}" "${flag}" CMAKE_CXX_FLAGS)
268 function(add_flag_or_print_warning flag name)
269 check_c_compiler_flag("-Werror ${flag}" "C_SUPPORTS_${name}")
270 check_cxx_compiler_flag("-Werror ${flag}" "CXX_SUPPORTS_${name}")
271 if (C_SUPPORTS_${name} AND CXX_SUPPORTS_${name})
272 message(STATUS "Building with ${flag}")
273 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}" PARENT_SCOPE)
274 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}" PARENT_SCOPE)
275 set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} ${flag}" PARENT_SCOPE)
277 message(WARNING "${flag} is not supported.")
281 function(has_msvc_incremental_no_flag flags incr_no_flag_on)
282 set(${incr_no_flag_on} OFF PARENT_SCOPE)
283 string(FIND "${flags}" "/INCREMENTAL" idx REVERSE)
284 if (${idx} GREATER -1)
285 string(SUBSTRING "${flags}" ${idx} 15 no_flag)
286 if (${no_flag} MATCHES "/INCREMENTAL:NO")
287 set(${incr_no_flag_on} ON PARENT_SCOPE)
292 if( LLVM_ENABLE_LLD )
293 if ( LLVM_USE_LINKER )
294 message(FATAL_ERROR "LLVM_ENABLE_LLD and LLVM_USE_LINKER can't be set at the same time")
296 # In case of MSVC cmake always invokes the linker directly, so the linker
297 # should be specified by CMAKE_LINKER cmake variable instead of by -fuse-ld
300 set(LLVM_USE_LINKER "lld")
304 if( LLVM_USE_LINKER )
305 set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
306 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fuse-ld=${LLVM_USE_LINKER}")
307 check_cxx_source_compiles("int main() { return 0; }" CXX_SUPPORTS_CUSTOM_LINKER)
308 if ( NOT CXX_SUPPORTS_CUSTOM_LINKER )
309 message(FATAL_ERROR "Host compiler does not support '-fuse-ld=${LLVM_USE_LINKER}'")
311 set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
312 append("-fuse-ld=${LLVM_USE_LINKER}"
313 CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
316 if( LLVM_ENABLE_PIC )
318 # Xcode has -mdynamic-no-pic on by default, which overrides -fPIC. I don't
319 # know how to disable this, so just force ENABLE_PIC off for now.
320 message(WARNING "-fPIC not supported with Xcode.")
321 elseif( WIN32 OR CYGWIN)
322 # On Windows all code is PIC. MinGW warns if -fPIC is used.
324 add_flag_or_print_warning("-fPIC" FPIC)
325 # Enable interprocedural optimizations for non-inline functions which would
326 # otherwise be disabled due to GCC -fPIC's default.
327 # Note: GCC<10.3 has a bug on SystemZ.
329 # Note: Clang allows IPO for -fPIC so this optimization is less effective.
330 # Clang 13 has a bug related to -fsanitize-coverage
331 # -fno-semantic-interposition (https://reviews.llvm.org/D117183).
332 if ((CMAKE_COMPILER_IS_GNUCXX AND
333 NOT (LLVM_NATIVE_ARCH STREQUAL "SystemZ" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 10.3))
334 OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_CXX_COMPILER_VERSION GREATER_EQUAL 14))
335 add_flag_if_supported("-fno-semantic-interposition" FNO_SEMANTIC_INTERPOSITION)
338 # GCC for MIPS can miscompile LLVM due to PR37701.
339 if(CMAKE_COMPILER_IS_GNUCXX AND LLVM_NATIVE_ARCH STREQUAL "Mips" AND
340 NOT Uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG")
341 add_flag_or_print_warning("-fno-shrink-wrap" FNO_SHRINK_WRAP)
343 # gcc with -O3 -fPIC generates TLS sequences that violate the spec on
344 # Solaris/sparcv9, causing executables created with the system linker
345 # to SEGV (GCC PR target/96607).
346 # clang with -O3 -fPIC generates code that SEGVs.
347 # Both can be worked around by compiling with -O instead.
348 if(${CMAKE_SYSTEM_NAME} STREQUAL "SunOS" AND LLVM_NATIVE_ARCH STREQUAL "Sparc")
349 llvm_replace_compiler_option(CMAKE_CXX_FLAGS_RELEASE "-O[23]" "-O")
350 llvm_replace_compiler_option(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O[23]" "-O")
354 if((NOT (${CMAKE_SYSTEM_NAME} MATCHES "AIX")) AND
355 (NOT (WIN32 OR CYGWIN) OR (MINGW AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")))
356 # GCC for MinGW does nothing about -fvisibility-inlines-hidden, but warns
357 # about use of the attributes. As long as we don't use the attributes (to
358 # override the default) we shouldn't set the command line options either.
359 # GCC on AIX warns if -fvisibility-inlines-hidden is used and Clang on AIX doesn't currently support visibility.
360 check_cxx_compiler_flag("-fvisibility-inlines-hidden" SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG)
361 append_if(SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG "-fvisibility-inlines-hidden" CMAKE_CXX_FLAGS)
364 if(CMAKE_SIZEOF_VOID_P EQUAL 8 AND MINGW)
365 add_definitions( -D_FILE_OFFSET_BITS=64 )
368 if( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 )
369 # TODO: support other platforms and toolchains.
370 if( LLVM_BUILD_32_BITS )
371 message(STATUS "Building 32 bits executables and libraries.")
372 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
373 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32")
374 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32")
375 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32")
376 set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -m32")
378 # FIXME: CMAKE_SIZEOF_VOID_P is still 8
379 add_definitions(-D_LARGEFILE_SOURCE)
380 add_definitions(-D_FILE_OFFSET_BITS=64)
381 endif( LLVM_BUILD_32_BITS )
382 endif( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 )
384 # If building on a GNU specific 32-bit system, make sure off_t is 64 bits
385 # so that off_t can stored offset > 2GB.
386 # Android until version N (API 24) doesn't support it.
387 if (ANDROID AND (ANDROID_NATIVE_API_LEVEL LESS 24))
388 set(LLVM_FORCE_SMALLFILE_FOR_ANDROID TRUE)
390 if( CMAKE_SIZEOF_VOID_P EQUAL 4 AND NOT LLVM_FORCE_SMALLFILE_FOR_ANDROID)
391 # FIXME: It isn't handled in LLVM_BUILD_32_BITS.
392 add_definitions( -D_LARGEFILE_SOURCE )
393 add_definitions( -D_FILE_OFFSET_BITS=64 )
397 # For Xcode enable several build settings that correspond to
398 # many warnings that are on by default in Clang but are
399 # not enabled for historical reasons. For versions of Xcode
400 # that do not support these options they will simply
402 set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_ABOUT_RETURN_TYPE "YES")
403 set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_ABOUT_MISSING_NEWLINE "YES")
404 set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_UNUSED_VALUE "YES")
405 set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_UNUSED_VARIABLE "YES")
406 set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_SIGN_COMPARE "YES")
407 set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_UNUSED_FUNCTION "YES")
408 set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED "YES")
409 set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS "YES")
410 set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_UNINITIALIZED_AUTOS "YES")
411 set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_BOOL_CONVERSION "YES")
412 set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_EMPTY_BODY "YES")
413 set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_ENUM_CONVERSION "YES")
414 set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_INT_CONVERSION "YES")
415 set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_CONSTANT_CONVERSION "YES")
416 set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_NON_VIRTUAL_DESTRUCTOR "YES")
419 # On Win32 using MS tools, provide an option to set the number of parallel jobs
422 set(LLVM_COMPILER_JOBS "0" CACHE STRING
423 "Number of parallel compiler jobs. 0 means use all processors. Default is 0.")
424 if( NOT LLVM_COMPILER_JOBS STREQUAL "1" )
425 if( LLVM_COMPILER_JOBS STREQUAL "0" )
426 add_definitions( /MP )
428 message(STATUS "Number of parallel compiler jobs set to " ${LLVM_COMPILER_JOBS})
429 add_definitions( /MP${LLVM_COMPILER_JOBS} )
432 message(STATUS "Parallel compilation disabled")
436 # set stack reserved size to ~10MB
438 # CMake previously automatically set this value for MSVC builds, but the
439 # behavior was changed in CMake 2.8.11 (Issue 12437) to use the MSVC default
440 # value (1 MB) which is not enough for us in tasks such as parsing recursive
441 # C++ templates in Clang.
442 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:10000000")
443 elseif(MINGW) # FIXME: Also cygwin?
444 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--stack,16777216")
446 # Pass -mbig-obj to mingw gas to avoid COFF 2**16 section limit.
447 if (NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
448 append("-Wa,-mbig-obj" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
452 option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." ON)
455 include(ChooseMSVCCRT)
457 # Add definitions that make MSVC much less annoying.
459 # For some reason MS wants to deprecate a bunch of standard functions...
460 -D_CRT_SECURE_NO_DEPRECATE
461 -D_CRT_SECURE_NO_WARNINGS
462 -D_CRT_NONSTDC_NO_DEPRECATE
463 -D_CRT_NONSTDC_NO_WARNINGS
464 -D_SCL_SECURE_NO_DEPRECATE
465 -D_SCL_SECURE_NO_WARNINGS
468 # Tell MSVC to use the Unicode version of the Win32 APIs instead of ANSI.
476 message(ERROR "LLVM_WINSYSROOT requires clang-cl")
478 append("/winsysroot${LLVM_WINSYSROOT}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
481 if (LLVM_ENABLE_WERROR)
482 append("/WX" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
483 endif (LLVM_ENABLE_WERROR)
485 append("/Zc:inline" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
487 # Some projects use the __cplusplus preprocessor macro to check support for
488 # a particular version of the C++ standard. When this option is not specified
489 # explicitly, macro's value is "199711L" that implies C++98 Standard.
490 # https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/
491 append("/Zc:__cplusplus" CMAKE_CXX_FLAGS)
493 # Allow users to request PDBs in release mode. CMake offeres the
494 # RelWithDebInfo configuration, but it uses different optimization settings
495 # (/Ob1 vs /Ob2 or -O2 vs -O3). LLVM provides this flag so that users can get
496 # PDBs without changing codegen.
497 option(LLVM_ENABLE_PDB OFF)
498 if (LLVM_ENABLE_PDB AND uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE")
499 append("/Zi" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
500 # /DEBUG disables linker GC and ICF, but we want those in Release mode.
501 append("/DEBUG /OPT:REF /OPT:ICF"
502 CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS
503 CMAKE_SHARED_LINKER_FLAGS)
506 # Get all linker flags in upper case form so we can search them.
507 string(CONCAT all_linker_flags_uppercase
508 ${CMAKE_EXE_LINKER_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} " "
509 ${CMAKE_EXE_LINKER_FLAGS} " "
510 ${CMAKE_MODULE_LINKER_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} " "
511 ${CMAKE_MODULE_LINKER_FLAGS} " "
512 ${CMAKE_SHARED_LINKER_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} " "
513 ${CMAKE_SHARED_LINKER_FLAGS})
514 string(TOUPPER "${all_linker_flags_uppercase}" all_linker_flags_uppercase)
516 if (CLANG_CL AND LINKER_IS_LLD)
517 # If we are using clang-cl with lld-link and /debug is present in any of the
518 # linker flag variables, pass -gcodeview-ghash to the compiler to speed up
519 # linking. This flag is orthogonal from /Zi, /Z7, and other flags that
520 # enable debug info emission, and only has an effect if those are also in
522 string(FIND "${all_linker_flags_uppercase}" "/DEBUG" linker_flag_idx)
523 if (${linker_flag_idx} GREATER -1)
524 add_flag_if_supported("-gcodeview-ghash" GCODEVIEW_GHASH)
528 # "Generate Intrinsic Functions".
529 append("/Oi" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
531 if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT LLVM_ENABLE_LTO)
532 # clang-cl and cl by default produce non-deterministic binaries because
533 # link.exe /incremental requires a timestamp in the .obj file. clang-cl
534 # has the flag /Brepro to force deterministic binaries. We want to pass that
535 # whenever you're building with clang unless you're passing /incremental
536 # or using LTO (/Brepro with LTO would result in a warning about the flag
537 # being unused, because we're not generating object files).
538 # This checks CMAKE_CXX_COMPILER_ID in addition to check_cxx_compiler_flag()
539 # because cl.exe does not emit an error on flags it doesn't understand,
540 # letting check_cxx_compiler_flag() claim it understands all flags.
541 check_cxx_compiler_flag("/Brepro" SUPPORTS_BREPRO)
543 # Check if /INCREMENTAL is passed to the linker and complain that it
544 # won't work with /Brepro.
545 has_msvc_incremental_no_flag("${CMAKE_EXE_LINKER_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${CMAKE_EXE_LINKER_FLAGS}" NO_INCR_EXE)
546 has_msvc_incremental_no_flag("${CMAKE_MODULE_LINKER_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${CMAKE_MODULE_LINKER_FLAGS}" NO_INCR_MODULE)
547 has_msvc_incremental_no_flag("${CMAKE_SHARED_LINKER_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${CMAKE_SHARED_LINKER_FLAGS}" NO_INCR_SHARED)
548 if (NO_INCR_EXE AND NO_INCR_MODULE AND NO_INCR_SHARED)
549 append("/Brepro" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
551 message(WARNING "/Brepro not compatible with /INCREMENTAL linking - builds will be non-deterministic")
555 # By default MSVC has a 2^16 limit on the number of sections in an object file,
556 # but in many objects files need more than that. This flag is to increase the
557 # number of sections.
558 append("/bigobj" CMAKE_CXX_FLAGS)
560 # Enable standards conformance mode.
561 # This ensures handling of various C/C++ constructs is more similar to other compilers.
562 append("/permissive-" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
565 # Warnings-as-errors handling for GCC-compatible compilers:
566 if ( LLVM_COMPILER_IS_GCC_COMPATIBLE )
567 append_if(LLVM_ENABLE_WERROR "-Werror" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
568 append_if(LLVM_ENABLE_WERROR "-Wno-error" CMAKE_REQUIRED_FLAGS)
569 endif( LLVM_COMPILER_IS_GCC_COMPATIBLE )
571 # Specific default warnings-as-errors for compilers accepting GCC-compatible warning flags:
572 if ( LLVM_COMPILER_IS_GCC_COMPATIBLE OR CMAKE_CXX_COMPILER_ID MATCHES "XL" )
573 add_flag_if_supported("-Werror=date-time" WERROR_DATE_TIME)
574 add_flag_if_supported("-Werror=unguarded-availability-new" WERROR_UNGUARDED_AVAILABILITY_NEW)
575 endif( LLVM_COMPILER_IS_GCC_COMPATIBLE OR CMAKE_CXX_COMPILER_ID MATCHES "XL" )
577 # Modules enablement for GCC-compatible compilers:
578 if ( LLVM_COMPILER_IS_GCC_COMPATIBLE AND LLVM_ENABLE_MODULES )
579 set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
580 set(module_flags "-fmodules -fmodules-cache-path=${PROJECT_BINARY_DIR}/module.cache")
581 if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
582 # On Darwin -fmodules does not imply -fcxx-modules.
583 set(module_flags "${module_flags} -fcxx-modules")
585 if (LLVM_ENABLE_LOCAL_SUBMODULE_VISIBILITY)
586 set(module_flags "${module_flags} -Xclang -fmodules-local-submodule-visibility")
588 if (LLVM_ENABLE_MODULE_DEBUGGING AND
589 ((uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG") OR
590 (uppercase_CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO")))
591 set(module_flags "${module_flags} -gmodules")
593 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${module_flags}")
595 # Check that we can build code with modules enabled, and that repeatedly
596 # including <cassert> still manages to respect NDEBUG properly.
597 CHECK_CXX_SOURCE_COMPILES("#undef NDEBUG
601 int main() { assert(this code is not compiled); }"
602 CXX_SUPPORTS_MODULES)
603 set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
604 if (CXX_SUPPORTS_MODULES)
605 append("${module_flags}" CMAKE_CXX_FLAGS)
607 message(FATAL_ERROR "LLVM_ENABLE_MODULES is not supported by this compiler")
609 endif( LLVM_COMPILER_IS_GCC_COMPATIBLE AND LLVM_ENABLE_MODULES )
613 set(msvc_warning_flags
615 -wd4141 # Suppress ''modifier' : used more than once' (because of __forceinline combined with inline)
616 -wd4146 # Suppress 'unary minus operator applied to unsigned type, result still unsigned'
617 -wd4244 # Suppress ''argument' : conversion from 'type1' to 'type2', possible loss of data'
618 -wd4267 # Suppress ''var' : conversion from 'size_t' to 'type', possible loss of data'
619 -wd4291 # Suppress ''declaration' : no matching operator delete found; memory will not be freed if initialization throws an exception'
620 -wd4351 # Suppress 'new behavior: elements of array 'array' will be default initialized'
621 -wd4456 # Suppress 'declaration of 'var' hides local variable'
622 -wd4457 # Suppress 'declaration of 'var' hides function parameter'
623 -wd4458 # Suppress 'declaration of 'var' hides class member'
624 -wd4459 # Suppress 'declaration of 'var' hides global declaration'
625 -wd4503 # Suppress ''identifier' : decorated name length exceeded, name was truncated'
626 -wd4624 # Suppress ''derived class' : destructor could not be generated because a base class destructor is inaccessible'
627 -wd4722 # Suppress 'function' : destructor never returns, potential memory leak
628 -wd4100 # Suppress 'unreferenced formal parameter'
629 -wd4127 # Suppress 'conditional expression is constant'
630 -wd4512 # Suppress 'assignment operator could not be generated'
631 -wd4505 # Suppress 'unreferenced local function has been removed'
632 -wd4610 # Suppress '<class> can never be instantiated'
633 -wd4510 # Suppress 'default constructor could not be generated'
634 -wd4702 # Suppress 'unreachable code'
635 -wd4245 # Suppress ''conversion' : conversion from 'type1' to 'type2', signed/unsigned mismatch'
636 -wd4706 # Suppress 'assignment within conditional expression'
637 -wd4310 # Suppress 'cast truncates constant value'
638 -wd4701 # Suppress 'potentially uninitialized local variable'
639 -wd4703 # Suppress 'potentially uninitialized local pointer variable'
640 -wd4389 # Suppress 'signed/unsigned mismatch'
641 -wd4611 # Suppress 'interaction between '_setjmp' and C++ object destruction is non-portable'
642 -wd4805 # Suppress 'unsafe mix of type <type> and type <type> in operation'
643 -wd4204 # Suppress 'nonstandard extension used : non-constant aggregate initializer'
644 -wd4577 # Suppress 'noexcept used with no exception handling mode specified; termination on exception is not guaranteed'
645 -wd4091 # Suppress 'typedef: ignored on left of '' when no variable is declared'
646 # C4592 is disabled because of false positives in Visual Studio 2015
647 # Update 1. Re-evaluate the usefulness of this diagnostic with Update 2.
648 -wd4592 # Suppress ''var': symbol will be dynamically initialized (implementation limitation)
649 -wd4319 # Suppress ''operator' : zero extending 'type' to 'type' of greater size'
650 # C4709 is disabled because of a bug with Visual Studio 2017 as of
651 # v15.8.8. Re-evaluate the usefulness of this diagnostic when the bug
653 -wd4709 # Suppress comma operator within array index expression
655 # Ideally, we'd like this warning to be enabled, but even MSVC 2019 doesn't
656 # support the 'aligned' attribute in the way that clang sources requires (for
657 # any code that uses the LLVM_ALIGNAS macro), so this is must be disabled to
658 # avoid unwanted alignment warnings.
659 -wd4324 # Suppress 'structure was padded due to __declspec(align())'
662 -w14062 # Promote 'enumerator in switch of enum is not handled' to level 1 warning.
664 # Promoted warnings to errors.
665 -we4238 # Promote 'nonstandard extension used : class rvalue used as lvalue' to error.
670 if (LLVM_ENABLE_WARNINGS)
671 # Put /W4 in front of all the -we flags. cl.exe doesn't care, but for
672 # clang-cl having /W4 after the -we flags will re-enable the warnings
674 set(msvc_warning_flags "/W4 ${msvc_warning_flags}")
675 # CMake appends /W3 by default, and having /W3 followed by /W4 will result in
676 # cl : Command line warning D9025 : overriding '/W3' with '/W4'. Since this is
677 # a command line warning and not a compiler warning, it cannot be suppressed except
678 # by fixing the command line.
679 string(REGEX REPLACE " /W[0-4]" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
680 string(REGEX REPLACE " /W[0-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
682 if (LLVM_ENABLE_PEDANTIC)
683 # No MSVC equivalent available
684 endif (LLVM_ENABLE_PEDANTIC)
685 endif (LLVM_ENABLE_WARNINGS)
687 foreach(flag ${msvc_warning_flags})
688 append("${flag}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
692 if (LLVM_ENABLE_WARNINGS AND (LLVM_COMPILER_IS_GCC_COMPATIBLE OR CLANG_CL))
694 # Don't add -Wall for clang-cl, because it maps -Wall to -Weverything for
695 # MSVC compatibility. /W4 is added above instead.
697 append("-Wall" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
700 append("-Wextra -Wno-unused-parameter -Wwrite-strings" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
701 append("-Wcast-qual" CMAKE_CXX_FLAGS)
703 # Turn off missing field initializer warnings for gcc to avoid noise from
704 # false positives with empty {}. Turn them on otherwise (they're off by
705 # default for clang).
706 check_cxx_compiler_flag("-Wmissing-field-initializers" CXX_SUPPORTS_MISSING_FIELD_INITIALIZERS_FLAG)
707 if (CXX_SUPPORTS_MISSING_FIELD_INITIALIZERS_FLAG)
708 if (CMAKE_COMPILER_IS_GNUCXX)
709 append("-Wno-missing-field-initializers" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
711 append("-Wmissing-field-initializers" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
715 if (LLVM_ENABLE_PEDANTIC AND LLVM_COMPILER_IS_GCC_COMPATIBLE)
716 append("-pedantic" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
717 append("-Wno-long-long" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
719 # GCC warns about redundant toplevel semicolons (enabled by -pedantic
720 # above), while Clang doesn't. Enable the corresponding Clang option to
721 # pick up on these even in builds with Clang.
722 add_flag_if_supported("-Wc++98-compat-extra-semi" CXX98_COMPAT_EXTRA_SEMI_FLAG)
725 add_flag_if_supported("-Wimplicit-fallthrough" IMPLICIT_FALLTHROUGH_FLAG)
726 add_flag_if_supported("-Wcovered-switch-default" COVERED_SWITCH_DEFAULT_FLAG)
727 append_if(USE_NO_UNINITIALIZED "-Wno-uninitialized" CMAKE_CXX_FLAGS)
728 append_if(USE_NO_MAYBE_UNINITIALIZED "-Wno-maybe-uninitialized" CMAKE_CXX_FLAGS)
730 # Disable -Wclass-memaccess, a C++-only warning from GCC 8 that fires on
731 # LLVM's ADT classes.
732 check_cxx_compiler_flag("-Wclass-memaccess" CXX_SUPPORTS_CLASS_MEMACCESS_FLAG)
733 append_if(CXX_SUPPORTS_CLASS_MEMACCESS_FLAG "-Wno-class-memaccess" CMAKE_CXX_FLAGS)
735 # Disable -Wredundant-move and -Wpessimizing-move on GCC>=9. GCC wants to
736 # remove std::move in code like "A foo(ConvertibleToA a) {
737 # return std::move(a); }", but this code does not compile (or uses the copy
738 # constructor instead) on clang<=3.8. Clang also has a -Wredundant-move and
739 # -Wpessimizing-move, but they only fire when the types match exactly, so we
740 # can keep them here.
741 if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
742 check_cxx_compiler_flag("-Wredundant-move" CXX_SUPPORTS_REDUNDANT_MOVE_FLAG)
743 append_if(CXX_SUPPORTS_REDUNDANT_MOVE_FLAG "-Wno-redundant-move" CMAKE_CXX_FLAGS)
744 check_cxx_compiler_flag("-Wpessimizing-move" CXX_SUPPORTS_PESSIMIZING_MOVE_FLAG)
745 append_if(CXX_SUPPORTS_PESSIMIZING_MOVE_FLAG "-Wno-pessimizing-move" CMAKE_CXX_FLAGS)
748 # The LLVM libraries have no stable C++ API, so -Wnoexcept-type is not useful.
749 check_cxx_compiler_flag("-Wnoexcept-type" CXX_SUPPORTS_NOEXCEPT_TYPE_FLAG)
750 append_if(CXX_SUPPORTS_NOEXCEPT_TYPE_FLAG "-Wno-noexcept-type" CMAKE_CXX_FLAGS)
752 # Check if -Wnon-virtual-dtor warns for a class marked final, when it has a
753 # friend declaration. If it does, don't add -Wnon-virtual-dtor. The case is
754 # considered unhelpful (https://gcc.gnu.org/PR102168).
755 set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
756 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Werror=non-virtual-dtor")
757 CHECK_CXX_SOURCE_COMPILES("class f {};
758 class base {friend f; public: virtual void anchor();protected: ~base();};
759 int main() { return 0; }"
760 CXX_WONT_WARN_ON_FINAL_NONVIRTUALDTOR)
761 set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
762 append_if(CXX_WONT_WARN_ON_FINAL_NONVIRTUALDTOR "-Wnon-virtual-dtor" CMAKE_CXX_FLAGS)
764 append("-Wdelete-non-virtual-dtor" CMAKE_CXX_FLAGS)
766 # Enable -Wsuggest-override if it's available, and only if it doesn't
767 # suggest adding 'override' to functions that are already marked 'final'
768 # (which means it is disabled for GCC < 9.2).
769 check_cxx_compiler_flag("-Wsuggest-override" CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG)
770 if (CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG)
771 set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
772 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Werror=suggest-override")
773 CHECK_CXX_SOURCE_COMPILES("class base {public: virtual void anchor();};
774 class derived : base {public: void anchor() final;};
775 int main() { return 0; }"
776 CXX_WSUGGEST_OVERRIDE_ALLOWS_ONLY_FINAL)
777 set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
778 append_if(CXX_WSUGGEST_OVERRIDE_ALLOWS_ONLY_FINAL "-Wsuggest-override" CMAKE_CXX_FLAGS)
781 # Check if -Wcomment is OK with an // comment ending with '\' if the next
782 # line is also a // comment.
783 set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
784 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Werror -Wcomment")
785 CHECK_C_SOURCE_COMPILES("// \\\\\\n//\\nint main() {return 0;}"
786 C_WCOMMENT_ALLOWS_LINE_WRAP)
787 set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
788 if (NOT C_WCOMMENT_ALLOWS_LINE_WRAP)
789 append("-Wno-comment" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
792 # Enable -Wstring-conversion to catch misuse of string literals.
793 add_flag_if_supported("-Wstring-conversion" STRING_CONVERSION_FLAG)
795 if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
796 # Disable the misleading indentation warning with GCC; GCC can
797 # produce noisy notes about this getting disabled in large files.
798 # See e.g. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89549
799 check_cxx_compiler_flag("-Wmisleading-indentation" CXX_SUPPORTS_MISLEADING_INDENTATION_FLAG)
800 append_if(CXX_SUPPORTS_MISLEADING_INDENTATION_FLAG "-Wno-misleading-indentation" CMAKE_CXX_FLAGS)
802 # Prevent bugs that can happen with llvm's brace style.
803 add_flag_if_supported("-Wmisleading-indentation" MISLEADING_INDENTATION_FLAG)
806 # Enable -Wctad-maybe-unsupported to catch unintended use of CTAD.
807 add_flag_if_supported("-Wctad-maybe-unsupported" CTAD_MAYBE_UNSPPORTED_FLAG)
808 endif (LLVM_ENABLE_WARNINGS AND (LLVM_COMPILER_IS_GCC_COMPATIBLE OR CLANG_CL))
810 if (LLVM_COMPILER_IS_GCC_COMPATIBLE AND NOT LLVM_ENABLE_WARNINGS)
811 append("-w" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
814 macro(append_common_sanitizer_flags)
816 # Append -fno-omit-frame-pointer and turn on debug info to get better
818 add_flag_if_supported("-fno-omit-frame-pointer" FNO_OMIT_FRAME_POINTER)
819 if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" AND
820 NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO")
821 add_flag_if_supported("-gline-tables-only" GLINE_TABLES_ONLY)
823 # Use -O1 even in debug mode, otherwise sanitizers slowdown is too large.
824 if (uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" AND LLVM_OPTIMIZE_SANITIZED_BUILDS)
825 add_flag_if_supported("-O1" O1)
828 # Always ask the linker to produce symbols with asan.
829 append("/Z7" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
830 append("/debug" CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
831 # Not compatible with /INCREMENTAL link.
832 foreach (flags_opt_to_scrub
833 CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
834 string (REGEX REPLACE "(^| )/INCREMENTAL($| )" " /INCREMENTAL:NO "
835 "${flags_opt_to_scrub}" "${${flags_opt_to_scrub}}")
837 if (LLVM_HOST_TRIPLE MATCHES "i[2-6]86-.*")
838 # Keep frame pointers around.
839 append("/Oy-" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
844 # Turn on sanitizers if necessary.
845 if(LLVM_USE_SANITIZER)
847 if (LLVM_USE_SANITIZER STREQUAL "Address")
848 append_common_sanitizer_flags()
849 append("-fsanitize=address" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
850 elseif (LLVM_USE_SANITIZER STREQUAL "HWAddress")
851 append_common_sanitizer_flags()
852 append("-fsanitize=hwaddress" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
853 elseif (LLVM_USE_SANITIZER MATCHES "Memory(WithOrigins)?")
854 append_common_sanitizer_flags()
855 append("-fsanitize=memory" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
856 if(LLVM_USE_SANITIZER STREQUAL "MemoryWithOrigins")
857 append("-fsanitize-memory-track-origins" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
859 elseif (LLVM_USE_SANITIZER STREQUAL "Undefined")
860 append_common_sanitizer_flags()
861 append("${LLVM_UBSAN_FLAGS}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
862 elseif (LLVM_USE_SANITIZER STREQUAL "Thread")
863 append_common_sanitizer_flags()
864 append("-fsanitize=thread" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
865 elseif (LLVM_USE_SANITIZER STREQUAL "DataFlow")
866 append("-fsanitize=dataflow" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
867 elseif (LLVM_USE_SANITIZER STREQUAL "Address;Undefined" OR
868 LLVM_USE_SANITIZER STREQUAL "Undefined;Address")
869 append_common_sanitizer_flags()
870 append("-fsanitize=address" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
871 append("${LLVM_UBSAN_FLAGS}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
872 elseif (LLVM_USE_SANITIZER STREQUAL "Leaks")
873 append_common_sanitizer_flags()
874 append("-fsanitize=leak" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
876 message(FATAL_ERROR "Unsupported value of LLVM_USE_SANITIZER: ${LLVM_USE_SANITIZER}")
879 if (LLVM_USE_SANITIZER STREQUAL "Address")
880 append_common_sanitizer_flags()
881 append("-fsanitize=address" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
882 elseif (LLVM_USE_SANITIZER STREQUAL "Undefined")
883 append_common_sanitizer_flags()
884 append("${LLVM_UBSAN_FLAGS}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
885 elseif (LLVM_USE_SANITIZER STREQUAL "Address;Undefined" OR
886 LLVM_USE_SANITIZER STREQUAL "Undefined;Address")
887 append_common_sanitizer_flags()
888 append("-fsanitize=address" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
889 append("${LLVM_UBSAN_FLAGS}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
891 message(FATAL_ERROR "This sanitizer not yet supported in a MinGW environment: ${LLVM_USE_SANITIZER}")
894 if (LLVM_USE_SANITIZER STREQUAL "Address")
895 append_common_sanitizer_flags()
896 append("/fsanitize=address" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
898 # Not compatible with /RTC flags.
899 foreach (flags_opt_to_scrub
900 CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE} CMAKE_C_FLAGS_${uppercase_CMAKE_BUILD_TYPE})
901 string (REGEX REPLACE "(^| )/RTC[1csu]*($| )" " "
902 "${flags_opt_to_scrub}" "${${flags_opt_to_scrub}}")
905 if (LINKER_IS_LLD_LINK)
906 if (LLVM_HOST_TRIPLE MATCHES "i[2-6]86-.*")
911 if (${LLVM_USE_CRT_${uppercase_CMAKE_BUILD_TYPE}} MATCHES "^(MT|MTd)$")
912 append("/wholearchive:clang_rt.asan-${arch}.lib /wholearchive:clang_rt.asan_cxx-${arch}.lib"
913 CMAKE_EXE_LINKER_FLAGS)
914 append("/wholearchive:clang_rt.asan_dll_thunk-${arch}.lib"
915 CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
917 append("clang_rt.asan_dynamic-${arch}.lib /wholearchive:clang_rt.asan_dynamic_runtime_thunk-${arch}.lib"
918 CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
922 message(FATAL_ERROR "This sanitizer not yet supported in the MSVC environment: ${LLVM_USE_SANITIZER}")
925 message(FATAL_ERROR "LLVM_USE_SANITIZER is not supported on this platform.")
927 if (LLVM_USE_SANITIZE_COVERAGE)
928 append("-fsanitize=fuzzer-no-link" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
930 if (LLVM_USE_SANITIZER MATCHES ".*Undefined.*")
931 set(IGNORELIST_FILE "${CMAKE_SOURCE_DIR}/utils/sanitizers/ubsan_ignorelist.txt")
932 if (EXISTS "${IGNORELIST_FILE}")
933 # Use this option name version since -fsanitize-ignorelist is only
934 # accepted with clang 13.0 or newer.
935 append("-fsanitize-blacklist=${IGNORELIST_FILE}"
936 CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
941 # Turn on -gsplit-dwarf if requested in debug builds.
942 if (LLVM_USE_SPLIT_DWARF AND
943 ((uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG") OR
944 (uppercase_CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO")))
945 # Limit to clang and gcc so far. Add compilers supporting this option.
946 if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR
947 CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
948 add_compile_options(-gsplit-dwarf)
949 include(LLVMCheckLinkerFlag)
950 llvm_check_linker_flag(CXX "-Wl,--gdb-index" LINKER_SUPPORTS_GDB_INDEX)
951 append_if(LINKER_SUPPORTS_GDB_INDEX "-Wl,--gdb-index"
952 CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
956 add_definitions( -D__STDC_CONSTANT_MACROS )
957 add_definitions( -D__STDC_FORMAT_MACROS )
958 add_definitions( -D__STDC_LIMIT_MACROS )
960 # clang and gcc don't default-print colored diagnostics when invoked from Ninja.
962 CMAKE_GENERATOR MATCHES "Ninja" AND
963 (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR
964 (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND
965 NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9))))
966 append("-fdiagnostics-color" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
969 # lld doesn't print colored diagnostics when invoked from Ninja
970 if (UNIX AND CMAKE_GENERATOR MATCHES "Ninja")
971 include(LLVMCheckLinkerFlag)
972 llvm_check_linker_flag(CXX "-Wl,--color-diagnostics" LINKER_SUPPORTS_COLOR_DIAGNOSTICS)
973 append_if(LINKER_SUPPORTS_COLOR_DIAGNOSTICS "-Wl,--color-diagnostics"
974 CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
977 # Add flags for add_dead_strip().
978 # FIXME: With MSVS, consider compiling with /Gy and linking with /OPT:REF?
979 # But MinSizeRel seems to add that automatically, so maybe disable these
980 # flags instead if LLVM_NO_DEAD_STRIP is set.
981 if(NOT CYGWIN AND NOT MSVC)
982 if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND
983 NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG")
984 check_c_compiler_flag("-Werror -fno-function-sections" C_SUPPORTS_FNO_FUNCTION_SECTIONS)
985 if (C_SUPPORTS_FNO_FUNCTION_SECTIONS)
986 # Don't add -ffunction-sections if it can't be disabled with -fno-function-sections.
987 # Doing so will break sanitizers.
988 add_flag_if_supported("-ffunction-sections" FFUNCTION_SECTIONS)
989 elseif (CMAKE_CXX_COMPILER_ID MATCHES "XL")
990 append("-qfuncsect" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
992 add_flag_if_supported("-fdata-sections" FDATA_SECTIONS)
995 if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
996 append("/Gw" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
1001 # Remove flags here, for exceptions and RTTI.
1002 # Each target property or source property should be responsible to control
1004 # CL.EXE complains to override flags like "/GR /GR-".
1005 string(REGEX REPLACE "(^| ) */EH[-cs]+ *( |$)" "\\1 \\2" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
1006 string(REGEX REPLACE "(^| ) */GR-? *( |$)" "\\1 \\2" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
1009 # Provide public options to globally control RTTI and EH
1010 option(LLVM_ENABLE_EH "Enable Exception handling" OFF)
1011 option(LLVM_ENABLE_RTTI "Enable run time type information" OFF)
1012 if(LLVM_ENABLE_EH AND NOT LLVM_ENABLE_RTTI)
1013 message(FATAL_ERROR "Exception handling requires RTTI. You must set LLVM_ENABLE_RTTI to ON")
1016 option(LLVM_ENABLE_IR_PGO "Build LLVM and tools with IR PGO instrumentation (deprecated)" Off)
1017 mark_as_advanced(LLVM_ENABLE_IR_PGO)
1019 set(LLVM_BUILD_INSTRUMENTED OFF CACHE STRING "Build LLVM and tools with PGO instrumentation. May be specified as IR or Frontend")
1020 set(LLVM_VP_COUNTERS_PER_SITE "1.5" CACHE STRING "Value profile counters to use per site for IR PGO with Clang")
1021 mark_as_advanced(LLVM_BUILD_INSTRUMENTED LLVM_VP_COUNTERS_PER_SITE)
1022 string(TOUPPER "${LLVM_BUILD_INSTRUMENTED}" uppercase_LLVM_BUILD_INSTRUMENTED)
1024 if (LLVM_BUILD_INSTRUMENTED)
1025 if (LLVM_ENABLE_IR_PGO OR uppercase_LLVM_BUILD_INSTRUMENTED STREQUAL "IR")
1026 append("-fprofile-generate=\"${LLVM_PROFILE_DATA_DIR}\""
1029 if(NOT LINKER_IS_LLD_LINK)
1030 append("-fprofile-generate=\"${LLVM_PROFILE_DATA_DIR}\""
1031 CMAKE_EXE_LINKER_FLAGS
1032 CMAKE_SHARED_LINKER_FLAGS)
1034 # Set this to avoid running out of the value profile node section
1035 # under clang in dynamic linking mode.
1036 if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND
1037 CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 11 AND
1038 LLVM_LINK_LLVM_DYLIB)
1039 append("-Xclang -mllvm -Xclang -vp-counters-per-site=${LLVM_VP_COUNTERS_PER_SITE}"
1043 elseif(uppercase_LLVM_BUILD_INSTRUMENTED STREQUAL "CSIR")
1044 append("-fcs-profile-generate=\"${LLVM_CSPROFILE_DATA_DIR}\""
1047 if(NOT LINKER_IS_LLD_LINK)
1048 append("-fcs-profile-generate=\"${LLVM_CSPROFILE_DATA_DIR}\""
1049 CMAKE_EXE_LINKER_FLAGS
1050 CMAKE_SHARED_LINKER_FLAGS)
1053 append("-fprofile-instr-generate=\"${LLVM_PROFILE_FILE_PATTERN}\""
1056 if(NOT LINKER_IS_LLD_LINK)
1057 append("-fprofile-instr-generate=\"${LLVM_PROFILE_FILE_PATTERN}\""
1058 CMAKE_EXE_LINKER_FLAGS
1059 CMAKE_SHARED_LINKER_FLAGS)
1064 # When using clang-cl with an instrumentation-based tool, add clang's library
1065 # resource directory to the library search path. Because cmake invokes the
1066 # linker directly, it isn't sufficient to pass -fsanitize=* to the linker.
1067 if (CLANG_CL AND (LLVM_BUILD_INSTRUMENTED OR LLVM_USE_SANITIZER))
1069 COMMAND ${CMAKE_CXX_COMPILER} /clang:-print-libgcc-file-name /clang:--rtlib=compiler-rt
1070 OUTPUT_VARIABLE clang_compiler_rt_file
1071 ERROR_VARIABLE clang_cl_stderr
1072 OUTPUT_STRIP_TRAILING_WHITESPACE
1073 ERROR_STRIP_TRAILING_WHITESPACE
1074 RESULT_VARIABLE clang_cl_exit_code)
1075 if (NOT "${clang_cl_exit_code}" STREQUAL "0")
1077 "Unable to invoke clang-cl to find resource dir: ${clang_cl_stderr}")
1079 file(TO_CMAKE_PATH "${clang_compiler_rt_file}" clang_compiler_rt_file)
1080 get_filename_component(clang_runtime_dir "${clang_compiler_rt_file}" DIRECTORY)
1081 append("/libpath:${clang_runtime_dir}"
1082 CMAKE_EXE_LINKER_FLAGS
1083 CMAKE_MODULE_LINKER_FLAGS
1084 CMAKE_SHARED_LINKER_FLAGS)
1087 if(LLVM_PROFDATA_FILE AND EXISTS ${LLVM_PROFDATA_FILE})
1088 if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" )
1089 append("-fprofile-instr-use=\"${LLVM_PROFDATA_FILE}\""
1092 if(NOT LINKER_IS_LLD_LINK)
1093 append("-fprofile-instr-use=\"${LLVM_PROFDATA_FILE}\""
1094 CMAKE_EXE_LINKER_FLAGS
1095 CMAKE_SHARED_LINKER_FLAGS)
1098 message(FATAL_ERROR "LLVM_PROFDATA_FILE can only be specified when compiling with clang")
1102 option(LLVM_BUILD_INSTRUMENTED_COVERAGE "Build LLVM and tools with Code Coverage instrumentation" Off)
1103 mark_as_advanced(LLVM_BUILD_INSTRUMENTED_COVERAGE)
1104 append_if(LLVM_BUILD_INSTRUMENTED_COVERAGE "-fprofile-instr-generate=\"${LLVM_PROFILE_FILE_PATTERN}\" -fcoverage-mapping"
1107 CMAKE_EXE_LINKER_FLAGS
1108 CMAKE_SHARED_LINKER_FLAGS)
1110 if (LLVM_BUILD_INSTRUMENTED AND LLVM_BUILD_INSTRUMENTED_COVERAGE)
1111 message(FATAL_ERROR "LLVM_BUILD_INSTRUMENTED and LLVM_BUILD_INSTRUMENTED_COVERAGE cannot both be specified")
1114 set(LLVM_THINLTO_CACHE_PATH "${PROJECT_BINARY_DIR}/lto.cache" CACHE STRING "Set ThinLTO cache path. This can be used when building LLVM from several different directiories.")
1116 if(LLVM_ENABLE_LTO AND LLVM_ON_WIN32 AND NOT LINKER_IS_LLD_LINK AND NOT MINGW)
1117 message(FATAL_ERROR "When compiling for Windows, LLVM_ENABLE_LTO requires using lld as the linker (point CMAKE_LINKER at lld-link.exe)")
1119 if(uppercase_LLVM_ENABLE_LTO STREQUAL "THIN")
1120 append("-flto=thin" CMAKE_CXX_FLAGS CMAKE_C_FLAGS)
1121 if(NOT LINKER_IS_LLD_LINK)
1122 append("-flto=thin" CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
1124 # If the linker supports it, enable the lto cache. This improves initial build
1125 # time a little since we re-link a lot of the same objects, and significantly
1126 # improves incremental build time.
1127 # FIXME: We should move all this logic into the clang driver.
1129 append("-Wl,-cache_path_lto,${LLVM_THINLTO_CACHE_PATH}"
1130 CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
1131 elseif((UNIX OR MINGW) AND LLVM_USE_LINKER STREQUAL "lld")
1132 append("-Wl,--thinlto-cache-dir=${LLVM_THINLTO_CACHE_PATH}"
1133 CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
1134 elseif(LLVM_USE_LINKER STREQUAL "gold")
1135 append("-Wl,--plugin-opt,cache-dir=${LLVM_THINLTO_CACHE_PATH}"
1136 CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
1137 elseif(LINKER_IS_LLD_LINK)
1138 append("/lldltocache:${LLVM_THINLTO_CACHE_PATH}"
1139 CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
1141 elseif(uppercase_LLVM_ENABLE_LTO STREQUAL "FULL")
1142 append("-flto=full" CMAKE_CXX_FLAGS CMAKE_C_FLAGS)
1143 if(NOT LINKER_IS_LLD_LINK)
1144 append("-flto=full" CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
1146 elseif(LLVM_ENABLE_LTO)
1147 append("-flto" CMAKE_CXX_FLAGS CMAKE_C_FLAGS)
1148 if(NOT LINKER_IS_LLD_LINK)
1149 append("-flto" CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
1153 # Set an AIX default for LLVM_EXPORT_SYMBOLS_FOR_PLUGINS based on whether we are
1154 # doing dynamic linking (see below).
1155 set(LLVM_EXPORT_SYMBOLS_FOR_PLUGINS_AIX_default OFF)
1156 if (NOT (BUILD_SHARED_LIBS OR LLVM_LINK_LLVM_DYLIB))
1157 set(LLVM_EXPORT_SYMBOLS_FOR_PLUGINS_AIX_default ON)
1160 # This option makes utils/extract_symbols.py be used to determine the list of
1161 # symbols to export from LLVM tools. This is necessary when on AIX or when using
1162 # MSVC if you want to allow plugins. On AIX we don't show this option, and we
1163 # enable it by default except when the LLVM libraries are set up for dynamic
1164 # linking (due to incompatibility). With MSVC, note that the plugin has to
1165 # explicitly link against (exactly one) tool so we can't unilaterally turn on
1166 # LLVM_ENABLE_PLUGINS when it's enabled.
1167 CMAKE_DEPENDENT_OPTION(LLVM_EXPORT_SYMBOLS_FOR_PLUGINS
1168 "Export symbols from LLVM tools so that plugins can import them" OFF
1169 "NOT ${CMAKE_SYSTEM_NAME} MATCHES AIX" ${LLVM_EXPORT_SYMBOLS_FOR_PLUGINS_AIX_default})
1170 if(BUILD_SHARED_LIBS AND LLVM_EXPORT_SYMBOLS_FOR_PLUGINS)
1171 message(FATAL_ERROR "BUILD_SHARED_LIBS not compatible with LLVM_EXPORT_SYMBOLS_FOR_PLUGINS")
1173 if(LLVM_LINK_LLVM_DYLIB AND LLVM_EXPORT_SYMBOLS_FOR_PLUGINS)
1174 message(FATAL_ERROR "LLVM_LINK_LLVM_DYLIB not compatible with LLVM_EXPORT_SYMBOLS_FOR_PLUGINS")
1177 # By default we should enable LLVM_ENABLE_IDE only for multi-configuration
1178 # generators. This option disables optional build system features that make IDEs
1180 set(LLVM_ENABLE_IDE_default OFF)
1181 if (CMAKE_CONFIGURATION_TYPES)
1182 set(LLVM_ENABLE_IDE_default ON)
1184 option(LLVM_ENABLE_IDE
1185 "Disable optional build system features that cause problems for IDE generators"
1186 ${LLVM_ENABLE_IDE_default})
1187 if (CMAKE_CONFIGURATION_TYPES AND NOT LLVM_ENABLE_IDE)
1188 message(WARNING "Disabling LLVM_ENABLE_IDE on multi-configuration generators is not recommended.")
1191 function(get_compile_definitions)
1192 get_directory_property(top_dir_definitions DIRECTORY ${CMAKE_SOURCE_DIR} COMPILE_DEFINITIONS)
1193 foreach(definition ${top_dir_definitions})
1195 string(APPEND result " -D${definition}")
1197 set(result "-D${definition}")
1200 set(LLVM_DEFINITIONS "${result}" PARENT_SCOPE)
1202 get_compile_definitions()
1204 option(LLVM_FORCE_ENABLE_STATS "Enable statistics collection for builds that wouldn't normally enable it" OFF)
1206 check_symbol_exists(os_signpost_interval_begin "os/signpost.h" macos_signposts_available)
1207 if(macos_signposts_available)
1208 check_cxx_source_compiles(
1209 "#include <os/signpost.h>
1210 int main() { os_signpost_interval_begin(nullptr, 0, \"\", \"\"); return 0; }"
1211 macos_signposts_usable)
1212 if(macos_signposts_usable)
1213 set(LLVM_ENABLE_SUPPORT_XCODE_SIGNPOSTS "WITH_ASSERTS" CACHE STRING
1214 "Enable support for Xcode signposts. Can be WITH_ASSERTS, FORCE_ON, FORCE_OFF")
1215 string(TOUPPER "${LLVM_ENABLE_SUPPORT_XCODE_SIGNPOSTS}"
1216 uppercase_LLVM_ENABLE_SUPPORT_XCODE_SIGNPOSTS)
1217 if( uppercase_LLVM_ENABLE_SUPPORT_XCODE_SIGNPOSTS STREQUAL "WITH_ASSERTS" )
1218 if( LLVM_ENABLE_ASSERTIONS )
1219 set( LLVM_SUPPORT_XCODE_SIGNPOSTS 1 )
1221 elseif( uppercase_LLVM_ENABLE_SUPPORT_XCODE_SIGNPOSTS STREQUAL "FORCE_ON" )
1222 set( LLVM_SUPPORT_XCODE_SIGNPOSTS 1 )
1223 elseif( uppercase_LLVM_ENABLE_SUPPORT_XCODE_SIGNPOSTS STREQUAL "FORCE_OFF" )
1224 # We don't need to do anything special to turn off signposts.
1225 elseif( NOT DEFINED LLVM_ENABLE_SUPPORT_XCODE_SIGNPOSTS )
1226 # Treat LLVM_ENABLE_SUPPORT_XCODE_SIGNPOSTS like "FORCE_OFF" when it has not been
1229 message(FATAL_ERROR "Unknown value for LLVM_ENABLE_SUPPORT_XCODE_SIGNPOSTS:"
1230 " \"${LLVM_ENABLE_SUPPORT_XCODE_SIGNPOSTS}\"!")
1235 set(LLVM_SOURCE_PREFIX "" CACHE STRING "Use prefix for sources")
1237 option(LLVM_USE_RELATIVE_PATHS_IN_DEBUG_INFO "Use relative paths in debug info" OFF)
1239 if(LLVM_USE_RELATIVE_PATHS_IN_DEBUG_INFO)
1240 check_c_compiler_flag("-fdebug-prefix-map=foo=bar" SUPPORTS_FDEBUG_PREFIX_MAP)
1241 if(LLVM_ENABLE_PROJECTS_USED)
1242 get_filename_component(source_root "${LLVM_MAIN_SRC_DIR}/.." ABSOLUTE)
1244 set(source_root "${LLVM_MAIN_SRC_DIR}")
1246 file(RELATIVE_PATH relative_root "${source_root}" "${CMAKE_BINARY_DIR}")
1247 append_if(SUPPORTS_FDEBUG_PREFIX_MAP "-fdebug-prefix-map=${CMAKE_BINARY_DIR}=${relative_root}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
1248 append_if(SUPPORTS_FDEBUG_PREFIX_MAP "-fdebug-prefix-map=${source_root}/=${LLVM_SOURCE_PREFIX}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
1249 add_flag_if_supported("-no-canonical-prefixes" NO_CANONICAL_PREFIXES)
1252 option(LLVM_USE_RELATIVE_PATHS_IN_FILES "Use relative paths in sources and debug info" OFF)
1254 if(LLVM_USE_RELATIVE_PATHS_IN_FILES)
1255 check_c_compiler_flag("-ffile-prefix-map=foo=bar" SUPPORTS_FFILE_PREFIX_MAP)
1256 if(LLVM_ENABLE_PROJECTS_USED)
1257 get_filename_component(source_root "${LLVM_MAIN_SRC_DIR}/.." ABSOLUTE)
1259 set(source_root "${LLVM_MAIN_SRC_DIR}")
1261 file(RELATIVE_PATH relative_root "${source_root}" "${CMAKE_BINARY_DIR}")
1262 append_if(SUPPORTS_FFILE_PREFIX_MAP "-ffile-prefix-map=${CMAKE_BINARY_DIR}=${relative_root}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
1263 append_if(SUPPORTS_FFILE_PREFIX_MAP "-ffile-prefix-map=${source_root}/=${LLVM_SOURCE_PREFIX}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
1264 add_flag_if_supported("-no-canonical-prefixes" NO_CANONICAL_PREFIXES)