summaryrefslogtreecommitdiff
path: root/cmake/modules
diff options
context:
space:
mode:
Diffstat (limited to 'cmake/modules')
-rwxr-xr-xcmake/modules/AddLLVM.cmake266
-rw-r--r--cmake/modules/AddOCaml.cmake1
-rw-r--r--cmake/modules/AddSphinxTarget.cmake2
-rw-r--r--cmake/modules/CMakeLists.txt6
-rw-r--r--cmake/modules/CheckAtomic.cmake2
-rw-r--r--cmake/modules/CheckLinkerFlag.cmake4
-rw-r--r--cmake/modules/CrossCompile.cmake64
-rw-r--r--cmake/modules/GetHostTriple.cmake2
-rw-r--r--cmake/modules/GetSVN.cmake52
-rw-r--r--cmake/modules/HandleLLVMOptions.cmake194
-rwxr-xr-xcmake/modules/LLVM-Config.cmake15
-rw-r--r--cmake/modules/LLVMConfig.cmake.in8
-rw-r--r--cmake/modules/LLVMExternalProjectUtils.cmake20
-rw-r--r--cmake/modules/LLVMProcessSources.cmake20
-rw-r--r--cmake/modules/TableGen.cmake22
15 files changed, 468 insertions, 210 deletions
diff --git a/cmake/modules/AddLLVM.cmake b/cmake/modules/AddLLVM.cmake
index 1c922651b133..fd5627eecbb2 100755
--- a/cmake/modules/AddLLVM.cmake
+++ b/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/cmake/modules/AddOCaml.cmake b/cmake/modules/AddOCaml.cmake
index 1d8094cc505f..02bab6846376 100644
--- a/cmake/modules/AddOCaml.cmake
+++ b/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/cmake/modules/AddSphinxTarget.cmake b/cmake/modules/AddSphinxTarget.cmake
index 4540c5c36c8e..22e3dcb776aa 100644
--- a/cmake/modules/AddSphinxTarget.cmake
+++ b/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/cmake/modules/CMakeLists.txt b/cmake/modules/CMakeLists.txt
index ac4b0b7c0304..6074e8358594 100644
--- a/cmake/modules/CMakeLists.txt
+++ b/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/cmake/modules/CheckAtomic.cmake b/cmake/modules/CheckAtomic.cmake
index dcf021b8fdda..11f0366bc851 100644
--- a/cmake/modules/CheckAtomic.cmake
+++ b/cmake/modules/CheckAtomic.cmake
@@ -1,6 +1,7 @@
# 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.
@@ -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/cmake/modules/CheckLinkerFlag.cmake b/cmake/modules/CheckLinkerFlag.cmake
index e96d35e7721e..fe9d01a349cd 100644
--- a/cmake/modules/CheckLinkerFlag.cmake
+++ b/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/cmake/modules/CrossCompile.cmake b/cmake/modules/CrossCompile.cmake
index b0726ebd4de2..0ec76ead5c47 100644
--- a/cmake/modules/CrossCompile.cmake
+++ b/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/cmake/modules/GetHostTriple.cmake b/cmake/modules/GetHostTriple.cmake
index 0cad1db4effe..019188a59cc6 100644
--- a/cmake/modules/GetHostTriple.cmake
+++ b/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/cmake/modules/GetSVN.cmake b/cmake/modules/GetSVN.cmake
index d512bd292cf4..f729395f6e4b 100644
--- a/cmake/modules/GetSVN.cmake
+++ b/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/cmake/modules/HandleLLVMOptions.cmake b/cmake/modules/HandleLLVMOptions.cmake
index 0676317acc68..f77600a48308 100644
--- a/cmake/modules/HandleLLVMOptions.cmake
+++ b/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'
+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())'
+ # 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.
+ -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.
- )
+ # 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)
-option(LLVM_BUILD_INSTRUMENTED_COVERAGE "Build LLVM and tools with Code Coverage instrumentation (experimental)" Off)
+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" 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/cmake/modules/LLVM-Config.cmake b/cmake/modules/LLVM-Config.cmake
index 52330151065b..10fd52609274 100755
--- a/cmake/modules/LLVM-Config.cmake
+++ b/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/cmake/modules/LLVMConfig.cmake.in b/cmake/modules/LLVMConfig.cmake.in
index 7a8eb3674720..077201691656 100644
--- a/cmake/modules/LLVMConfig.cmake.in
+++ b/cmake/modules/LLVMConfig.cmake.in
@@ -72,6 +72,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 +80,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/cmake/modules/LLVMExternalProjectUtils.cmake b/cmake/modules/LLVMExternalProjectUtils.cmake
index c851eb8dbf08..b84ebbb53872 100644
--- a/cmake/modules/LLVMExternalProjectUtils.cmake
+++ b/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/cmake/modules/LLVMProcessSources.cmake b/cmake/modules/LLVMProcessSources.cmake
index ae1921b5bc0b..3b4838daed5a 100644
--- a/cmake/modules/LLVMProcessSources.cmake
+++ b/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/cmake/modules/TableGen.cmake b/cmake/modules/TableGen.cmake
index 8c3e2d7d7004..d1afcb42f9de 100644
--- a/cmake/modules/TableGen.cmake
+++ b/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)