aboutsummaryrefslogtreecommitdiff
path: root/lib/cmake/llvm/HandleLLVMOptions.cmake
diff options
context:
space:
mode:
authorDanny <danny@kdrag0n.dev>2021-01-09 23:34:32 +0000
committermosimchah <mosimchah@gmail.com>2021-01-22 03:35:20 -0800
commit783d21ff74759076d2fc503685ca47d2c29baea3 (patch)
treed650cc46cbf7ca53f15c77ced2682e97d492c068 /lib/cmake/llvm/HandleLLVMOptions.cmake
parentfdbc6f7102056fb52d26bfb2cbc6ea317890ee34 (diff)
Update to 20210109 buildHEADmaster
LLVM commit: https://github.com/llvm/llvm-project/commit/b02eab9058e58782fca32dd8b1e53c27ed93f866 binutils version: 2.35.1 Builder commit: https://github.com/kdrag0n/proton-clang-build/commit/ba42f701467c9103f23fbb90aca4b23858221ee2
Diffstat (limited to 'lib/cmake/llvm/HandleLLVMOptions.cmake')
-rw-r--r--lib/cmake/llvm/HandleLLVMOptions.cmake217
1 files changed, 179 insertions, 38 deletions
diff --git a/lib/cmake/llvm/HandleLLVMOptions.cmake b/lib/cmake/llvm/HandleLLVMOptions.cmake
index d519a7e..5d4d692 100644
--- a/lib/cmake/llvm/HandleLLVMOptions.cmake
+++ b/lib/cmake/llvm/HandleLLVMOptions.cmake
@@ -11,8 +11,10 @@ include(HandleLLVMStdlib)
include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
include(CheckSymbolExists)
+include(CMakeDependentOption)
+include(LLVMProcessSources)
-if(CMAKE_LINKER MATCHES "lld-link" OR (WIN32 AND LLVM_USE_LINKER STREQUAL "lld") OR LLVM_ENABLE_LLD)
+if(CMAKE_LINKER MATCHES "lld-link" OR (MSVC AND (LLVM_USE_LINKER STREQUAL "lld" OR LLVM_ENABLE_LLD)))
set(LINKER_IS_LLD_LINK TRUE)
else()
set(LINKER_IS_LLD_LINK FALSE)
@@ -26,7 +28,7 @@ string(TOUPPER "${LLVM_ENABLE_LTO}" uppercase_LLVM_ENABLE_LTO)
set(LLVM_PARALLEL_COMPILE_JOBS "" CACHE STRING
"Define the maximum number of concurrent compilation jobs (Ninja only).")
if(LLVM_PARALLEL_COMPILE_JOBS)
- if(NOT CMAKE_MAKE_PROGRAM MATCHES "ninja")
+ if(NOT CMAKE_GENERATOR STREQUAL "Ninja")
message(WARNING "Job pooling is only available with Ninja generators.")
else()
set_property(GLOBAL APPEND PROPERTY JOB_POOLS compile_job_pool=${LLVM_PARALLEL_COMPILE_JOBS})
@@ -36,7 +38,7 @@ endif()
set(LLVM_PARALLEL_LINK_JOBS "" CACHE STRING
"Define the maximum number of concurrent link jobs (Ninja only).")
-if(CMAKE_MAKE_PROGRAM MATCHES "ninja")
+if(CMAKE_GENERATOR STREQUAL "Ninja")
if(NOT LLVM_PARALLEL_LINK_JOBS AND uppercase_LLVM_ENABLE_LTO STREQUAL "THIN")
message(STATUS "ThinLTO provides its own parallel linking - limiting parallel link jobs to 2.")
set(LLVM_PARALLEL_LINK_JOBS "2")
@@ -57,7 +59,10 @@ if( LLVM_ENABLE_ASSERTIONS )
# On non-Debug builds cmake automatically defines NDEBUG, so we
# explicitly undefine it:
if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
- add_definitions( -UNDEBUG )
+ # NOTE: use `add_compile_options` rather than `add_definitions` since
+ # `add_definitions` does not support generator expressions.
+ add_compile_options($<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:-UNDEBUG>)
+
# Also remove /D NDEBUG to avoid MSVC warnings about conflicting defines.
foreach (flags_var_to_scrub
CMAKE_CXX_FLAGS_RELEASE
@@ -74,7 +79,26 @@ endif()
if(LLVM_ENABLE_EXPENSIVE_CHECKS)
add_definitions(-DEXPENSIVE_CHECKS)
- add_definitions(-D_GLIBCXX_DEBUG)
+
+ # In some libstdc++ versions, std::min_element is not constexpr when
+ # _GLIBCXX_DEBUG is enabled.
+ CHECK_CXX_SOURCE_COMPILES("
+ #define _GLIBCXX_DEBUG
+ #include <algorithm>
+ int main(int argc, char** argv) {
+ static constexpr int data[] = {0, 1};
+ constexpr const int* min_elt = std::min_element(&data[0], &data[2]);
+ return 0;
+ }" CXX_SUPPORTS_GLIBCXX_DEBUG)
+ if(CXX_SUPPORTS_GLIBCXX_DEBUG)
+ add_definitions(-D_GLIBCXX_DEBUG)
+ else()
+ add_definitions(-D_GLIBCXX_ASSERTIONS)
+ endif()
+endif()
+
+if (LLVM_ENABLE_STRICT_FIXED_SIZE_VECTORS)
+ add_definitions(-DSTRICT_FIXED_SIZE_VECTORS)
endif()
string(TOUPPER "${LLVM_ABI_BREAKING_CHECKS}" uppercase_LLVM_ABI_BREAKING_CHECKS)
@@ -121,6 +145,10 @@ else(WIN32)
endif(FUCHSIA OR UNIX)
endif(WIN32)
+if (CMAKE_SYSTEM_NAME MATCHES "OS390")
+ set(LLVM_HAVE_LINK_VERSION_SCRIPT 0)
+endif()
+
set(EXEEXT ${CMAKE_EXECUTABLE_SUFFIX})
set(LTDL_SHLIB_EXT ${CMAKE_SHARED_LIBRARY_SUFFIX})
@@ -137,13 +165,21 @@ endif()
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
# RHEL7 has ar and ranlib being non-deterministic by default. The D flag forces determinism,
- # however only GNU version of ar and ranlib (2.27) have this option.
+ # however only GNU version of ar and ranlib (2.27) have this option.
# RHEL DTS7 is also affected by this, which uses GNU binutils 2.28
execute_process(COMMAND ${CMAKE_AR} rD t.a
- WORKING_DIRECTORY ${CMAKE_BINARY_DIR} RESULT_VARIABLE AR_RESULT OUTPUT_VARIABLE RANLIB_OUTPUT)
+ WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+ RESULT_VARIABLE AR_RESULT
+ OUTPUT_QUIET
+ ERROR_QUIET
+ )
if(${AR_RESULT} EQUAL 0)
execute_process(COMMAND ${CMAKE_RANLIB} -D t.a
- WORKING_DIRECTORY ${CMAKE_BINARY_DIR} RESULT_VARIABLE RANLIB_RESULT OUTPUT_VARIABLE RANLIB_OUTPUT)
+ WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+ RESULT_VARIABLE RANLIB_RESULT
+ OUTPUT_QUIET
+ ERROR_QUIET
+ )
if(${RANLIB_RESULT} EQUAL 0)
set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> Dqc <TARGET> <LINK_FLAGS> <OBJECTS>")
set(CMAKE_C_ARCHIVE_APPEND "<CMAKE_AR> Dq <TARGET> <LINK_FLAGS> <OBJECTS>")
@@ -158,30 +194,25 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
endif()
if(${CMAKE_SYSTEM_NAME} MATCHES "AIX")
- if(NOT LLVM_BUILD_32_BITS)
- if (CMAKE_CXX_COMPILER_ID MATCHES "XL")
- append("-q64" CMAKE_CXX_FLAGS CMAKE_C_FLAGS)
- else()
- append("-maix64" CMAKE_CXX_FLAGS CMAKE_C_FLAGS)
- endif()
- set(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> -X64 qc <TARGET> <LINK_FLAGS> <OBJECTS>")
- set(CMAKE_CXX_ARCHIVE_APPEND "<CMAKE_AR> -X64 q <TARGET> <LINK_FLAGS> <OBJECTS>")
- set(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> -X64 <TARGET>")
- set(CMAKE_CXX_ARCHIVE_FINISH "<CMAKE_RANLIB> -X64 <TARGET>")
- endif()
# -fPIC does not enable the large code model for GCC on AIX but does for XL.
- if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
+ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
append("-mcmodel=large" CMAKE_CXX_FLAGS CMAKE_C_FLAGS)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "XL")
# XL generates a small number of relocations not of the large model, -bbigtoc is needed.
append("-Wl,-bbigtoc"
CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
+ # The default behaviour on AIX processes dynamic initialization of non-local variables with
+ # static storage duration even for archive members that are otherwise unreferenced.
+ # Since `--whole-archive` is not used by the LLVM build to keep such initializations for Linux,
+ # we can limit the processing for archive members to only those that are otherwise referenced.
+ append("-bcdtors:mbr"
+ CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
endif()
endif()
# Pass -Wl,-z,defs. This makes sure all symbols are defined. Otherwise a DSO
# build might work on ELF but fail on MachO/COFF.
-if(NOT (${CMAKE_SYSTEM_NAME} MATCHES "Darwin|FreeBSD|OpenBSD|DragonFly|AIX|SunOS" OR
+if(NOT (CMAKE_SYSTEM_NAME MATCHES "Darwin|FreeBSD|OpenBSD|DragonFly|AIX|SunOS|OS390" OR
WIN32 OR CYGWIN) AND
NOT LLVM_USE_SANITIZER)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,defs")
@@ -235,7 +266,12 @@ if( LLVM_ENABLE_LLD )
if ( LLVM_USE_LINKER )
message(FATAL_ERROR "LLVM_ENABLE_LLD and LLVM_USE_LINKER can't be set at the same time")
endif()
- set(LLVM_USE_LINKER "lld")
+ # In case of MSVC cmake always invokes the linker directly, so the linker
+ # should be specified by CMAKE_LINKER cmake variable instead of by -fuse-ld
+ # compiler option.
+ if ( NOT MSVC )
+ set(LLVM_USE_LINKER "lld")
+ endif()
endif()
if( LLVM_USE_LINKER )
@@ -265,6 +301,15 @@ if( LLVM_ENABLE_PIC )
NOT Uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG")
add_flag_or_print_warning("-fno-shrink-wrap" FNO_SHRINK_WRAP)
endif()
+ # gcc with -O3 -fPIC generates TLS sequences that violate the spec on
+ # Solaris/sparcv9, causing executables created with the system linker
+ # to SEGV (GCC PR target/96607).
+ # clang with -O3 -fPIC generates code that SEGVs.
+ # Both can be worked around by compiling with -O instead.
+ if(${CMAKE_SYSTEM_NAME} STREQUAL "SunOS" AND LLVM_NATIVE_ARCH STREQUAL "Sparc")
+ llvm_replace_compiler_option(CMAKE_CXX_FLAGS_RELEASE "-O[23]" "-O")
+ llvm_replace_compiler_option(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O[23]" "-O")
+ endif()
endif()
if(NOT WIN32 AND NOT CYGWIN AND NOT (${CMAKE_SYSTEM_NAME} MATCHES "AIX" AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU"))
@@ -364,6 +409,8 @@ elseif(MINGW) # FIXME: Also cygwin?
endif()
endif()
+option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." ON)
+
if( MSVC )
include(ChooseMSVCCRT)
@@ -390,6 +437,12 @@ if( MSVC )
append("/Zc:inline" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
+ # Some projects use the __cplusplus preprocessor macro to check support for
+ # a particular version of the C++ standard. When this option is not specified
+ # explicitly, macro's value is "199711L" that implies C++98 Standard.
+ # https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/
+ append("/Zc:__cplusplus" CMAKE_CXX_FLAGS)
+
# Allow users to request PDBs in release mode. CMake offeres the
# RelWithDebInfo configuration, but it uses different optimization settings
# (/Ob1 vs /Ob2 or -O2 vs -O3). LLVM provides this flag so that users can get
@@ -442,6 +495,10 @@ if( MSVC )
endif()
endif()
endif()
+ # By default MSVC has a 2^16 limit on the number of sections in an object file,
+ # but in many objects files need more than that. This flag is to increase the
+ # number of sections.
+ append("/bigobj" CMAKE_CXX_FLAGS)
endif( MSVC )
# Warnings-as-errors handling for GCC-compatible compilers:
@@ -499,7 +556,6 @@ if (MSVC)
-wd4244 # Suppress ''argument' : conversion from 'type1' to 'type2', possible loss of data'
-wd4267 # Suppress ''var' : conversion from 'size_t' to 'type', possible loss of data'
-wd4291 # Suppress ''declaration' : no matching operator delete found; memory will not be freed if initialization throws an exception'
- -wd4345 # Suppress 'behavior change: an object of POD type constructed with an initializer of the form () will be default-initialized'
-wd4351 # Suppress 'new behavior: elements of array 'array' will be default initialized'
-wd4456 # Suppress 'declaration of 'var' hides local variable'
-wd4457 # Suppress 'declaration of 'var' hides function parameter'
@@ -647,6 +703,21 @@ if (LLVM_ENABLE_WARNINGS AND (LLVM_COMPILER_IS_GCC_COMPATIBLE OR CLANG_CL))
# Enable -Wdelete-non-virtual-dtor if available.
add_flag_if_supported("-Wdelete-non-virtual-dtor" DELETE_NON_VIRTUAL_DTOR_FLAG)
+ # Enable -Wsuggest-override if it's available, and only if it doesn't
+ # suggest adding 'override' to functions that are already marked 'final'
+ # (which means it is disabled for GCC < 9.2).
+ check_cxx_compiler_flag("-Wsuggest-override" CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG)
+ if (CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG)
+ set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
+ set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Werror=suggest-override")
+ CHECK_CXX_SOURCE_COMPILES("class base {public: virtual void anchor();};
+ class derived : base {public: void anchor() final;};
+ int main() { return 0; }"
+ CXX_WSUGGEST_OVERRIDE_ALLOWS_ONLY_FINAL)
+ set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
+ append_if(CXX_WSUGGEST_OVERRIDE_ALLOWS_ONLY_FINAL "-Wsuggest-override" CMAKE_CXX_FLAGS)
+ endif()
+
# Check if -Wcomment is OK with an // comment ending with '\' if the next
# line is also a // comment.
set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
@@ -705,16 +776,17 @@ if(LLVM_USE_SANITIZER)
endif()
elseif (LLVM_USE_SANITIZER STREQUAL "Undefined")
append_common_sanitizer_flags()
- append("-fsanitize=undefined -fno-sanitize=vptr,function -fno-sanitize-recover=all"
- CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
+ append("${LLVM_UBSAN_FLAGS}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
elseif (LLVM_USE_SANITIZER STREQUAL "Thread")
append_common_sanitizer_flags()
append("-fsanitize=thread" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
+ elseif (LLVM_USE_SANITIZER STREQUAL "DataFlow")
+ append("-fsanitize=dataflow" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
elseif (LLVM_USE_SANITIZER STREQUAL "Address;Undefined" OR
LLVM_USE_SANITIZER STREQUAL "Undefined;Address")
append_common_sanitizer_flags()
- append("-fsanitize=address,undefined -fno-sanitize=vptr,function -fno-sanitize-recover=all"
- CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
+ append("-fsanitize=address" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
+ append("${LLVM_UBSAN_FLAGS}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
elseif (LLVM_USE_SANITIZER STREQUAL "Leaks")
append_common_sanitizer_flags()
append("-fsanitize=leak" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
@@ -747,9 +819,15 @@ if(LLVM_USE_SANITIZER)
endif()
endif()
-# Turn on -gsplit-dwarf if requested
-if(LLVM_USE_SPLIT_DWARF)
- add_definitions("-gsplit-dwarf")
+# Turn on -gsplit-dwarf if requested in debug builds.
+if (LLVM_USE_SPLIT_DWARF AND
+ ((uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG") OR
+ (uppercase_CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO")))
+ # Limit to clang and gcc so far. Add compilers supporting this option.
+ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR
+ CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
+ add_compile_options(-gsplit-dwarf)
+ endif()
endif()
add_definitions( -D__STDC_CONSTANT_MACROS )
@@ -790,6 +868,10 @@ if(NOT CYGWIN AND NOT WIN32)
endif()
add_flag_if_supported("-fdata-sections" FDATA_SECTIONS)
endif()
+elseif(MSVC)
+ if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
+ append("/Gw" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
+ endif()
endif()
if(MSVC)
@@ -822,7 +904,8 @@ option(LLVM_ENABLE_IR_PGO "Build LLVM and tools with IR PGO instrumentation (dep
mark_as_advanced(LLVM_ENABLE_IR_PGO)
set(LLVM_BUILD_INSTRUMENTED OFF CACHE STRING "Build LLVM and tools with PGO instrumentation. May be specified as IR or Frontend")
-mark_as_advanced(LLVM_BUILD_INSTRUMENTED)
+set(LLVM_VP_COUNTERS_PER_SITE "1.5" CACHE STRING "Value profile counters to use per site for IR PGO with Clang")
+mark_as_advanced(LLVM_BUILD_INSTRUMENTED LLVM_VP_COUNTERS_PER_SITE)
string(TOUPPER "${LLVM_BUILD_INSTRUMENTED}" uppercase_LLVM_BUILD_INSTRUMENTED)
if (LLVM_BUILD_INSTRUMENTED)
@@ -835,6 +918,15 @@ if (LLVM_BUILD_INSTRUMENTED)
CMAKE_EXE_LINKER_FLAGS
CMAKE_SHARED_LINKER_FLAGS)
endif()
+ # Set this to avoid running out of the value profile node section
+ # under clang in dynamic linking mode.
+ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND
+ CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 11 AND
+ LLVM_LINK_LLVM_DYLIB)
+ append("-Xclang -mllvm -Xclang -vp-counters-per-site=${LLVM_VP_COUNTERS_PER_SITE}"
+ CMAKE_CXX_FLAGS
+ CMAKE_C_FLAGS)
+ endif()
elseif(uppercase_LLVM_BUILD_INSTRUMENTED STREQUAL "CSIR")
append("-fcs-profile-generate=\"${LLVM_CSPROFILE_DATA_DIR}\""
CMAKE_CXX_FLAGS
@@ -856,6 +948,28 @@ if (LLVM_BUILD_INSTRUMENTED)
endif()
endif()
+# When using clang-cl with an instrumentation-based tool, add clang's library
+# resource directory to the library search path. Because cmake invokes the
+# linker directly, it isn't sufficient to pass -fsanitize=* to the linker.
+if (CLANG_CL AND (LLVM_BUILD_INSTRUMENTED OR LLVM_USE_SANITIZER))
+ execute_process(
+ COMMAND ${CMAKE_CXX_COMPILER} /clang:-print-resource-dir
+ OUTPUT_VARIABLE clang_resource_dir
+ ERROR_VARIABLE clang_cl_stderr
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ ERROR_STRIP_TRAILING_WHITESPACE
+ RESULT_VARIABLE clang_cl_exit_code)
+ if (NOT "${clang_cl_exit_code}" STREQUAL "0")
+ message(FATAL_ERROR
+ "Unable to invoke clang-cl to find resource dir: ${clang_cl_stderr}")
+ endif()
+ file(TO_CMAKE_PATH "${clang_resource_dir}" clang_resource_dir)
+ append("/libpath:${clang_resource_dir}/lib/windows"
+ CMAKE_EXE_LINKER_FLAGS
+ CMAKE_MODULE_LINKER_FLAGS
+ CMAKE_SHARED_LINKER_FLAGS)
+endif()
+
if(LLVM_PROFDATA_FILE AND EXISTS ${LLVM_PROFDATA_FILE})
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" )
append("-fprofile-instr-use=\"${LLVM_PROFDATA_FILE}\""
@@ -883,7 +997,7 @@ if (LLVM_BUILD_INSTRUMENTED AND LLVM_BUILD_INSTRUMENTED_COVERAGE)
message(FATAL_ERROR "LLVM_BUILD_INSTRUMENTED and LLVM_BUILD_INSTRUMENTED_COVERAGE cannot both be specified")
endif()
-if(LLVM_ENABLE_LTO AND LLVM_ON_WIN32 AND NOT LINKER_IS_LLD_LINK)
+if(LLVM_ENABLE_LTO AND LLVM_ON_WIN32 AND NOT LINKER_IS_LLD_LINK AND NOT MINGW)
message(FATAL_ERROR "When compiling for Windows, LLVM_ENABLE_LTO requires using lld as the linker (point CMAKE_LINKER at lld-link.exe)")
endif()
if(uppercase_LLVM_ENABLE_LTO STREQUAL "THIN")
@@ -898,7 +1012,7 @@ if(uppercase_LLVM_ENABLE_LTO STREQUAL "THIN")
if(APPLE)
append("-Wl,-cache_path_lto,${PROJECT_BINARY_DIR}/lto.cache"
CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
- elseif(UNIX AND LLVM_USE_LINKER STREQUAL "lld")
+ elseif((UNIX OR MINGW) AND LLVM_USE_LINKER STREQUAL "lld")
append("-Wl,--thinlto-cache-dir=${PROJECT_BINARY_DIR}/lto.cache"
CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
elseif(LLVM_USE_LINKER STREQUAL "gold")
@@ -920,12 +1034,23 @@ elseif(LLVM_ENABLE_LTO)
endif()
endif()
+# Set an AIX default for LLVM_EXPORT_SYMBOLS_FOR_PLUGINS based on whether we are
+# doing dynamic linking (see below).
+set(LLVM_EXPORT_SYMBOLS_FOR_PLUGINS_AIX_default OFF)
+if (NOT (BUILD_SHARED_LIBS OR LLVM_LINK_LLVM_DYLIB))
+ set(LLVM_EXPORT_SYMBOLS_FOR_PLUGINS_AIX_default ON)
+endif()
+
# This option makes utils/extract_symbols.py be used to determine the list of
-# symbols to export from LLVM tools. This is necessary when using MSVC if you
-# want to allow plugins, though note that the plugin has to explicitly link
-# against (exactly one) tool so we can't unilaterally turn on
+# symbols to export from LLVM tools. This is necessary when on AIX or when using
+# MSVC if you want to allow plugins. On AIX we don't show this option, and we
+# enable it by default except when the LLVM libraries are set up for dynamic
+# linking (due to incompatibility). With MSVC, note that the plugin has to
+# explicitly link against (exactly one) tool so we can't unilaterally turn on
# LLVM_ENABLE_PLUGINS when it's enabled.
-option(LLVM_EXPORT_SYMBOLS_FOR_PLUGINS "Export symbols from LLVM tools so that plugins can import them" OFF)
+CMAKE_DEPENDENT_OPTION(LLVM_EXPORT_SYMBOLS_FOR_PLUGINS
+ "Export symbols from LLVM tools so that plugins can import them" OFF
+ "NOT ${CMAKE_SYSTEM_NAME} MATCHES AIX" ${LLVM_EXPORT_SYMBOLS_FOR_PLUGINS_AIX_default})
if(BUILD_SHARED_LIBS AND LLVM_EXPORT_SYMBOLS_FOR_PLUGINS)
message(FATAL_ERROR "BUILD_SHARED_LIBS not compatible with LLVM_EXPORT_SYMBOLS_FOR_PLUGINS")
endif()
@@ -991,8 +1116,9 @@ if(macos_signposts_available)
endif()
endif()
+set(LLVM_SOURCE_PREFIX "" CACHE STRING "Use prefix for sources")
+
option(LLVM_USE_RELATIVE_PATHS_IN_DEBUG_INFO "Use relative paths in debug info" OFF)
-set(LLVM_SOURCE_PREFIX "" CACHE STRING "Use prefix for sources in debug info")
if(LLVM_USE_RELATIVE_PATHS_IN_DEBUG_INFO)
check_c_compiler_flag("-fdebug-prefix-map=foo=bar" SUPPORTS_FDEBUG_PREFIX_MAP)
@@ -1006,3 +1132,18 @@ if(LLVM_USE_RELATIVE_PATHS_IN_DEBUG_INFO)
append_if(SUPPORTS_FDEBUG_PREFIX_MAP "-fdebug-prefix-map=${source_root}/=${LLVM_SOURCE_PREFIX}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
add_flag_if_supported("-no-canonical-prefixes" NO_CANONICAL_PREFIXES)
endif()
+
+option(LLVM_USE_RELATIVE_PATHS_IN_FILES "Use relative paths in sources and debug info" OFF)
+
+if(LLVM_USE_RELATIVE_PATHS_IN_FILES)
+ check_c_compiler_flag("-ffile-prefix-map=foo=bar" SUPPORTS_FFILE_PREFIX_MAP)
+ if(LLVM_ENABLE_PROJECTS_USED)
+ get_filename_component(source_root "${LLVM_MAIN_SRC_DIR}/.." ABSOLUTE)
+ else()
+ set(source_root "${LLVM_MAIN_SRC_DIR}")
+ endif()
+ file(RELATIVE_PATH relative_root "${source_root}" "${CMAKE_BINARY_DIR}")
+ append_if(SUPPORTS_FFILE_PREFIX_MAP "-ffile-prefix-map=${CMAKE_BINARY_DIR}=${relative_root}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
+ append_if(SUPPORTS_FFILE_PREFIX_MAP "-ffile-prefix-map=${source_root}/=${LLVM_SOURCE_PREFIX}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
+ add_flag_if_supported("-no-canonical-prefixes" NO_CANONICAL_PREFIXES)
+endif()