diff options
author | Patrick Wildt <patrick@cvs.openbsd.org> | 2018-04-06 14:26:57 +0000 |
---|---|---|
committer | Patrick Wildt <patrick@cvs.openbsd.org> | 2018-04-06 14:26:57 +0000 |
commit | 5b0514634148624e8c36b28a654e89ce77f7cc92 (patch) | |
tree | c8c69996dfcbfd77243169cfb2652e27604a50d3 /gnu/llvm/cmake | |
parent | 2d2537b3985221b371b2a4a1471fa2e56b846bf0 (diff) |
Import LLVM 6.0.1 release including clang, lld and lldb.
"where is the kaboom?" deraadt@
Diffstat (limited to 'gnu/llvm/cmake')
20 files changed, 886 insertions, 244 deletions
diff --git a/gnu/llvm/cmake/config-ix.cmake b/gnu/llvm/cmake/config-ix.cmake index de8e9bf9a49..aaf22ff474b 100755 --- a/gnu/llvm/cmake/config-ix.cmake +++ b/gnu/llvm/cmake/config-ix.cmake @@ -8,6 +8,7 @@ include(CheckIncludeFileCXX) include(CheckLibraryExists) include(CheckSymbolExists) include(CheckFunctionExists) +include(CheckCCompilerFlag) include(CheckCXXSourceCompiles) include(TestBigEndian) @@ -16,7 +17,7 @@ include(HandleLLVMStdlib) if( UNIX AND NOT (BEOS OR HAIKU) ) # Used by check_symbol_exists: - set(CMAKE_REQUIRED_LIBRARIES m) + list(APPEND CMAKE_REQUIRED_LIBRARIES "m") endif() # x86_64 FreeBSD 9.2 requires libcxxrt to be specified explicitly. if( CMAKE_SYSTEM MATCHES "FreeBSD-9.2-RELEASE" AND @@ -126,37 +127,63 @@ if(HAVE_LIBPTHREAD) set(LLVM_PTHREAD_LIB ${CMAKE_THREAD_LIBS_INIT}) endif() -# Don't look for these libraries on Windows. Also don't look for them if we're -# using MSan, since uninstrumented third party code may call MSan interceptors -# like strlen, leading to false positives. -if( NOT PURE_WINDOWS AND NOT LLVM_USE_SANITIZER MATCHES "Memory.*") - if (LLVM_ENABLE_ZLIB) - check_library_exists(z compress2 "" HAVE_LIBZ) - else() - set(HAVE_LIBZ 0) - endif() - # Skip libedit if using ASan as it contains memory leaks. - if (LLVM_ENABLE_LIBEDIT AND HAVE_HISTEDIT_H AND NOT LLVM_USE_SANITIZER MATCHES ".*Address.*") - check_library_exists(edit el_init "" HAVE_LIBEDIT) - else() - set(HAVE_LIBEDIT 0) - endif() - if(LLVM_ENABLE_TERMINFO) - set(HAVE_TERMINFO 0) - foreach(library tinfo terminfo curses ncurses ncursesw) +# Don't look for these libraries if we're using MSan, since uninstrumented third +# party code may call MSan interceptors like strlen, leading to false positives. +if(NOT LLVM_USE_SANITIZER MATCHES "Memory.*") + set(HAVE_LIBZ 0) + if(LLVM_ENABLE_ZLIB) + foreach(library z zlib_static zlib) string(TOUPPER ${library} library_suffix) - check_library_exists(${library} setupterm "" HAVE_TERMINFO_${library_suffix}) - if(HAVE_TERMINFO_${library_suffix}) - set(HAVE_TERMINFO 1) - set(TERMINFO_LIBS "${library}") + check_library_exists(${library} compress2 "" HAVE_LIBZ_${library_suffix}) + if(HAVE_LIBZ_${library_suffix}) + set(HAVE_LIBZ 1) + set(ZLIB_LIBRARIES "${library}") break() endif() endforeach() - else() - set(HAVE_TERMINFO 0) + endif() + + # Don't look for these libraries on Windows. + if (NOT PURE_WINDOWS) + # Skip libedit if using ASan as it contains memory leaks. + if (LLVM_ENABLE_LIBEDIT AND HAVE_HISTEDIT_H AND NOT LLVM_USE_SANITIZER MATCHES ".*Address.*") + check_library_exists(edit el_init "" HAVE_LIBEDIT) + else() + set(HAVE_LIBEDIT 0) + endif() + if(LLVM_ENABLE_TERMINFO) + set(HAVE_TERMINFO 0) + foreach(library tinfo terminfo curses ncurses ncursesw) + string(TOUPPER ${library} library_suffix) + check_library_exists(${library} setupterm "" HAVE_TERMINFO_${library_suffix}) + if(HAVE_TERMINFO_${library_suffix}) + set(HAVE_TERMINFO 1) + set(TERMINFO_LIBS "${library}") + break() + endif() + endforeach() + else() + set(HAVE_TERMINFO 0) + endif() + + find_library(ICONV_LIBRARY_PATH NAMES iconv libiconv libiconv-2 c) + set(LLVM_LIBXML2_ENABLED 0) + set(LIBXML2_FOUND 0) + if((LLVM_ENABLE_LIBXML2) AND ((CMAKE_SYSTEM_NAME MATCHES "Linux") AND (ICONV_LIBRARY_PATH) OR APPLE)) + find_package(LibXml2) + if (LIBXML2_FOUND) + set(LLVM_LIBXML2_ENABLED 1) + include_directories(${LIBXML2_INCLUDE_DIR}) + set(LIBXML2_LIBS "xml2") + endif() + endif() endif() endif() +if (LLVM_ENABLE_LIBXML2 STREQUAL "FORCE_ON" AND NOT LLVM_LIBXML2_ENABLED) + message(FATAL_ERROR "Failed to congifure libxml2") +endif() + check_library_exists(xar xar_open "" HAVE_LIBXAR) if(HAVE_LIBXAR) set(XAR_LIB xar) @@ -167,6 +194,14 @@ check_symbol_exists(arc4random "stdlib.h" HAVE_DECL_ARC4RANDOM) find_package(Backtrace) set(HAVE_BACKTRACE ${Backtrace_FOUND}) set(BACKTRACE_HEADER ${Backtrace_HEADER}) + +# Prevent check_symbol_exists from using API that is not supported for a given +# deployment target. +check_c_compiler_flag("-Werror=unguarded-availability-new" "C_SUPPORTS_WERROR_UNGUARDED_AVAILABILITY_NEW") +if(C_SUPPORTS_WERROR_UNGUARDED_AVAILABILITY_NEW) + set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Werror=unguarded-availability-new") +endif() + check_symbol_exists(_Unwind_Backtrace "unwind.h" HAVE__UNWIND_BACKTRACE) check_symbol_exists(getpagesize unistd.h HAVE_GETPAGESIZE) check_symbol_exists(sysconf unistd.h HAVE_SYSCONF) @@ -246,8 +281,11 @@ endif() check_symbol_exists(__GLIBC__ stdio.h LLVM_USING_GLIBC) if( LLVM_USING_GLIBC ) add_definitions( -D_GNU_SOURCE ) + list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_GNU_SOURCE") endif() # This check requires _GNU_SOURCE +check_symbol_exists(sched_getaffinity sched.h HAVE_SCHED_GETAFFINITY) +check_symbol_exists(CPU_COUNT sched.h HAVE_CPU_COUNT) if(HAVE_LIBPTHREAD) check_library_exists(pthread pthread_getname_np "" HAVE_PTHREAD_GETNAME_NP) check_library_exists(pthread pthread_setname_np "" HAVE_PTHREAD_SETNAME_NP) @@ -600,3 +638,38 @@ else() endif() string(REPLACE " " ";" LLVM_BINDINGS_LIST "${LLVM_BINDINGS}") + +function(find_python_module module) + string(REPLACE "." "_" module_name ${module}) + string(TOUPPER ${module_name} module_upper) + set(FOUND_VAR PY_${module_upper}_FOUND) + + execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c" "import ${module}" + RESULT_VARIABLE status + ERROR_QUIET) + + if(status) + set(${FOUND_VAR} 0 PARENT_SCOPE) + message(STATUS "Could NOT find Python module ${module}") + else() + set(${FOUND_VAR} 1 PARENT_SCOPE) + message(STATUS "Found Python module ${module}") + endif() +endfunction() + +set (PYTHON_MODULES + pygments + # Some systems still don't have pygments.lexers.c_cpp which was introduced in + # version 2.0 in 2014... + pygments.lexers.c_cpp + yaml + ) +foreach(module ${PYTHON_MODULES}) + find_python_module(${module}) +endforeach() + +if(PY_PYGMENTS_FOUND AND PY_PYGMENTS_LEXERS_C_CPP_FOUND AND PY_YAML_FOUND) + set (LLVM_HAVE_OPT_VIEWER_MODULES 1) +else() + set (LLVM_HAVE_OPT_VIEWER_MODULES 0) +endif() diff --git a/gnu/llvm/cmake/config.guess b/gnu/llvm/cmake/config.guess index 8bf4226db32..ccb30f4e75e 100644 --- a/gnu/llvm/cmake/config.guess +++ b/gnu/llvm/cmake/config.guess @@ -206,10 +206,6 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'` echo ${UNAME_MACHINE_ARCH}-unknown-openbsd${UNAME_RELEASE} exit ;; - *:Bitrig:*:*) - UNAME_MACHINE_ARCH=`arch | sed 's/Bitrig.//'` - echo ${UNAME_MACHINE_ARCH}-unknown-bitrig${UNAME_RELEASE} - exit ;; *:ekkoBSD:*:*) echo ${UNAME_MACHINE}-unknown-ekkobsd${UNAME_RELEASE} exit ;; diff --git a/gnu/llvm/cmake/modules/AddLLVM.cmake b/gnu/llvm/cmake/modules/AddLLVM.cmake index 1c922651b13..fd5627eecbb 100644 --- a/gnu/llvm/cmake/modules/AddLLVM.cmake +++ b/gnu/llvm/cmake/modules/AddLLVM.cmake @@ -149,8 +149,13 @@ endfunction(add_llvm_symbol_exports) if(NOT WIN32 AND NOT APPLE) # Detect what linker we have here + if( LLVM_USE_LINKER ) + set(command ${CMAKE_C_COMPILER} -fuse-ld=${LLVM_USE_LINKER} -Wl,--version) + else() + set(command ${CMAKE_C_COMPILER} -Wl,--version) + endif() execute_process( - COMMAND ${CMAKE_C_COMPILER} -Wl,--version + COMMAND ${command} OUTPUT_VARIABLE stdout ERROR_VARIABLE stderr ) @@ -164,7 +169,8 @@ if(NOT WIN32 AND NOT APPLE) elseif("${stdout}" MATCHES "GNU ld") set(LLVM_LINKER_IS_GNULD ON) message(STATUS "Linker detection: GNU ld") - elseif("${stderr}" MATCHES "Solaris Link Editors") + elseif("${stderr}" MATCHES "Solaris Link Editors" OR + "${stdout}" MATCHES "Solaris Link Editors") set(LLVM_LINKER_IS_SOLARISLD ON) message(STATUS "Linker detection: Solaris ld") else() @@ -263,14 +269,14 @@ endfunction() # function(add_windows_version_resource_file OUT_VAR) set(sources ${ARGN}) - if (MSVC) + if (MSVC AND CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") set(resource_file ${LLVM_SOURCE_DIR}/resources/windows_version_resource.rc) if(EXISTS ${resource_file}) set(sources ${sources} ${resource_file}) source_group("Resource Files" ${resource_file}) set(windows_resource_file ${resource_file} PARENT_SCOPE) endif() - endif(MSVC) + endif(MSVC AND CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") set(${OUT_VAR} ${sources} PARENT_SCOPE) endfunction(add_windows_version_resource_file) @@ -563,6 +569,32 @@ function(llvm_add_library name) endif() endfunction() +function(add_llvm_install_targets target) + cmake_parse_arguments(ARG "" "COMPONENT;PREFIX" "DEPENDS" ${ARGN}) + if(ARG_COMPONENT) + set(component_option -DCMAKE_INSTALL_COMPONENT="${ARG_COMPONENT}") + endif() + if(ARG_PREFIX) + set(prefix_option -DCMAKE_INSTALL_PREFIX="${ARG_PREFIX}") + endif() + + add_custom_target(${target} + DEPENDS ${ARG_DEPENDS} + COMMAND "${CMAKE_COMMAND}" + ${component_option} + ${prefix_option} + -P "${CMAKE_BINARY_DIR}/cmake_install.cmake" + USES_TERMINAL) + add_custom_target(${target}-stripped + DEPENDS ${ARG_DEPENDS} + COMMAND "${CMAKE_COMMAND}" + ${component_option} + ${prefix_option} + -DCMAKE_INSTALL_DO_STRIP=1 + -P "${CMAKE_BINARY_DIR}/cmake_install.cmake" + USES_TERMINAL) +endfunction() + macro(add_llvm_library name) cmake_parse_arguments(ARG "SHARED;BUILDTREE_ONLY" @@ -613,11 +645,9 @@ macro(add_llvm_library name) COMPONENT ${name}) if (NOT CMAKE_CONFIGURATION_TYPES) - add_custom_target(install-${name} - DEPENDS ${name} - COMMAND "${CMAKE_COMMAND}" - -DCMAKE_INSTALL_COMPONENT=${name} - -P "${CMAKE_BINARY_DIR}/cmake_install.cmake") + add_llvm_install_targets(install-${name} + DEPENDS ${name} + COMPONENT ${name}) endif() endif() set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name}) @@ -687,7 +717,7 @@ macro(add_llvm_executable name) # it forces Xcode to properly link the static library. list(APPEND ALL_FILES "${LLVM_MAIN_SRC_DIR}/cmake/dummy.cpp") endif() - + if( EXCLUDE_FROM_ALL ) add_executable(${name} EXCLUDE_FROM_ALL ${ALL_FILES}) else() @@ -738,7 +768,7 @@ macro(add_llvm_executable name) # libpthreads overrides some standard library symbols, so main # executable must be linked with it in order to provide consistent # API for all shared libaries loaded by this executable. - target_link_libraries(${name} ${LLVM_PTHREAD_LIB}) + target_link_libraries(${name} PRIVATE ${LLVM_PTHREAD_LIB}) endif() endmacro(add_llvm_executable name) @@ -843,11 +873,9 @@ macro(add_llvm_tool name) COMPONENT ${name}) if (NOT CMAKE_CONFIGURATION_TYPES) - add_custom_target(install-${name} - DEPENDS ${name} - COMMAND "${CMAKE_COMMAND}" - -DCMAKE_INSTALL_COMPONENT=${name} - -P "${CMAKE_BINARY_DIR}/cmake_install.cmake") + add_llvm_install_targets(install-${name} + DEPENDS ${name} + COMPONENT ${name}) endif() endif() endif() @@ -883,15 +911,30 @@ macro(add_llvm_utility name) RUNTIME DESTINATION ${LLVM_UTILS_INSTALL_DIR} COMPONENT ${name}) if (NOT CMAKE_CONFIGURATION_TYPES) - add_custom_target(install-${name} - DEPENDS ${name} - COMMAND "${CMAKE_COMMAND}" - -DCMAKE_INSTALL_COMPONENT=${name} - -P "${CMAKE_BINARY_DIR}/cmake_install.cmake") + add_llvm_install_targets(install-${name} + DEPENDS ${name} + COMPONENT ${name}) endif() endif() endmacro(add_llvm_utility name) +macro(add_llvm_fuzzer name) + cmake_parse_arguments(ARG "" "DUMMY_MAIN" "" ${ARGN}) + if( LLVM_LIB_FUZZING_ENGINE ) + set(LLVM_OPTIONAL_SOURCES ${ARG_DUMMY_MAIN}) + add_llvm_executable(${name} ${ARG_UNPARSED_ARGUMENTS}) + target_link_libraries(${name} PRIVATE ${LLVM_LIB_FUZZING_ENGINE}) + set_target_properties(${name} PROPERTIES FOLDER "Fuzzers") + elseif( LLVM_USE_SANITIZE_COVERAGE ) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=fuzzer") + set(LLVM_OPTIONAL_SOURCES ${ARG_DUMMY_MAIN}) + add_llvm_executable(${name} ${ARG_UNPARSED_ARGUMENTS}) + set_target_properties(${name} PROPERTIES FOLDER "Fuzzers") + elseif( ARG_DUMMY_MAIN ) + add_llvm_executable(${name} ${ARG_DUMMY_MAIN} ${ARG_UNPARSED_ARGUMENTS}) + set_target_properties(${name} PROPERTIES FOLDER "Fuzzers") + endif() +endmacro() macro(add_llvm_target target_name) include_directories(BEFORE @@ -1020,6 +1063,13 @@ function(add_unittest test_suite test_name) set(EXCLUDE_FROM_ALL ON) endif() + # Our current version of gtest does not properly recognize C++11 support + # with MSVC, so it falls back to tr1 / experimental classes. Since LLVM + # itself requires C++11, we can safely force it on unconditionally so that + # we don't have to fight with the buggy gtest check. + add_definitions(-DGTEST_LANG_CXX11=1) + add_definitions(-DGTEST_HAS_TR1_TUPLE=0) + include_directories(${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include) include_directories(${LLVM_MAIN_SRC_DIR}/utils/unittest/googlemock/include) if (NOT LLVM_ENABLE_THREADS) @@ -1043,7 +1093,7 @@ function(add_unittest test_suite test_name) # libpthreads overrides some standard library symbols, so main # executable must be linked with it in order to provide consistent # API for all shared libaries loaded by this executable. - target_link_libraries(${test_name} gtest_main gtest ${LLVM_PTHREAD_LIB}) + target_link_libraries(${test_name} PRIVATE gtest_main gtest ${LLVM_PTHREAD_LIB}) add_dependencies(${test_suite} ${test_name}) get_target_property(test_suite_folder ${test_suite} FOLDER) @@ -1095,12 +1145,31 @@ function(llvm_canonicalize_cmake_booleans) endforeach() endfunction(llvm_canonicalize_cmake_booleans) +macro(set_llvm_build_mode) + # Configuration-time: See Unit/lit.site.cfg.in + if (CMAKE_CFG_INTDIR STREQUAL ".") + set(LLVM_BUILD_MODE ".") + else () + set(LLVM_BUILD_MODE "%(build_mode)s") + endif () +endmacro() + # This function provides an automatic way to 'configure'-like generate a file # based on a set of common and custom variables, specifically targeting the # variables needed for the 'lit.site.cfg' files. This function bundles the # common variables that any Lit instance is likely to need, and custom # variables can be passed in. -function(configure_lit_site_cfg input output) +function(configure_lit_site_cfg site_in site_out) + cmake_parse_arguments(ARG "" "" "MAIN_CONFIG;OUTPUT_MAPPING" ${ARGN}) + + if ("${ARG_MAIN_CONFIG}" STREQUAL "") + get_filename_component(INPUT_DIR ${site_in} DIRECTORY) + set(ARG_MAIN_CONFIG "${INPUT_DIR}/lit.cfg") + endif() + if ("${ARG_OUTPUT_MAPPING}" STREQUAL "") + set(ARG_OUTPUT_MAPPING "${site_out}") + endif() + foreach(c ${LLVM_TARGETS_TO_BUILD}) set(TARGETS_BUILT "${TARGETS_BUILT} ${c}") endforeach(c) @@ -1108,21 +1177,16 @@ function(configure_lit_site_cfg input output) set(SHLIBEXT "${LTDL_SHLIB_EXT}") - # Configuration-time: See Unit/lit.site.cfg.in - if (CMAKE_CFG_INTDIR STREQUAL ".") - set(LLVM_BUILD_MODE ".") - else () - set(LLVM_BUILD_MODE "%(build_mode)s") - endif () + set_llvm_build_mode() # They below might not be the build tree but provided binary tree. set(LLVM_SOURCE_DIR ${LLVM_MAIN_SRC_DIR}) set(LLVM_BINARY_DIR ${LLVM_BINARY_DIR}) - string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} LLVM_TOOLS_DIR ${LLVM_TOOLS_BINARY_DIR}) - string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} LLVM_LIBS_DIR ${LLVM_LIBRARY_DIR}) + string(REPLACE "${CMAKE_CFG_INTDIR}" "${LLVM_BUILD_MODE}" LLVM_TOOLS_DIR "${LLVM_TOOLS_BINARY_DIR}") + string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} LLVM_LIBS_DIR "${LLVM_LIBRARY_DIR}") # SHLIBDIR points the build tree. - string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} SHLIBDIR "${LLVM_SHLIB_OUTPUT_INTDIR}") + string(REPLACE "${CMAKE_CFG_INTDIR}" "${LLVM_BUILD_MODE}" SHLIBDIR "${LLVM_SHLIB_OUTPUT_INTDIR}") set(PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE}) # FIXME: "ENABLE_SHARED" doesn't make sense, since it is used just for @@ -1146,7 +1210,7 @@ function(configure_lit_site_cfg input output) set(HOST_CXX "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}") set(HOST_LDFLAGS "${CMAKE_EXE_LINKER_FLAGS}") - set(LIT_SITE_CFG_IN_HEADER "## Autogenerated from ${input}\n## Do not edit!") + set(LIT_SITE_CFG_IN_HEADER "## Autogenerated from ${site_in}\n## Do not edit!") # Override config_target_triple (and the env) if(LLVM_TARGET_TRIPLE_ENV) @@ -1161,7 +1225,74 @@ function(configure_lit_site_cfg input output) set(TARGET_TRIPLE "\"+config.target_triple+\"") endif() - configure_file(${input} ${output} @ONLY) + string(CONCAT LIT_SITE_CFG_IN_FOOTER + "import lit.llvm\n" + "lit.llvm.initialize(lit_config, config)\n") + + configure_file(${site_in} ${site_out} @ONLY) + if (EXISTS "${ARG_MAIN_CONFIG}") + set(PYTHON_STATEMENT "map_config('${ARG_MAIN_CONFIG}', '${site_out}')") + get_property(LLVM_LIT_CONFIG_MAP GLOBAL PROPERTY LLVM_LIT_CONFIG_MAP) + set(LLVM_LIT_CONFIG_MAP "${LLVM_LIT_CONFIG_MAP}\n${PYTHON_STATEMENT}") + set_property(GLOBAL PROPERTY LLVM_LIT_CONFIG_MAP ${LLVM_LIT_CONFIG_MAP}) + endif() +endfunction() + +function(dump_all_cmake_variables) + get_cmake_property(_variableNames VARIABLES) + foreach (_variableName ${_variableNames}) + message(STATUS "${_variableName}=${${_variableName}}") + endforeach() +endfunction() + +function(get_llvm_lit_path base_dir file_name) + cmake_parse_arguments(ARG "ALLOW_EXTERNAL" "" "" ${ARGN}) + + if (ARG_ALLOW_EXTERNAL) + set(LLVM_DEFAULT_EXTERNAL_LIT "${LLVM_EXTERNAL_LIT}") + set (LLVM_EXTERNAL_LIT "" CACHE STRING "Command used to spawn lit") + if ("${LLVM_EXTERNAL_LIT}" STREQUAL "") + set(LLVM_EXTERNAL_LIT "${LLVM_DEFAULT_EXTERNAL_LIT}") + endif() + + if (NOT "${LLVM_EXTERNAL_LIT}" STREQUAL "") + if (EXISTS ${LLVM_EXTERNAL_LIT}) + get_filename_component(LIT_FILE_NAME ${LLVM_EXTERNAL_LIT} NAME) + get_filename_component(LIT_BASE_DIR ${LLVM_EXTERNAL_LIT} DIRECTORY) + set(${file_name} ${LIT_FILE_NAME} PARENT_SCOPE) + set(${base_dir} ${LIT_BASE_DIR} PARENT_SCOPE) + return() + else() + message(WARN "LLVM_EXTERNAL_LIT set to ${LLVM_EXTERNAL_LIT}, but the path does not exist.") + endif() + endif() + endif() + + set(lit_file_name "llvm-lit") + if (WIN32 AND NOT CYGWIN) + # llvm-lit needs suffix.py for multiprocess to find a main module. + set(lit_file_name "${lit_file_name}.py") + endif () + set(${file_name} ${lit_file_name} PARENT_SCOPE) + + get_property(LLVM_LIT_BASE_DIR GLOBAL PROPERTY LLVM_LIT_BASE_DIR) + if (NOT "${LLVM_LIT_BASE_DIR}" STREQUAL "") + set(${base_dir} ${LLVM_LIT_BASE_DIR} PARENT_SCOPE) + endif() + + # Allow individual projects to provide an override + if (NOT "${LLVM_LIT_OUTPUT_DIR}" STREQUAL "") + set(LLVM_LIT_BASE_DIR ${LLVM_LIT_OUTPUT_DIR}) + elseif(NOT "${LLVM_RUNTIME_OUTPUT_INTDIR}" STREQUAL "") + set(LLVM_LIT_BASE_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR}) + else() + set(LLVM_LIT_BASE_DIR "") + endif() + + # Cache this so we don't have to do it again and have subsequent calls + # potentially disagree on the value. + set_property(GLOBAL PROPERTY LLVM_LIT_BASE_DIR ${LLVM_LIT_BASE_DIR}) + set(${base_dir} ${LLVM_LIT_BASE_DIR} PARENT_SCOPE) endfunction() # A raw function to create a lit target. This is used to implement the testuite @@ -1173,12 +1304,16 @@ function(add_lit_target target comment) if (NOT CMAKE_CFG_INTDIR STREQUAL ".") list(APPEND LIT_ARGS --param build_mode=${CMAKE_CFG_INTDIR}) endif () - if (EXISTS ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py) - set (LIT_COMMAND "${PYTHON_EXECUTABLE};${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py" - CACHE STRING "Command used to spawn llvm-lit") - else() - find_program(LIT_COMMAND NAMES llvm-lit lit.py lit) - endif () + + # Get the path to the lit to *run* tests with. This can be overriden by + # the user by specifying -DLLVM_EXTERNAL_LIT=<path-to-lit.py> + get_llvm_lit_path( + lit_base_dir + lit_file_name + ALLOW_EXTERNAL + ) + + set(LIT_COMMAND "${PYTHON_EXECUTABLE};${lit_base_dir}/${lit_file_name}") list(APPEND LIT_COMMAND ${LIT_ARGS}) foreach(param ${ARG_PARAMS}) list(APPEND LIT_COMMAND --param ${param}) @@ -1285,11 +1420,9 @@ function(llvm_install_library_symlink name dest type) COMPONENT ${component}) if (NOT CMAKE_CONFIGURATION_TYPES AND NOT ARG_ALWAYS_GENERATE) - add_custom_target(install-${name} - DEPENDS ${name} ${dest} install-${dest} - COMMAND "${CMAKE_COMMAND}" - -DCMAKE_INSTALL_COMPONENT=${name} - -P "${CMAKE_BINARY_DIR}/cmake_install.cmake") + add_llvm_install_targets(install-${name} + DEPENDS ${name} ${dest} install-${dest} + COMPONENT ${name}) endif() endfunction() @@ -1320,11 +1453,9 @@ function(llvm_install_symlink name dest) COMPONENT ${component}) if (NOT CMAKE_CONFIGURATION_TYPES AND NOT ARG_ALWAYS_GENERATE) - add_custom_target(install-${name} - DEPENDS ${name} ${dest} install-${dest} - COMMAND "${CMAKE_COMMAND}" - -DCMAKE_INSTALL_COMPONENT=${name} - -P "${CMAKE_BINARY_DIR}/cmake_install.cmake") + add_llvm_install_targets(install-${name} + DEPENDS ${name} ${dest} install-${dest} + COMPONENT ${name}) endif() endfunction() @@ -1338,7 +1469,7 @@ function(add_llvm_tool_symlink link_name target) # magic. First we grab one of the types, and a type-specific path. Then from # the type-specific path we find the last occurrence of the type in the path, # and replace it with CMAKE_CFG_INTDIR. This allows the build step to be type - # agnostic again. + # agnostic again. if(NOT ARG_OUTPUT_DIR) # If you're not overriding the OUTPUT_DIR, we can make the link relative in # the same directory. @@ -1488,3 +1619,36 @@ function(setup_dependency_debugging name) set(sandbox_command "sandbox-exec -p '(version 1) (allow default) ${deny_attributes_gen} ${deny_intrinsics_gen}'") set_target_properties(${name} PROPERTIES RULE_LAUNCH_COMPILE ${sandbox_command}) endfunction() + +# Figure out if we can track VC revisions. +function(find_first_existing_file out_var) + foreach(file ${ARGN}) + if(EXISTS "${file}") + set(${out_var} "${file}" PARENT_SCOPE) + return() + endif() + endforeach() +endfunction() + +macro(find_first_existing_vc_file out_var path) + find_program(git_executable NAMES git git.exe git.cmd) + # Run from a subdirectory to force git to print an absolute path. + execute_process(COMMAND ${git_executable} rev-parse --git-dir + WORKING_DIRECTORY ${path}/cmake + RESULT_VARIABLE git_result + OUTPUT_VARIABLE git_dir + ERROR_QUIET) + if(git_result EQUAL 0) + string(STRIP "${git_dir}" git_dir) + set(${out_var} "${git_dir}/logs/HEAD") + # some branchless cases (e.g. 'repo') may not yet have .git/logs/HEAD + if (NOT EXISTS "${git_dir}/logs/HEAD") + file(WRITE "${git_dir}/logs/HEAD" "") + endif() + else() + find_first_existing_file(${out_var} + "${path}/.svn/wc.db" # SVN 1.7 + "${path}/.svn/entries" # SVN 1.6 + ) + endif() +endmacro() diff --git a/gnu/llvm/cmake/modules/AddOCaml.cmake b/gnu/llvm/cmake/modules/AddOCaml.cmake index 1d8094cc505..02bab684637 100644 --- a/gnu/llvm/cmake/modules/AddOCaml.cmake +++ b/gnu/llvm/cmake/modules/AddOCaml.cmake @@ -221,3 +221,4 @@ add_custom_target(ocaml_make_directory COMMAND "${CMAKE_COMMAND}" "-E" "make_directory" "${LLVM_LIBRARY_DIR}/ocaml/llvm") add_custom_target("ocaml_all") set_target_properties(ocaml_all PROPERTIES FOLDER "Misc") +set_target_properties(ocaml_make_directory PROPERTIES FOLDER "Misc") diff --git a/gnu/llvm/cmake/modules/AddSphinxTarget.cmake b/gnu/llvm/cmake/modules/AddSphinxTarget.cmake index 4540c5c36c8..22e3dcb776a 100644 --- a/gnu/llvm/cmake/modules/AddSphinxTarget.cmake +++ b/gnu/llvm/cmake/modules/AddSphinxTarget.cmake @@ -19,7 +19,7 @@ endif() # ``project`` should be the project name function (add_sphinx_target builder project) set(SPHINX_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/${builder}") - set(SPHINX_DOC_TREE_DIR "${CMAKE_CURRENT_BINARY_DIR}/_doctrees-${builder}") + set(SPHINX_DOC_TREE_DIR "${CMAKE_CURRENT_BINARY_DIR}/_doctrees-${project}-${builder}") set(SPHINX_TARGET_NAME docs-${project}-${builder}) if (SPHINX_WARNINGS_AS_ERRORS) diff --git a/gnu/llvm/cmake/modules/CMakeLists.txt b/gnu/llvm/cmake/modules/CMakeLists.txt index ac4b0b7c030..6074e835859 100644 --- a/gnu/llvm/cmake/modules/CMakeLists.txt +++ b/gnu/llvm/cmake/modules/CMakeLists.txt @@ -129,9 +129,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) if (NOT CMAKE_CONFIGURATION_TYPES) # Add a dummy target so this can be used with LLVM_DISTRIBUTION_COMPONENTS add_custom_target(cmake-exports) - add_custom_target(install-cmake-exports - COMMAND "${CMAKE_COMMAND}" - -DCMAKE_INSTALL_COMPONENT=cmake-exports - -P "${CMAKE_BINARY_DIR}/cmake_install.cmake") + add_llvm_install_targets(install-cmake-exports + COMPONENT cmake-exports) endif() endif() diff --git a/gnu/llvm/cmake/modules/CheckAtomic.cmake b/gnu/llvm/cmake/modules/CheckAtomic.cmake index dcf021b8fdd..9a4cdf12a62 100644 --- a/gnu/llvm/cmake/modules/CheckAtomic.cmake +++ b/gnu/llvm/cmake/modules/CheckAtomic.cmake @@ -1,13 +1,14 @@ # atomic builtins are required for threading support. INCLUDE(CheckCXXSourceCompiles) +INCLUDE(CheckLibraryExists) # Sometimes linking against libatomic is required for atomic ops, if # the platform doesn't support lock-free atomics. function(check_working_cxx_atomics varname) set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) - set(CMAKE_REQUIRED_FLAGS "-std=c++11") + set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -std=c++11") CHECK_CXX_SOURCE_COMPILES(" #include <atomic> std::atomic<int> x; @@ -80,7 +81,6 @@ endif() ## assumes C++11 <atomic> works. CHECK_CXX_SOURCE_COMPILES(" #ifdef _MSC_VER -#include <Intrin.h> /* Workaround for PR19898. */ #include <windows.h> #endif int main() { diff --git a/gnu/llvm/cmake/modules/CheckCompilerVersion.cmake b/gnu/llvm/cmake/modules/CheckCompilerVersion.cmake index 2e8f5445781..adf500ad53a 100644 --- a/gnu/llvm/cmake/modules/CheckCompilerVersion.cmake +++ b/gnu/llvm/cmake/modules/CheckCompilerVersion.cmake @@ -28,7 +28,7 @@ if(NOT DEFINED LLVM_COMPILER_CHECKED) # bug in libstdc++4.6 that is fixed in libstdc++4.7. set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) set(OLD_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}) - set(CMAKE_REQUIRED_FLAGS "-std=c++0x") + set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -std=c++0x") check_cxx_source_compiles(" #include <atomic> std::atomic<float> x(0.0f); diff --git a/gnu/llvm/cmake/modules/CheckLinkerFlag.cmake b/gnu/llvm/cmake/modules/CheckLinkerFlag.cmake index e96d35e7721..fe9d01a349c 100644 --- a/gnu/llvm/cmake/modules/CheckLinkerFlag.cmake +++ b/gnu/llvm/cmake/modules/CheckLinkerFlag.cmake @@ -1,8 +1,6 @@ include(CheckCXXCompilerFlag) function(check_linker_flag flag out_var) - set(OLD_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}") - set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${flag}") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${flag}") check_cxx_compiler_flag("" ${out_var}) - set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS}) endfunction() diff --git a/gnu/llvm/cmake/modules/CrossCompile.cmake b/gnu/llvm/cmake/modules/CrossCompile.cmake index b0726ebd4de..0ec76ead5c4 100644 --- a/gnu/llvm/cmake/modules/CrossCompile.cmake +++ b/gnu/llvm/cmake/modules/CrossCompile.cmake @@ -7,52 +7,56 @@ function(llvm_create_cross_target_internal target_name toolchain buildtype) endif(NOT DEFINED LLVM_${target_name}_BUILD) if (EXISTS ${LLVM_MAIN_SRC_DIR}/cmake/platforms/${toolchain}.cmake) - set(CROSS_TOOLCHAIN_FLAGS_${target_name} - -DCMAKE_TOOLCHAIN_FILE=\"${LLVM_MAIN_SRC_DIR}/cmake/platforms/${toolchain}.cmake\" - CACHE STRING "Toolchain file for ${target_name}") + set(CROSS_TOOLCHAIN_FLAGS_INIT + -DCMAKE_TOOLCHAIN_FILE=\"${LLVM_MAIN_SRC_DIR}/cmake/platforms/${toolchain}.cmake\") + else() + set(CROSS_TOOLCHAIN_FLAGS_INIT + -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} + -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} + ) + endif() + set(CROSS_TOOLCHAIN_FLAGS_${target_name} ${CROSS_TOOLCHAIN_FLAGS_INIT} + CACHE STRING "Toolchain configuration for ${target_name}") + + if (buildtype) + set(build_type_flags "-DCMAKE_BUILD_TYPE=${buildtype}") + endif() + if (LLVM_USE_LINKER AND NOT CMAKE_CROSSCOMPILING) + set(linker_flag "-DLLVM_USE_LINKER=${LLVM_USE_LINKER}") + endif() + if (LLVM_EXTERNAL_CLANG_SOURCE_DIR) + # Propagate LLVM_EXTERNAL_CLANG_SOURCE_DIR so that clang-tblgen can be built + set(external_clang_dir "-DLLVM_EXTERNAL_CLANG_SOURCE_DIR=${LLVM_EXTERNAL_CLANG_SOURCE_DIR}") endif() add_custom_command(OUTPUT ${LLVM_${target_name}_BUILD} COMMAND ${CMAKE_COMMAND} -E make_directory ${LLVM_${target_name}_BUILD} COMMENT "Creating ${LLVM_${target_name}_BUILD}...") + add_custom_target(CREATE_LLVM_${target_name} + DEPENDS ${LLVM_${target_name}_BUILD}) + + # Escape semicolons in the targets list so that cmake doesn't expand + # them to spaces. + string(REPLACE ";" "$<SEMICOLON>" targets_to_build_arg + "${LLVM_TARGETS_TO_BUILD}") + string(REPLACE ";" "$<SEMICOLON>" experimental_targets_to_build_arg + "${LLVM_EXPERIMENTAL_TARGETS_TO_BUILD}") + add_custom_command(OUTPUT ${LLVM_${target_name}_BUILD}/CMakeCache.txt COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" ${CROSS_TOOLCHAIN_FLAGS_${target_name}} ${CMAKE_SOURCE_DIR} -DLLVM_TARGET_IS_CROSSCOMPILE_HOST=TRUE + -DLLVM_TARGETS_TO_BUILD="${targets_to_build_arg}" + -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="${experimental_targets_to_build_arg}" + ${build_type_flags} ${linker_flag} ${external_clang_dir} WORKING_DIRECTORY ${LLVM_${target_name}_BUILD} - DEPENDS ${LLVM_${target_name}_BUILD} + DEPENDS CREATE_LLVM_${target_name} COMMENT "Configuring ${target_name} LLVM...") add_custom_target(CONFIGURE_LLVM_${target_name} DEPENDS ${LLVM_${target_name}_BUILD}/CMakeCache.txt) - set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES - ${LLVM_${target_name}_BUILD}) - - if(NOT IS_DIRECTORY ${LLVM_${target_name}_BUILD}) - - - message(STATUS "Configuring ${target_name} build...") - execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory - ${LLVM_${target_name}_BUILD} ) - - message(STATUS "Configuring ${target_name} targets...") - if (buildtype) - set(build_type_flags "-DCMAKE_BUILD_TYPE=${buildtype}") - endif() - if (LLVM_EXTERNAL_CLANG_SOURCE_DIR) - # Propagate LLVM_EXTERNAL_CLANG_SOURCE_DIR so that clang-tblgen can be built - set(external_clang_dir "-DLLVM_EXTERNAL_CLANG_SOURCE_DIR=${LLVM_EXTERNAL_CLANG_SOURCE_DIR}") - endif() - execute_process(COMMAND ${CMAKE_COMMAND} ${build_type_flags} - -G "${CMAKE_GENERATOR}" -DLLVM_TARGETS_TO_BUILD=${LLVM_TARGETS_TO_BUILD} - ${CROSS_TOOLCHAIN_FLAGS_${target_name}} ${CMAKE_SOURCE_DIR} - -DLLVM_TARGET_IS_CROSSCOMPILE_HOST=TRUE - ${external_clang_dir} - WORKING_DIRECTORY ${LLVM_${target_name}_BUILD} ) - endif(NOT IS_DIRECTORY ${LLVM_${target_name}_BUILD}) - endfunction() function(llvm_create_cross_target target_name sysroot) diff --git a/gnu/llvm/cmake/modules/GetHostTriple.cmake b/gnu/llvm/cmake/modules/GetHostTriple.cmake index 0cad1db4eff..019188a59cc 100644 --- a/gnu/llvm/cmake/modules/GetHostTriple.cmake +++ b/gnu/llvm/cmake/modules/GetHostTriple.cmake @@ -3,7 +3,7 @@ function( get_host_triple var ) if( MSVC ) - if( CMAKE_CL_64 ) + if( CMAKE_SIZEOF_VOID_P EQUAL 8 ) set( value "x86_64-pc-win32" ) else() set( value "i686-pc-win32" ) diff --git a/gnu/llvm/cmake/modules/GetSVN.cmake b/gnu/llvm/cmake/modules/GetSVN.cmake index d512bd292cf..f729395f6e4 100644 --- a/gnu/llvm/cmake/modules/GetSVN.cmake +++ b/gnu/llvm/cmake/modules/GetSVN.cmake @@ -1,17 +1,15 @@ # CMake project that writes Subversion revision information to a header. # # Input variables: -# FIRST_SOURCE_DIR - First source directory -# FIRST_NAME - The macro prefix for the first repository's info -# SECOND_SOURCE_DIR - Second source directory (opt) -# SECOND_NAME - The macro prefix for the second repository's info (opt) -# HEADER_FILE - The header file to write +# SOURCE_DIRS - A list of source directories. +# NAMES - A list of macro prefixes for each of the source directories. +# HEADER_FILE - The header file to write # -# The output header will contain macros FIRST_REPOSITORY and FIRST_REVISION, -# and SECOND_REPOSITORY and SECOND_REVISION if requested, where "FIRST" and -# "SECOND" are substituted with the names specified in the input variables. +# The output header will contain macros <NAME>_REPOSITORY and <NAME>_REVISION, +# where "<NAME>" and is substituted with the names specified in the input +# variables, for each of the SOURCE_DIRS given. -# Chop off cmake/modules/GetSVN.cmake +# Chop off cmake/modules/GetSVN.cmake get_filename_component(LLVM_DIR "${CMAKE_SCRIPT_MODE_FILE}" PATH) get_filename_component(LLVM_DIR "${LLVM_DIR}" PATH) get_filename_component(LLVM_DIR "${LLVM_DIR}" PATH) @@ -86,7 +84,7 @@ endmacro() function(get_source_info path revision repository) if (EXISTS "${path}/.svn") get_source_info_svn("${path}" revision repository) - elseif (EXISTS "${path}/.git/svn") + elseif (EXISTS "${path}/.git/svn/refs") get_source_info_git_svn("${path}" revision repository) elseif (EXISTS "${path}/.git") get_source_info_git("${path}" revision repository) @@ -103,9 +101,37 @@ function(append_info name path) "#define ${name}_REPOSITORY \"${repository}\"\n") endfunction() -append_info(${FIRST_NAME} "${FIRST_SOURCE_DIR}") -if(DEFINED SECOND_SOURCE_DIR) - append_info(${SECOND_NAME} "${SECOND_SOURCE_DIR}") +function(validate_inputs source_dirs names) + list(LENGTH source_dirs source_dirs_length) + list(LENGTH names names_length) + if (NOT source_dirs_length EQUAL names_length) + message(FATAL_ERROR + "GetSVN.cmake takes two arguments: a list of source directories, " + "and a list of names. Expected two lists must be of equal length, " + "but got ${source_dirs_length} source directories and " + "${names_length} names.") + endif() +endfunction() + +if (DEFINED SOURCE_DIRS AND DEFINED NAMES) + validate_inputs("${SOURCE_DIRS}" "${NAMES}") + + list(LENGTH SOURCE_DIRS source_dirs_length) + math(EXPR source_dirs_max_index ${source_dirs_length}-1) + foreach(index RANGE ${source_dirs_max_index}) + list(GET SOURCE_DIRS ${index} source_dir) + list(GET NAMES ${index} name) + append_info(${name} ${source_dir}) + endforeach() +endif() + +# Allow -DFIRST_SOURCE_DIR arguments until Clang migrates to the new +# -DSOURCE_DIRS argument. +if(DEFINED FIRST_SOURCE_DIR) + append_info(${FIRST_NAME} "${FIRST_SOURCE_DIR}") + if(DEFINED SECOND_SOURCE_DIR) + append_info(${SECOND_NAME} "${SECOND_SOURCE_DIR}") + endif() endif() # Copy the file only if it has changed. diff --git a/gnu/llvm/cmake/modules/HandleLLVMOptions.cmake b/gnu/llvm/cmake/modules/HandleLLVMOptions.cmake index 0676317acc6..f77600a4830 100644 --- a/gnu/llvm/cmake/modules/HandleLLVMOptions.cmake +++ b/gnu/llvm/cmake/modules/HandleLLVMOptions.cmake @@ -151,6 +151,14 @@ if(NOT (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" OR WIN32 OR CYGWIN OR set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,defs") endif() +# Pass -Wl,-z,nodelete. This makes sure our shared libraries are not unloaded +# by dlclose(). We need that since the CLI API relies on cross-references +# between global objects which became horribly broken when one of the libraries +# is unloaded. +if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,nodelete") +endif() + function(append value) foreach(variable ${ARGN}) @@ -194,10 +202,13 @@ if( LLVM_ENABLE_LLD ) endif() if( LLVM_USE_LINKER ) - check_cxx_compiler_flag("-fuse-ld=${LLVM_USE_LINKER}" CXX_SUPPORTS_CUSTOM_LINKER) + set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) + set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fuse-ld=${LLVM_USE_LINKER}") + check_cxx_source_compiles("int main() { return 0; }" CXX_SUPPORTS_CUSTOM_LINKER) if ( NOT CXX_SUPPORTS_CUSTOM_LINKER ) message(FATAL_ERROR "Host compiler does not support '-fuse-ld=${LLVM_USE_LINKER}'") endif() + set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS}) append("-fuse-ld=${LLVM_USE_LINKER}" CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS) endif() @@ -229,12 +240,21 @@ if( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 ) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32") set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -m32") + + # FIXME: CMAKE_SIZEOF_VOID_P is still 8 + add_definitions(-D_LARGEFILE_SOURCE) + add_definitions(-D_FILE_OFFSET_BITS=64) endif( LLVM_BUILD_32_BITS ) endif( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 ) # If building on a GNU specific 32-bit system, make sure off_t is 64 bits -# so that off_t can stored offset > 2GB -if( CMAKE_SIZEOF_VOID_P EQUAL 4 ) +# so that off_t can stored offset > 2GB. +# Android until version N (API 24) doesn't support it. +if (ANDROID AND (ANDROID_NATIVE_API_LEVEL LESS 24)) + set(LLVM_FORCE_SMALLFILE_FOR_ANDROID TRUE) +endif() +if( CMAKE_SIZEOF_VOID_P EQUAL 4 AND NOT LLVM_FORCE_SMALLFILE_FOR_ANDROID) + # FIXME: It isn't handled in LLVM_BUILD_32_BITS. add_definitions( -D_LARGEFILE_SOURCE ) add_definitions( -D_FILE_OFFSET_BITS=64 ) endif() @@ -303,13 +323,13 @@ if( MSVC ) # especially so std::equal(nullptr, nullptr, nullptr) will not assert. add_definitions("-D_DEBUG_POINTER_IMPL=") endif() - + include(ChooseMSVCCRT) if( MSVC11 ) add_definitions(-D_VARIADIC_MAX=10) endif() - + # Add definitions that make MSVC much less annoying. add_definitions( # For some reason MS wants to deprecate a bunch of standard functions... @@ -370,7 +390,7 @@ if( MSVC ) string(FIND "${upper_exe_flags} ${upper_module_flags} ${upper_shared_flags}" "/INCREMENTAL" linker_flag_idx) - + if (${linker_flag_idx} GREATER -1) message(WARNING "/Brepro not compatible with /INCREMENTAL linking - builds will be non-deterministic") else() @@ -381,7 +401,9 @@ if( MSVC ) elseif( LLVM_COMPILER_IS_GCC_COMPATIBLE ) append_if(LLVM_ENABLE_WERROR "-Werror" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) + append_if(LLVM_ENABLE_WERROR "-Wno-error" CMAKE_REQUIRED_FLAGS) add_flag_if_supported("-Werror=date-time" WERROR_DATE_TIME) + add_flag_if_supported("-Werror=unguarded-availability-new" WERROR_UNGUARDED_AVAILABILITY_NEW) if (LLVM_ENABLE_CXX1Y) check_cxx_compiler_flag("-std=c++1y" CXX_SUPPORTS_CXX1Y) append_if(CXX_SUPPORTS_CXX1Y "-std=c++1y" CMAKE_CXX_FLAGS) @@ -436,64 +458,66 @@ elseif( LLVM_COMPILER_IS_GCC_COMPATIBLE ) endif(LLVM_ENABLE_MODULES) endif( MSVC ) -if (MSVC AND NOT CLANG_CL) - set(msvc_warning_flags - # Disabled warnings. - -wd4141 # Suppress ''modifier' : used more than once' (because of __forceinline combined with inline) - -wd4146 # Suppress 'unary minus operator applied to unsigned type, result still unsigned' - -wd4180 # Suppress 'qualifier applied to function type has no meaning; ignored' - -wd4244 # Suppress ''argument' : conversion from 'type1' to 'type2', possible loss of data' - -wd4258 # Suppress ''var' : definition from the for loop is ignored; the definition from the enclosing scope is used' - -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' - -wd4355 # Suppress ''this' : used in base member initializer list' - -wd4456 # Suppress 'declaration of 'var' hides local variable' - -wd4457 # Suppress 'declaration of 'var' hides function parameter' - -wd4458 # Suppress 'declaration of 'var' hides class member' - -wd4459 # Suppress 'declaration of 'var' hides global declaration' - -wd4503 # Suppress ''identifier' : decorated name length exceeded, name was truncated' - -wd4624 # Suppress ''derived class' : destructor could not be generated because a base class destructor is inaccessible' - -wd4722 # Suppress 'function' : destructor never returns, potential memory leak - -wd4800 # Suppress ''type' : forcing value to bool 'true' or 'false' (performance warning)' - -wd4100 # Suppress 'unreferenced formal parameter' - -wd4127 # Suppress 'conditional expression is constant' - -wd4512 # Suppress 'assignment operator could not be generated' - -wd4505 # Suppress 'unreferenced local function has been removed' - -wd4610 # Suppress '<class> can never be instantiated' - -wd4510 # Suppress 'default constructor could not be generated' - -wd4702 # Suppress 'unreachable code' - -wd4245 # Suppress 'signed/unsigned mismatch' - -wd4706 # Suppress 'assignment within conditional expression' - -wd4310 # Suppress 'cast truncates constant value' - -wd4701 # Suppress 'potentially uninitialized local variable' - -wd4703 # Suppress 'potentially uninitialized local pointer variable' - -wd4389 # Suppress 'signed/unsigned mismatch' - -wd4611 # Suppress 'interaction between '_setjmp' and C++ object destruction is non-portable' - -wd4805 # Suppress 'unsafe mix of type <type> and type <type> in operation' - -wd4204 # Suppress 'nonstandard extension used : non-constant aggregate initializer' - -wd4577 # Suppress 'noexcept used with no exception handling mode specified; termination on exception is not guaranteed' - -wd4091 # Suppress 'typedef: ignored on left of '' when no variable is declared' - # C4592 is disabled because of false positives in Visual Studio 2015 - # Update 1. Re-evaluate the usefulness of this diagnostic with Update 2. - -wd4592 # Suppress ''var': symbol will be dynamically initialized (implementation limitation) - -wd4319 # Suppress ''operator' : zero extending 'type' to 'type' of greater size' - - # Ideally, we'd like this warning to be enabled, but MSVC 2013 doesn't - # support the 'aligned' attribute in the way that clang sources requires (for - # any code that uses the LLVM_ALIGNAS macro), so this is must be disabled to - # avoid unwanted alignment warnings. - # When we switch to requiring a version of MSVC that supports the 'alignas' - # specifier (MSVC 2015?) this warning can be re-enabled. - -wd4324 # Suppress 'structure was padded due to __declspec(align())' - - # Promoted warnings. - -w14062 # Promote 'enumerator in switch of enum is not handled' to level 1 warning. - - # Promoted warnings to errors. - -we4238 # Promote 'nonstandard extension used : class rvalue used as lvalue' to error. - ) +if (MSVC) + if (NOT CLANG_CL) + set(msvc_warning_flags + # Disabled warnings. + -wd4141 # Suppress ''modifier' : used more than once' (because of __forceinline combined with inline) + -wd4146 # Suppress 'unary minus operator applied to unsigned type, result still unsigned' + -wd4180 # Suppress 'qualifier applied to function type has no meaning; ignored' + -wd4244 # Suppress ''argument' : conversion from 'type1' to 'type2', possible loss of data' + -wd4258 # Suppress ''var' : definition from the for loop is ignored; the definition from the enclosing scope is used' + -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' + -wd4355 # Suppress ''this' : used in base member initializer list' + -wd4456 # Suppress 'declaration of 'var' hides local variable' + -wd4457 # Suppress 'declaration of 'var' hides function parameter' + -wd4458 # Suppress 'declaration of 'var' hides class member' + -wd4459 # Suppress 'declaration of 'var' hides global declaration' + -wd4503 # Suppress ''identifier' : decorated name length exceeded, name was truncated' + -wd4624 # Suppress ''derived class' : destructor could not be generated because a base class destructor is inaccessible' + -wd4722 # Suppress 'function' : destructor never returns, potential memory leak + -wd4800 # Suppress ''type' : forcing value to bool 'true' or 'false' (performance warning)' + -wd4100 # Suppress 'unreferenced formal parameter' + -wd4127 # Suppress 'conditional expression is constant' + -wd4512 # Suppress 'assignment operator could not be generated' + -wd4505 # Suppress 'unreferenced local function has been removed' + -wd4610 # Suppress '<class> can never be instantiated' + -wd4510 # Suppress 'default constructor could not be generated' + -wd4702 # Suppress 'unreachable code' + -wd4245 # Suppress 'signed/unsigned mismatch' + -wd4706 # Suppress 'assignment within conditional expression' + -wd4310 # Suppress 'cast truncates constant value' + -wd4701 # Suppress 'potentially uninitialized local variable' + -wd4703 # Suppress 'potentially uninitialized local pointer variable' + -wd4389 # Suppress 'signed/unsigned mismatch' + -wd4611 # Suppress 'interaction between '_setjmp' and C++ object destruction is non-portable' + -wd4805 # Suppress 'unsafe mix of type <type> and type <type> in operation' + -wd4204 # Suppress 'nonstandard extension used : non-constant aggregate initializer' + -wd4577 # Suppress 'noexcept used with no exception handling mode specified; termination on exception is not guaranteed' + -wd4091 # Suppress 'typedef: ignored on left of '' when no variable is declared' + # C4592 is disabled because of false positives in Visual Studio 2015 + # Update 1. Re-evaluate the usefulness of this diagnostic with Update 2. + -wd4592 # Suppress ''var': symbol will be dynamically initialized (implementation limitation) + -wd4319 # Suppress ''operator' : zero extending 'type' to 'type' of greater size' + + # Ideally, we'd like this warning to be enabled, but MSVC 2013 doesn't + # support the 'aligned' attribute in the way that clang sources requires (for + # any code that uses the LLVM_ALIGNAS macro), so this is must be disabled to + # avoid unwanted alignment warnings. + # When we switch to requiring a version of MSVC that supports the 'alignas' + # specifier (MSVC 2015?) this warning can be re-enabled. + -wd4324 # Suppress 'structure was padded due to __declspec(align())' + + # Promoted warnings. + -w14062 # Promote 'enumerator in switch of enum is not handled' to level 1 warning. + + # Promoted warnings to errors. + -we4238 # Promote 'nonstandard extension used : class rvalue used as lvalue' to error. + ) + endif(NOT CLANG_CL) # Enable warnings if (LLVM_ENABLE_WARNINGS) @@ -516,10 +540,17 @@ if (MSVC AND NOT CLANG_CL) foreach(flag ${msvc_warning_flags}) append("${flag}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) endforeach(flag) -endif (MSVC AND NOT CLANG_CL) +endif (MSVC) if (LLVM_ENABLE_WARNINGS AND (LLVM_COMPILER_IS_GCC_COMPATIBLE OR CLANG_CL)) - append("-Wall -W -Wno-unused-parameter -Wwrite-strings" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) + + # Don't add -Wall for clang-cl, because it maps -Wall to -Weverything for + # MSVC compatibility. /W4 is added above instead. + if (NOT CLANG_CL) + append("-Wall" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) + endif() + + append("-W -Wno-unused-parameter -Wwrite-strings" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) append("-Wcast-qual" CMAKE_CXX_FLAGS) # Turn off missing field initializer warnings for gcc to avoid noise from @@ -663,7 +694,7 @@ if(LLVM_USE_SANITIZER) FSANITIZE_USE_AFTER_SCOPE_FLAG) endif() if (LLVM_USE_SANITIZE_COVERAGE) - append("-fsanitize-coverage=trace-pc-guard,indirect-calls,trace-cmp" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) + append("-fsanitize=fuzzer-no-link" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) endif() endif() @@ -724,15 +755,30 @@ if(LLVM_ENABLE_EH AND NOT LLVM_ENABLE_RTTI) message(FATAL_ERROR "Exception handling requires RTTI. You must set LLVM_ENABLE_RTTI to ON") endif() -option(LLVM_BUILD_INSTRUMENTED "Build LLVM and tools with PGO instrumentation (experimental)" Off) +option(LLVM_ENABLE_IR_PGO "Build LLVM and tools with IR PGO instrumentation (deprecated)" Off) +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) -append_if(LLVM_BUILD_INSTRUMENTED "-fprofile-instr-generate='${LLVM_PROFILE_FILE_PATTERN}'" - CMAKE_CXX_FLAGS - CMAKE_C_FLAGS - CMAKE_EXE_LINKER_FLAGS - CMAKE_SHARED_LINKER_FLAGS) +string(TOUPPER "${LLVM_BUILD_INSTRUMENTED}" uppercase_LLVM_BUILD_INSTRUMENTED) + +if (LLVM_BUILD_INSTRUMENTED) + if (LLVM_ENABLE_IR_PGO OR uppercase_LLVM_BUILD_INSTRUMENTED STREQUAL "IR") + append("-fprofile-generate='${LLVM_PROFILE_DATA_DIR}'" + CMAKE_CXX_FLAGS + CMAKE_C_FLAGS + CMAKE_EXE_LINKER_FLAGS + CMAKE_SHARED_LINKER_FLAGS) + else() + append("-fprofile-instr-generate='${LLVM_PROFILE_FILE_PATTERN}'" + CMAKE_CXX_FLAGS + CMAKE_C_FLAGS + CMAKE_EXE_LINKER_FLAGS + CMAKE_SHARED_LINKER_FLAGS) + endif() +endif() -option(LLVM_BUILD_INSTRUMENTED_COVERAGE "Build LLVM and tools with Code Coverage instrumentation (experimental)" Off) +option(LLVM_BUILD_INSTRUMENTED_COVERAGE "Build LLVM and tools with Code Coverage instrumentation" Off) mark_as_advanced(LLVM_BUILD_INSTRUMENTED_COVERAGE) append_if(LLVM_BUILD_INSTRUMENTED_COVERAGE "-fprofile-instr-generate='${LLVM_PROFILE_FILE_PATTERN}' -fcoverage-mapping" CMAKE_CXX_FLAGS @@ -740,6 +786,10 @@ append_if(LLVM_BUILD_INSTRUMENTED_COVERAGE "-fprofile-instr-generate='${LLVM_PRO CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS) +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) message(FATAL_ERROR "When compiling for Windows, LLVM_ENABLE_LTO requires using lld as the linker (point CMAKE_LINKER at lld-link.exe)") endif() @@ -790,7 +840,7 @@ endif() # Plugin support # FIXME: Make this configurable. if(WIN32 OR CYGWIN) - if(BUILD_SHARED_LIBS) + if(BUILD_SHARED_LIBS OR LLVM_BUILD_LLVM_DYLIB) set(LLVM_ENABLE_PLUGINS ON) else() set(LLVM_ENABLE_PLUGINS OFF) diff --git a/gnu/llvm/cmake/modules/LLVM-Config.cmake b/gnu/llvm/cmake/modules/LLVM-Config.cmake index 52330151065..10fd5260927 100644 --- a/gnu/llvm/cmake/modules/LLVM-Config.cmake +++ b/gnu/llvm/cmake/modules/LLVM-Config.cmake @@ -87,7 +87,7 @@ macro(llvm_config executable) endif() endif() - target_link_libraries(${executable} LLVM) + target_link_libraries(${executable} PRIVATE LLVM) endif() explicit_llvm_config(${executable} ${link_components}) @@ -99,9 +99,9 @@ function(explicit_llvm_config executable) llvm_map_components_to_libnames(LIBRARIES ${link_components}) get_target_property(t ${executable} TYPE) - if("x${t}" STREQUAL "xSTATIC_LIBRARY") + if(t STREQUAL "STATIC_LIBRARY") target_link_libraries(${executable} INTERFACE ${LIBRARIES}) - elseif("x${t}" STREQUAL "xSHARED_LIBRARY" OR "x${t}" STREQUAL "xMODULE_LIBRARY") + elseif(t STREQUAL "EXECUTABLE" OR t STREQUAL "SHARED_LIBRARY" OR t STREQUAL "MODULE_LIBRARY") target_link_libraries(${executable} PRIVATE ${LIBRARIES}) else() # Use plain form for legacy user. @@ -175,18 +175,15 @@ function(llvm_map_components_to_libnames out_libs) message(FATAL_ERROR "Target ${c} is not in the set of libraries.") endif() endif() - if( TARGET LLVM${c}AsmPrinter ) - list(APPEND expanded_components "LLVM${c}AsmPrinter") - endif() if( TARGET LLVM${c}AsmParser ) list(APPEND expanded_components "LLVM${c}AsmParser") endif() + if( TARGET LLVM${c}AsmPrinter ) + list(APPEND expanded_components "LLVM${c}AsmPrinter") + endif() if( TARGET LLVM${c}Desc ) list(APPEND expanded_components "LLVM${c}Desc") endif() - if( TARGET LLVM${c}Info ) - list(APPEND expanded_components "LLVM${c}Info") - endif() if( TARGET LLVM${c}Disassembler ) list(APPEND expanded_components "LLVM${c}Disassembler") endif() diff --git a/gnu/llvm/cmake/modules/LLVMConfig.cmake.in b/gnu/llvm/cmake/modules/LLVMConfig.cmake.in index 7a8eb367472..fe4df527849 100644 --- a/gnu/llvm/cmake/modules/LLVMConfig.cmake.in +++ b/gnu/llvm/cmake/modules/LLVMConfig.cmake.in @@ -37,6 +37,8 @@ set(LLVM_ENABLE_THREADS @LLVM_ENABLE_THREADS@) set(LLVM_ENABLE_ZLIB @LLVM_ENABLE_ZLIB@) +set(LLVM_LIBXML2_ENABLED @LLVM_LIBXML2_ENABLED@) + set(LLVM_ENABLE_DIA_SDK @LLVM_ENABLE_DIA_SDK@) set(LLVM_NATIVE_ARCH @LLVM_NATIVE_ARCH@) @@ -72,6 +74,7 @@ set(LLVM_CMAKE_DIR "@LLVM_CONFIG_CMAKE_DIR@") set(LLVM_BINARY_DIR "@LLVM_CONFIG_BINARY_DIR@") set(LLVM_TOOLS_BINARY_DIR "@LLVM_CONFIG_TOOLS_BINARY_DIR@") set(LLVM_TOOLS_INSTALL_DIR "@LLVM_TOOLS_INSTALL_DIR@") +set(LLVM_HAVE_OPT_VIEWER_MODULES @LLVM_HAVE_OPT_VIEWER_MODULES@) if(NOT TARGET LLVMSupport) set(LLVM_EXPORTED_TARGETS "@LLVM_CONFIG_EXPORTS@") @@ -79,5 +82,12 @@ if(NOT TARGET LLVMSupport) @llvm_config_include_buildtree_only_exports@ endif() +# By creating intrinsics_gen here, subprojects that depend on LLVM's +# tablegen-generated headers can always depend on this target whether building +# in-tree with LLVM or not. +if(NOT TARGET intrinsics_gen) + add_custom_target(intrinsics_gen) +endif() + set_property(GLOBAL PROPERTY LLVM_TARGETS_CONFIGURED On) include(${LLVM_CMAKE_DIR}/LLVM-Config.cmake) diff --git a/gnu/llvm/cmake/modules/LLVMExternalProjectUtils.cmake b/gnu/llvm/cmake/modules/LLVMExternalProjectUtils.cmake index c851eb8dbf0..b84ebbb5387 100644 --- a/gnu/llvm/cmake/modules/LLVMExternalProjectUtils.cmake +++ b/gnu/llvm/cmake/modules/LLVMExternalProjectUtils.cmake @@ -95,7 +95,7 @@ function(llvm_ExternalProject_Add name source_dir) foreach(prefix ${ARG_PASSTHROUGH_PREFIXES}) foreach(variableName ${variableNames}) if(variableName MATCHES "^${prefix}") - string(REPLACE ";" "\;" value "${${variableName}}") + string(REPLACE ";" "|" value "${${variableName}}") list(APPEND PASSTHROUGH_VARIABLES -D${variableName}=${value}) endif() @@ -132,6 +132,10 @@ function(llvm_ExternalProject_Add name source_dir) set(exclude EXCLUDE_FROM_ALL 1) endif() + if(CMAKE_SYSROOT) + set(sysroot_arg -DCMAKE_SYSROOT=${CMAKE_SYSROOT}) + endif() + ExternalProject_Add(${name} DEPENDS ${ARG_DEPENDS} llvm-config ${name}-clobber @@ -143,12 +147,16 @@ function(llvm_ExternalProject_Add name source_dir) CMAKE_ARGS ${${nameCanon}_CMAKE_ARGS} ${compiler_args} -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} + ${sysroot_arg} -DLLVM_BINARY_DIR=${PROJECT_BINARY_DIR} -DLLVM_CONFIG_PATH=$<TARGET_FILE:llvm-config> -DLLVM_ENABLE_WERROR=${LLVM_ENABLE_WERROR} + -DLLVM_HOST_TRIPLE=${LLVM_HOST_TRIPLE} + -DLLVM_HAVE_LINK_VERSION_SCRIPT=${LLVM_HAVE_LINK_VERSION_SCRIPT} -DPACKAGE_VERSION=${PACKAGE_VERSION} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM} + -DCMAKE_EXPORT_COMPILE_COMMANDS=1 ${ARG_CMAKE_ARGS} ${PASSTHROUGH_VARIABLES} INSTALL_COMMAND "" @@ -157,6 +165,7 @@ function(llvm_ExternalProject_Add name source_dir) USES_TERMINAL_CONFIGURE 1 USES_TERMINAL_BUILD 1 USES_TERMINAL_INSTALL 1 + LIST_SEPARATOR | ) if(ARG_USE_TOOLCHAIN) @@ -185,12 +194,9 @@ function(llvm_ExternalProject_Add name source_dir) install(CODE "execute_process\(COMMAND \${CMAKE_COMMAND} -DCMAKE_INSTALL_PREFIX=\${CMAKE_INSTALL_PREFIX} -P ${BINARY_DIR}/cmake_install.cmake \)" COMPONENT ${name}) - add_custom_target(install-${name} - DEPENDS ${name} - COMMAND "${CMAKE_COMMAND}" - -DCMAKE_INSTALL_COMPONENT=${name} - -P "${CMAKE_BINARY_DIR}/cmake_install.cmake" - USES_TERMINAL) + add_llvm_install_targets(install-${name} + DEPENDS ${name} + COMPONENT ${name}) endif() # Add top-level targets diff --git a/gnu/llvm/cmake/modules/LLVMProcessSources.cmake b/gnu/llvm/cmake/modules/LLVMProcessSources.cmake index ae1921b5bc0..3b4838daed5 100644 --- a/gnu/llvm/cmake/modules/LLVMProcessSources.cmake +++ b/gnu/llvm/cmake/modules/LLVMProcessSources.cmake @@ -68,17 +68,29 @@ endfunction(llvm_process_sources) function(llvm_check_source_file_list) - set(listed ${ARGN}) - file(GLOB globbed *.c *.cpp) + cmake_parse_arguments(ARG "" "SOURCE_DIR" "" ${ARGN}) + set(listed ${ARG_UNPARSED_ARGUMENTS}) + if(ARG_SOURCE_DIR) + file(GLOB globbed + RELATIVE "${CMAKE_CURRENT_LIST_DIR}" + "${ARG_SOURCE_DIR}/*.c" "${ARG_SOURCE_DIR}/*.cpp") + else() + file(GLOB globbed *.c *.cpp) + endif() foreach(g ${globbed}) get_filename_component(fn ${g} NAME) + if(ARG_SOURCE_DIR) + set(entry "${g}") + else() + set(entry "${fn}") + endif() # Don't reject hidden files. Some editors create backups in the # same directory as the file. if (NOT "${fn}" MATCHES "^\\.") - list(FIND LLVM_OPTIONAL_SOURCES ${fn} idx) + list(FIND LLVM_OPTIONAL_SOURCES ${entry} idx) if( idx LESS 0 ) - list(FIND listed ${fn} idx) + list(FIND listed ${entry} idx) if( idx LESS 0 ) message(SEND_ERROR "Found unknown source file ${g} Please update ${CMAKE_CURRENT_LIST_FILE}\n") diff --git a/gnu/llvm/cmake/modules/TableGen.cmake b/gnu/llvm/cmake/modules/TableGen.cmake index 8c3e2d7d700..d1afcb42f9d 100644 --- a/gnu/llvm/cmake/modules/TableGen.cmake +++ b/gnu/llvm/cmake/modules/TableGen.cmake @@ -52,6 +52,13 @@ function(tablegen project ofn) list(APPEND LLVM_TABLEGEN_FLAGS "-instrument-coverage") endif() endif() + if (LLVM_ENABLE_GISEL_COV) + list(FIND ARGN "-gen-global-isel" idx) + if( NOT idx EQUAL -1 ) + list(APPEND LLVM_TABLEGEN_FLAGS "-instrument-gisel-coverage") + list(APPEND LLVM_TABLEGEN_FLAGS "-gisel-coverage-file=${LLVM_GISEL_COV_PREFIX}all") + endif() + endif() # We need both _TABLEGEN_TARGET and _TABLEGEN_EXE in the DEPENDS list # (both the target and the file) to have .inc files rebuilt on @@ -110,19 +117,6 @@ function(add_public_tablegen_target target) set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} ${target} PARENT_SCOPE) endfunction() -if(LLVM_USE_HOST_TOOLS) - llvm_ExternalProject_BuildCmd(tblgen_build_cmd LLVMSupport - ${LLVM_NATIVE_BUILD} - CONFIGURATION Release) - add_custom_command(OUTPUT LIB_LLVMTABLEGEN - COMMAND ${tblgen_build_cmd} - DEPENDS CONFIGURE_LLVM_NATIVE - WORKING_DIRECTORY ${LLVM_NATIVE_BUILD} - COMMENT "Building libLLVMTableGen for native TableGen..." - USES_TERMINAL) - add_custom_target(NATIVE_LIB_LLVMTABLEGEN DEPENDS LIB_LLVMTABLEGEN) -endif(LLVM_USE_HOST_TOOLS) - macro(add_tablegen target project) set(${target}_OLD_LLVM_LINK_COMPONENTS ${LLVM_LINK_COMPONENTS}) set(LLVM_LINK_COMPONENTS ${LLVM_LINK_COMPONENTS} TableGen) @@ -166,7 +160,7 @@ macro(add_tablegen target project) CONFIGURATION Release) add_custom_command(OUTPUT ${${project}_TABLEGEN_EXE} COMMAND ${tblgen_build_cmd} - DEPENDS ${target} NATIVE_LIB_LLVMTABLEGEN + DEPENDS CONFIGURE_LLVM_NATIVE ${target} WORKING_DIRECTORY ${LLVM_NATIVE_BUILD} COMMENT "Building native TableGen..." USES_TERMINAL) diff --git a/gnu/llvm/cmake/platforms/ClangClCMakeCompileRules.cmake b/gnu/llvm/cmake/platforms/ClangClCMakeCompileRules.cmake new file mode 100644 index 00000000000..a3bcf1c24a9 --- /dev/null +++ b/gnu/llvm/cmake/platforms/ClangClCMakeCompileRules.cmake @@ -0,0 +1,9 @@ +# macOS paths usually start with /Users/*. Unfortunately, clang-cl interprets +# paths starting with /U as macro undefines, so we need to put a -- before the +# input file path to force it to be treated as a path. CMake's compilation rules +# should be tweaked accordingly, but until that's done, and to support older +# CMake versions, overriding compilation rules works well enough. This file will +# be included by cmake after the default compilation rules have already been set +# up, so we can just modify them instead of duplicating them entirely. +string(REPLACE "-c <SOURCE>" "-c -- <SOURCE>" CMAKE_C_COMPILE_OBJECT "${CMAKE_C_COMPILE_OBJECT}") +string(REPLACE "-c <SOURCE>" "-c -- <SOURCE>" CMAKE_CXX_COMPILE_OBJECT "${CMAKE_CXX_COMPILE_OBJECT}") diff --git a/gnu/llvm/cmake/platforms/WinMsvc.cmake b/gnu/llvm/cmake/platforms/WinMsvc.cmake new file mode 100644 index 00000000000..a736a457872 --- /dev/null +++ b/gnu/llvm/cmake/platforms/WinMsvc.cmake @@ -0,0 +1,304 @@ +# Cross toolchain configuration for using clang-cl on non-Windows hosts to +# target MSVC. +# +# Usage: +# cmake -G Ninja +# -DCMAKE_TOOLCHAIN_FILE=/path/to/this/file +# -DHOST_ARCH=[aarch64|arm64|armv7|arm|i686|x86|x86_64|x64] +# -DLLVM_NATIVE_TOOLCHAIN=/path/to/llvm/installation +# -DMSVC_BASE=/path/to/MSVC/system/libraries/and/includes +# -DWINSDK_BASE=/path/to/windows-sdk +# -DWINSDK_VER=windows sdk version folder name +# +# HOST_ARCH: +# The architecture to build for. +# +# LLVM_NATIVE_TOOLCHAIN: +# *Absolute path* to a folder containing the toolchain which will be used to +# build. At a minimum, this folder should have a bin directory with a +# copy of clang-cl, clang, clang++, and lld-link, as well as a lib directory +# containing clang's system resource directory. +# +# MSVC_BASE: +# *Absolute path* to the folder containing MSVC headers and system libraries. +# The layout of the folder matches that which is intalled by MSVC 2017 on +# Windows, and should look like this: +# +# ${MSVC_BASE} +# include +# vector +# stdint.h +# etc... +# lib +# x64 +# libcmt.lib +# msvcrt.lib +# etc... +# x86 +# libcmt.lib +# msvcrt.lib +# etc... +# +# For versions of MSVC < 2017, or where you have a hermetic toolchain in a +# custom format, you must use symlinks or restructure it to look like the above. +# +# WINSDK_BASE: +# Together with WINSDK_VER, determines the location of Windows SDK headers +# and libraries. +# +# WINSDK_VER: +# Together with WINSDK_BASE, determines the locations of Windows SDK headers +# and libraries. +# +# WINSDK_BASE and WINSDK_VER work together to define a folder layout that matches +# that of the Windows SDK installation on a standard Windows machine. It should +# match the layout described below. +# +# Note that if you install Windows SDK to a windows machine and simply copy the +# files, it will already be in the correct layout. +# +# ${WINSDK_BASE} +# Include +# ${WINSDK_VER} +# shared +# ucrt +# um +# windows.h +# etc... +# Lib +# ${WINSDK_VER} +# ucrt +# x64 +# x86 +# ucrt.lib +# etc... +# um +# x64 +# x86 +# kernel32.lib +# etc +# +# IMPORTANT: In order for this to work, you will need a valid copy of the Windows +# SDK and C++ STL headers and libraries on your host. Additionally, since the +# Windows libraries and headers are not case-correct, this toolchain file sets +# up a VFS overlay for the SDK headers and case-correcting symlinks for the +# libraries when running on a case-sensitive filesystem. + + +# When configuring CMake with a toolchain file against a top-level CMakeLists.txt, +# it will actually run CMake many times, once for each small test program used to +# determine what features a compiler supports. Unfortunately, none of these +# invocations share a CMakeCache.txt with the top-level invocation, meaning they +# won't see the value of any arguments the user passed via -D. Since these are +# necessary to properly configure MSVC in both the top-level configuration as well as +# all feature-test invocations, we set environment variables with the values so that +# these environments get inherited by child invocations. +function(init_user_prop prop) + if(${prop}) + set(ENV{_${prop}} "${${prop}}") + else() + set(${prop} "$ENV{_${prop}}" PARENT_SCOPE) + endif() +endfunction() + +function(generate_winsdk_vfs_overlay winsdk_include_dir output_path) + set(include_dirs) + file(GLOB_RECURSE entries LIST_DIRECTORIES true "${winsdk_include_dir}/*") + foreach(entry ${entries}) + if(IS_DIRECTORY "${entry}") + list(APPEND include_dirs "${entry}") + endif() + endforeach() + + file(WRITE "${output_path}" "version: 0\n") + file(APPEND "${output_path}" "case-sensitive: false\n") + file(APPEND "${output_path}" "roots:\n") + + foreach(dir ${include_dirs}) + file(GLOB headers RELATIVE "${dir}" "${dir}/*.h") + if(NOT headers) + continue() + endif() + + file(APPEND "${output_path}" " - name: \"${dir}\"\n") + file(APPEND "${output_path}" " type: directory\n") + file(APPEND "${output_path}" " contents:\n") + + foreach(header ${headers}) + file(APPEND "${output_path}" " - name: \"${header}\"\n") + file(APPEND "${output_path}" " type: file\n") + file(APPEND "${output_path}" " external-contents: \"${dir}/${header}\"\n") + endforeach() + endforeach() +endfunction() + +function(generate_winsdk_lib_symlinks winsdk_um_lib_dir output_dir) + execute_process(COMMAND "${CMAKE_COMMAND}" -E make_directory "${output_dir}") + file(GLOB libraries RELATIVE "${winsdk_um_lib_dir}" "${winsdk_um_lib_dir}/*") + foreach(library ${libraries}) + string(TOLOWER "${library}" symlink_name) + execute_process(COMMAND "${CMAKE_COMMAND}" + -E create_symlink + "${winsdk_um_lib_dir}/${library}" + "${output_dir}/${symlink_name}") + endforeach() +endfunction() + +set(CMAKE_SYSTEM_NAME Windows) +set(CMAKE_SYSTEM_VERSION 10.0) +set(CMAKE_SYSTEM_PROCESSOR AMD64) + +init_user_prop(HOST_ARCH) +init_user_prop(LLVM_NATIVE_TOOLCHAIN) +init_user_prop(MSVC_BASE) +init_user_prop(WINSDK_BASE) +init_user_prop(WINSDK_VER) + +if(NOT HOST_ARCH) + set(HOST_ARCH x86_64) +endif() +if(HOST_ARCH STREQUAL "aarch64" OR HOST_ARCH STREQUAL "arm64") + set(TRIPLE_ARCH "aarch64") + set(WINSDK_ARCH "arm64") +elseif(HOST_ARCH STREQUAL "armv7" OR HOST_ARCH STREQUAL "arm") + set(TRIPLE_ARCH "armv7") + set(WINSDK_ARCH "arm") +elseif(HOST_ARCH STREQUAL "i686" OR HOST_ARCH STREQUAL "x86") + set(TRIPLE_ARCH "i686") + set(WINSDK_ARCH "x86") +elseif(HOST_ARCH STREQUAL "x86_64" OR HOST_ARCH STREQUAL "x64") + set(TRIPLE_ARCH "x86_64") + set(WINSDK_ARCH "x64") +else() + message(SEND_ERROR "Unknown host architecture ${HOST_ARCH}. Must be aarch64 (or arm64), armv7 (or arm), i686 (or x86), or x86_64 (or x64).") +endif() + +set(MSVC_INCLUDE "${MSVC_BASE}/include") +set(MSVC_LIB "${MSVC_BASE}/lib") +set(WINSDK_INCLUDE "${WINSDK_BASE}/Include/${WINSDK_VER}") +set(WINSDK_LIB "${WINSDK_BASE}/Lib/${WINSDK_VER}") + +# Do some sanity checking to make sure we can find a native toolchain and +# that the Windows SDK / MSVC STL directories look kosher. +if(NOT EXISTS "${LLVM_NATIVE_TOOLCHAIN}/bin/clang-cl" OR + NOT EXISTS "${LLVM_NATIVE_TOOLCHAIN}/bin/lld-link") + message(SEND_ERROR + "LLVM_NATIVE_TOOLCHAIN folder '${LLVM_NATIVE_TOOLCHAIN}' does not " + "point to a valid directory containing bin/clang-cl and bin/lld-link " + "binaries") +endif() + +if(NOT EXISTS "${MSVC_BASE}" OR + NOT EXISTS "${MSVC_INCLUDE}" OR + NOT EXISTS "${MSVC_LIB}") + message(SEND_ERROR + "CMake variable MSVC_BASE must point to a folder containing MSVC " + "system headers and libraries") +endif() + +if(NOT EXISTS "${WINSDK_BASE}" OR + NOT EXISTS "${WINSDK_INCLUDE}" OR + NOT EXISTS "${WINSDK_LIB}") + message(SEND_ERROR + "CMake variable WINSDK_BASE and WINSDK_VER must resolve to a valid " + "Windows SDK installation") +endif() + +if(NOT EXISTS "${WINSDK_INCLUDE}/um/Windows.h") + message(SEND_ERROR "Cannot find Windows.h") +endif() +if(NOT EXISTS "${WINSDK_INCLUDE}/um/WINDOWS.H") + set(case_sensitive_filesystem TRUE) +endif() + +set(CMAKE_C_COMPILER "${LLVM_NATIVE_TOOLCHAIN}/bin/clang-cl" CACHE FILEPATH "") +set(CMAKE_CXX_COMPILER "${LLVM_NATIVE_TOOLCHAIN}/bin/clang-cl" CACHE FILEPATH "") +set(CMAKE_LINKER "${LLVM_NATIVE_TOOLCHAIN}/bin/lld-link" CACHE FILEPATH "") + +# Even though we're cross-compiling, we need some native tools (e.g. llvm-tblgen), and those +# native tools have to be built before we can start doing the cross-build. LLVM supports +# a CROSS_TOOLCHAIN_FLAGS_NATIVE argument which consists of a list of flags to pass to CMake +# when configuring the NATIVE portion of the cross-build. By default we construct this so +# that it points to the tools in the same location as the native clang-cl that we're using. +list(APPEND _CTF_NATIVE_DEFAULT "-DCMAKE_ASM_COMPILER=${LLVM_NATIVE_TOOLCHAIN}/bin/clang") +list(APPEND _CTF_NATIVE_DEFAULT "-DCMAKE_C_COMPILER=${LLVM_NATIVE_TOOLCHAIN}/bin/clang") +list(APPEND _CTF_NATIVE_DEFAULT "-DCMAKE_CXX_COMPILER=${LLVM_NATIVE_TOOLCHAIN}/bin/clang++") + +set(CROSS_TOOLCHAIN_FLAGS_NATIVE "${_CTF_NATIVE_DEFAULT}" CACHE STRING "") + +set(COMPILE_FLAGS + -D_CRT_SECURE_NO_WARNINGS + --target=${TRIPLE_ARCH}-windows-msvc + -fms-compatibility-version=19.11 + -imsvc "${MSVC_INCLUDE}" + -imsvc "${WINSDK_INCLUDE}/ucrt" + -imsvc "${WINSDK_INCLUDE}/shared" + -imsvc "${WINSDK_INCLUDE}/um" + -imsvc "${WINSDK_INCLUDE}/winrt") + +if(case_sensitive_filesystem) + # Ensure all sub-configures use the top-level VFS overlay instead of generating their own. + init_user_prop(winsdk_vfs_overlay_path) + if(NOT winsdk_vfs_overlay_path) + set(winsdk_vfs_overlay_path "${CMAKE_BINARY_DIR}/winsdk_vfs_overlay.yaml") + generate_winsdk_vfs_overlay("${WINSDK_BASE}/Include/${WINSDK_VER}" "${winsdk_vfs_overlay_path}") + init_user_prop(winsdk_vfs_overlay_path) + endif() + list(APPEND COMPILE_FLAGS + -Xclang -ivfsoverlay -Xclang "${winsdk_vfs_overlay_path}") +endif() + +string(REPLACE ";" " " COMPILE_FLAGS "${COMPILE_FLAGS}") + +# We need to preserve any flags that were passed in by the user. However, we +# can't append to CMAKE_C_FLAGS and friends directly, because toolchain files +# will be re-invoked on each reconfigure and therefore need to be idempotent. +# The assignments to the _INITIAL cache variables don't use FORCE, so they'll +# only be populated on the initial configure, and their values won't change +# afterward. +set(_CMAKE_C_FLAGS_INITIAL "${CMAKE_C_FLAGS}" CACHE STRING "") +set(CMAKE_C_FLAGS "${_CMAKE_C_FLAGS_INITIAL} ${COMPILE_FLAGS}" CACHE STRING "" FORCE) + +set(_CMAKE_CXX_FLAGS_INITIAL "${CMAKE_CXX_FLAGS}" CACHE STRING "") +set(CMAKE_CXX_FLAGS "${_CMAKE_CXX_FLAGS_INITIAL} ${COMPILE_FLAGS}" CACHE STRING "" FORCE) + +set(LINK_FLAGS + # Prevent CMake from attempting to invoke mt.exe. It only recognizes the slashed form and not the dashed form. + /manifest:no + + -libpath:"${MSVC_LIB}/${WINSDK_ARCH}" + -libpath:"${WINSDK_LIB}/ucrt/${WINSDK_ARCH}" + -libpath:"${WINSDK_LIB}/um/${WINSDK_ARCH}") + +if(case_sensitive_filesystem) + # Ensure all sub-configures use the top-level symlinks dir instead of generating their own. + init_user_prop(winsdk_lib_symlinks_dir) + if(NOT winsdk_lib_symlinks_dir) + set(winsdk_lib_symlinks_dir "${CMAKE_BINARY_DIR}/winsdk_lib_symlinks") + generate_winsdk_lib_symlinks("${WINSDK_BASE}/Lib/${WINSDK_VER}/um/${WINSDK_ARCH}" "${winsdk_lib_symlinks_dir}") + init_user_prop(winsdk_lib_symlinks_dir) + endif() + list(APPEND LINK_FLAGS + -libpath:"${winsdk_lib_symlinks_dir}") +endif() + +string(REPLACE ";" " " LINK_FLAGS "${LINK_FLAGS}") + +# See explanation for compiler flags above for the _INITIAL variables. +set(_CMAKE_EXE_LINKER_FLAGS_INITIAL "${CMAKE_EXE_LINKER_FLAGS}" CACHE STRING "") +set(CMAKE_EXE_LINKER_FLAGS "${_CMAKE_EXE_LINKER_FLAGS_INITIAL} ${LINK_FLAGS}" CACHE STRING "" FORCE) + +set(_CMAKE_MODULE_LINKER_FLAGS_INITIAL "${CMAKE_MODULE_LINKER_FLAGS}" CACHE STRING "") +set(CMAKE_MODULE_LINKER_FLAGS "${_CMAKE_MODULE_LINKER_FLAGS_INITIAL} ${LINK_FLAGS}" CACHE STRING "" FORCE) + +set(_CMAKE_SHARED_LINKER_FLAGS_INITIAL "${CMAKE_SHARED_LINKER_FLAGS}" CACHE STRING "") +set(CMAKE_SHARED_LINKER_FLAGS "${_CMAKE_SHARED_LINKER_FLAGS_INITIAL} ${LINK_FLAGS}" CACHE STRING "" FORCE) + +# CMake populates these with a bunch of unnecessary libraries, which requires +# extra case-correcting symlinks and what not. Instead, let projects explicitly +# control which libraries they require. +set(CMAKE_C_STANDARD_LIBRARIES "" CACHE STRING "" FORCE) +set(CMAKE_CXX_STANDARD_LIBRARIES "" CACHE STRING "" FORCE) + +# Allow clang-cl to work with macOS paths. +set(CMAKE_USER_MAKE_RULES_OVERRIDE "${CMAKE_CURRENT_LIST_DIR}/ClangClCMakeCompileRules.cmake") |