summaryrefslogtreecommitdiff
path: root/cmake/Modules
diff options
context:
space:
mode:
Diffstat (limited to 'cmake/Modules')
-rw-r--r--cmake/Modules/AddCompilerRT.cmake94
-rw-r--r--cmake/Modules/BuiltinTests.cmake36
-rw-r--r--cmake/Modules/CompilerRTCompile.cmake2
-rw-r--r--cmake/Modules/CompilerRTDarwinUtils.cmake2
-rw-r--r--cmake/Modules/CompilerRTUtils.cmake8
-rw-r--r--cmake/Modules/CustomLibcxx/CMakeLists.txt26
6 files changed, 139 insertions, 29 deletions
diff --git a/cmake/Modules/AddCompilerRT.cmake b/cmake/Modules/AddCompilerRT.cmake
index 81b110203..3970fb415 100644
--- a/cmake/Modules/AddCompilerRT.cmake
+++ b/cmake/Modules/AddCompilerRT.cmake
@@ -132,7 +132,7 @@ endmacro()
# Adds static or shared runtime for a list of architectures and operating
# systems and puts it in the proper directory in the build and install trees.
# add_compiler_rt_runtime(<name>
-# {STATIC|SHARED}
+# {OBJECT|STATIC|SHARED}
# ARCHS <architectures>
# OS <os list>
# SOURCES <source files>
@@ -144,8 +144,8 @@ endmacro()
# PARENT_TARGET <convenience parent target>
# ADDITIONAL_HEADERS <header files>)
function(add_compiler_rt_runtime name type)
- if(NOT type MATCHES "^(STATIC|SHARED)$")
- message(FATAL_ERROR "type argument must be STATIC or SHARED")
+ if(NOT type MATCHES "^(OBJECT|STATIC|SHARED)$")
+ message(FATAL_ERROR "type argument must be OBJECT, STATIC or SHARED")
return()
endif()
cmake_parse_arguments(LIB
@@ -204,7 +204,10 @@ function(add_compiler_rt_runtime name type)
message(FATAL_ERROR "Architecture ${arch} can't be targeted")
return()
endif()
- if(type STREQUAL "STATIC")
+ if(type STREQUAL "OBJECT")
+ set(libname "${name}-${arch}")
+ set_output_name(output_name_${libname} ${name}${COMPILER_RT_OS_SUFFIX} ${arch})
+ elseif(type STREQUAL "STATIC")
set(libname "${name}-${arch}")
set_output_name(output_name_${libname} ${name} ${arch})
else()
@@ -270,17 +273,66 @@ function(add_compiler_rt_runtime name type)
set(COMPONENT_OPTION COMPONENT ${libname})
endif()
- add_library(${libname} ${type} ${sources_${libname}})
- set_target_compile_flags(${libname} ${extra_cflags_${libname}})
- set_target_link_flags(${libname} ${extra_link_flags_${libname}})
- set_property(TARGET ${libname} APPEND PROPERTY
- COMPILE_DEFINITIONS ${LIB_DEFS})
- set_target_output_directories(${libname} ${output_dir_${libname}})
+ if(type STREQUAL "OBJECT")
+ if(CMAKE_C_COMPILER_ID MATCHES Clang AND CMAKE_C_COMPILER_TARGET)
+ list(APPEND extra_cflags_${libname} "--target=${CMAKE_C_COMPILER_TARGET}")
+ endif()
+ if(CMAKE_SYSROOT)
+ list(APPEND extra_cflags_${libname} "--sysroot=${CMAKE_SYSROOT}")
+ endif()
+ string(REPLACE ";" " " extra_cflags_${libname} "${extra_cflags_${libname}}")
+ string(REGEX MATCHALL "<[A-Za-z0-9_]*>" substitutions
+ ${CMAKE_C_COMPILE_OBJECT})
+ set(compile_command_${libname} "${CMAKE_C_COMPILE_OBJECT}")
+ set(output_file_${libname} ${output_name_${libname}}${CMAKE_C_OUTPUT_EXTENSION})
+ foreach(substitution ${substitutions})
+ if(substitution STREQUAL "<CMAKE_C_COMPILER>")
+ string(REPLACE "<CMAKE_C_COMPILER>" "${CMAKE_C_COMPILER}"
+ compile_command_${libname} ${compile_command_${libname}})
+ elseif(substitution STREQUAL "<OBJECT>")
+ string(REPLACE "<OBJECT>" "${output_dir_${libname}}/${output_file_${libname}}"
+ compile_command_${libname} ${compile_command_${libname}})
+ elseif(substitution STREQUAL "<SOURCE>")
+ string(REPLACE "<SOURCE>" "${sources_${libname}}"
+ compile_command_${libname} ${compile_command_${libname}})
+ elseif(substitution STREQUAL "<FLAGS>")
+ string(REPLACE "<FLAGS>" "${CMAKE_C_FLAGS} ${extra_cflags_${libname}}"
+ compile_command_${libname} ${compile_command_${libname}})
+ else()
+ string(REPLACE "${substitution}" "" compile_command_${libname}
+ ${compile_command_${libname}})
+ endif()
+ endforeach()
+ separate_arguments(compile_command_${libname})
+ add_custom_command(
+ OUTPUT ${output_dir_${libname}}/${output_file_${libname}}
+ COMMAND ${compile_command_${libname}}
+ DEPENDS ${sources_${libname}}
+ COMMENT "Building C object ${output_file_${libname}}")
+ add_custom_target(${libname} DEPENDS ${output_dir_${libname}}/${output_file_${libname}})
+ install(FILES ${output_dir_${libname}}/${output_file_${libname}}
+ DESTINATION ${install_dir_${libname}}
+ ${COMPONENT_OPTION})
+ else()
+ add_library(${libname} ${type} ${sources_${libname}})
+ set_target_compile_flags(${libname} ${extra_cflags_${libname}})
+ set_target_link_flags(${libname} ${extra_link_flags_${libname}})
+ set_property(TARGET ${libname} APPEND PROPERTY
+ COMPILE_DEFINITIONS ${LIB_DEFS})
+ set_target_output_directories(${libname} ${output_dir_${libname}})
+ install(TARGETS ${libname}
+ ARCHIVE DESTINATION ${install_dir_${libname}}
+ ${COMPONENT_OPTION}
+ LIBRARY DESTINATION ${install_dir_${libname}}
+ ${COMPONENT_OPTION}
+ RUNTIME DESTINATION ${install_dir_${libname}}
+ ${COMPONENT_OPTION})
+ endif()
set_target_properties(${libname} PROPERTIES
OUTPUT_NAME ${output_name_${libname}})
set_target_properties(${libname} PROPERTIES FOLDER "Compiler-RT Runtime")
if(LIB_LINK_LIBS)
- target_link_libraries(${libname} ${LIB_LINK_LIBS})
+ target_link_libraries(${libname} PRIVATE ${LIB_LINK_LIBS})
endif()
if(${type} STREQUAL "SHARED")
if(COMMAND llvm_setup_rpath)
@@ -299,13 +351,6 @@ function(add_compiler_rt_runtime name type)
)
endif()
endif()
- install(TARGETS ${libname}
- ARCHIVE DESTINATION ${install_dir_${libname}}
- ${COMPONENT_OPTION}
- LIBRARY DESTINATION ${install_dir_${libname}}
- ${COMPONENT_OPTION}
- RUNTIME DESTINATION ${install_dir_${libname}}
- ${COMPONENT_OPTION})
# We only want to generate per-library install targets if you aren't using
# an IDE because the extra targets get cluttered in IDEs.
@@ -509,13 +554,16 @@ macro(add_custom_libcxx name prefix)
if(NOT COMPILER_RT_LIBCXX_PATH)
message(FATAL_ERROR "libcxx not found!")
endif()
+ if(NOT COMPILER_RT_LIBCXXABI_PATH)
+ message(FATAL_ERROR "libcxxabi not found!")
+ endif()
cmake_parse_arguments(LIBCXX "USE_TOOLCHAIN" "" "DEPS;CFLAGS;CMAKE_ARGS" ${ARGN})
if(LIBCXX_USE_TOOLCHAIN)
set(compiler_args -DCMAKE_C_COMPILER=${COMPILER_RT_TEST_COMPILER}
-DCMAKE_CXX_COMPILER=${COMPILER_RT_TEST_CXX_COMPILER})
- if(NOT COMPILER_RT_STANDALONE_BUILD)
+ if(NOT COMPILER_RT_STANDALONE_BUILD AND NOT RUNTIMES_BUILD)
set(toolchain_deps $<TARGET_FILE:clang>)
set(force_deps DEPENDS $<TARGET_FILE:clang>)
endif()
@@ -584,7 +632,7 @@ macro(add_custom_libcxx name prefix)
ExternalProject_Add(${name}
DEPENDS ${name}-clobber ${LIBCXX_DEPS}
PREFIX ${prefix}
- SOURCE_DIR ${COMPILER_RT_LIBCXX_PATH}
+ SOURCE_DIR ${COMPILER_RT_SOURCE_DIR}/cmake/Modules/CustomLibcxx
STAMP_DIR ${STAMP_DIR}
BINARY_DIR ${BINARY_DIR}
CMAKE_ARGS ${CMAKE_PASSTHROUGH_VARIABLES}
@@ -592,10 +640,12 @@ macro(add_custom_libcxx name prefix)
-DCMAKE_C_FLAGS=${LIBCXX_C_FLAGS}
-DCMAKE_CXX_FLAGS=${LIBCXX_CXX_FLAGS}
-DCMAKE_BUILD_TYPE=Release
+ -DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY
-DLLVM_PATH=${LLVM_MAIN_SRC_DIR}
-DLLVM_BINARY_DIR=${prefix}
-DLLVM_LIBRARY_OUTPUT_INTDIR=${prefix}/lib
- -DLIBCXX_STANDALONE_BUILD=ON
+ -DCOMPILER_RT_LIBCXX_PATH=${COMPILER_RT_LIBCXX_PATH}
+ -DCOMPILER_RT_LIBCXXABI_PATH=${COMPILER_RT_LIBCXXABI_PATH}
${LIBCXX_CMAKE_ARGS}
INSTALL_COMMAND ""
STEP_TARGETS configure build
@@ -610,7 +660,7 @@ macro(add_custom_libcxx name prefix)
set(run_clean "$(MAKE)" "-C" "${BINARY_DIR}" "clean")
else()
set(run_clean ${CMAKE_COMMAND} --build ${BINARY_DIR} --target clean
- --config "$<CONFIGURATION>")
+ --config "$<CONFIG>")
endif()
ExternalProject_Add_Step(${name} clean
diff --git a/cmake/Modules/BuiltinTests.cmake b/cmake/Modules/BuiltinTests.cmake
index a6bf8644a..eee77ad02 100644
--- a/cmake/Modules/BuiltinTests.cmake
+++ b/cmake/Modules/BuiltinTests.cmake
@@ -1,9 +1,41 @@
include(CMakeCheckCompilerFlagCommonPatterns)
-# This function takes an OS and a list of architectures and identifies the
-# subset of the architectures list that the installed toolchain can target.
+# Test compiler can compile simple C/C++/Objective-C program without invoking
+# the linker.
+#
+# try_compile_only(
+# OUTPUT_VAR
+# [SOURCE source_text]
+# [FLAGS flag_0 [ flag_1 ]]
+# )
+#
+# OUTPUT_VAR - The variable name to store the result. The result is a boolean
+# `True` or `False`.
+#
+# SOURCE - Optional. If specified use source the source text string
+# specified. If not specified source code will be used that is C,
+# C++, and Objective-C compatible.
+#
+# FLAGS - Optional. If specified pass the one or more specified flags to
+# the compiler.
+#
+# EXAMPLES:
+#
+# try_compile_only(HAS_F_NO_RTTI FLAGS "-fno-rtti")
+#
+# try_compile_only(HAS_CXX_AUTO_TYPE_DECL
+# SOURCE "int foo(int x) { auto y = x + 1; return y;}"
+# FLAGS "-x" "c++" "-std=c++11" "-Werror=c++11-extensions"
+# )
+#
function(try_compile_only output)
+ # NOTE: `SOURCE` needs to be a multi-argument because source code
+ # often contains semicolons which happens to be CMake's list separator
+ # which confuses `cmake_parse_arguments()`.
cmake_parse_arguments(ARG "" "" "SOURCE;FLAGS" ${ARGN})
+ if (ARG_UNPARSED_ARGUMENTS)
+ message(FATAL_ERROR "Unexpected arguments \"${ARG_UNPARSED_ARGUMENTS}\"")
+ endif()
if(NOT ARG_SOURCE)
set(ARG_SOURCE "int foo(int x, int y) { return x + y; }\n")
endif()
diff --git a/cmake/Modules/CompilerRTCompile.cmake b/cmake/Modules/CompilerRTCompile.cmake
index 556ee7896..07b589beb 100644
--- a/cmake/Modules/CompilerRTCompile.cmake
+++ b/cmake/Modules/CompilerRTCompile.cmake
@@ -136,7 +136,7 @@ macro(clang_compiler_add_cxx_check)
COMMAND bash -c "${CMD}"
COMMENT "Checking that just-built clang can find C++ headers..."
VERBATIM)
- if (NOT COMPILER_RT_STANDALONE_BUILD)
+ if (NOT COMPILER_RT_STANDALONE_BUILD AND NOT RUNTIMES_BUILD)
ADD_DEPENDENCIES(CompilerRTUnitTestCheckCxx clang)
endif()
endif()
diff --git a/cmake/Modules/CompilerRTDarwinUtils.cmake b/cmake/Modules/CompilerRTDarwinUtils.cmake
index 04cc95598..48f761a2e 100644
--- a/cmake/Modules/CompilerRTDarwinUtils.cmake
+++ b/cmake/Modules/CompilerRTDarwinUtils.cmake
@@ -93,7 +93,7 @@ function(darwin_test_archs os valid_archs)
set(arch_linker_flags "-arch ${arch} ${os_linker_flags}")
if(TEST_COMPILE_ONLY)
- try_compile_only(CAN_TARGET_${os}_${arch} -v -arch ${arch} ${DARWIN_${os}_CFLAGS})
+ try_compile_only(CAN_TARGET_${os}_${arch} FLAGS -v -arch ${arch} ${DARWIN_${os}_CFLAGS})
else()
set(SAVED_CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS})
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${arch_linker_flags}")
diff --git a/cmake/Modules/CompilerRTUtils.cmake b/cmake/Modules/CompilerRTUtils.cmake
index 5348f2064..957452cff 100644
--- a/cmake/Modules/CompilerRTUtils.cmake
+++ b/cmake/Modules/CompilerRTUtils.cmake
@@ -128,7 +128,7 @@ macro(test_target_arch arch def)
if(NOT HAS_${arch}_DEF)
set(CAN_TARGET_${arch} FALSE)
elseif(TEST_COMPILE_ONLY)
- try_compile_only(CAN_TARGET_${arch} ${TARGET_${arch}_CFLAGS})
+ try_compile_only(CAN_TARGET_${arch} FLAGS ${TARGET_${arch}_CFLAGS})
else()
set(FLAG_NO_EXCEPTIONS "")
if(COMPILER_RT_HAS_FNO_EXCEPTIONS_FLAG)
@@ -233,7 +233,8 @@ macro(load_llvm_config)
execute_process(
COMMAND ${LLVM_CONFIG_PATH} "--ldflags" "--libs" "xray"
RESULT_VARIABLE HAD_ERROR
- OUTPUT_VARIABLE CONFIG_OUTPUT)
+ OUTPUT_VARIABLE CONFIG_OUTPUT
+ ERROR_QUIET)
if (HAD_ERROR)
message(WARNING "llvm-config finding xray failed with status ${HAD_ERROR}")
set(COMPILER_RT_HAS_LLVMXRAY FALSE)
@@ -250,7 +251,8 @@ macro(load_llvm_config)
execute_process(
COMMAND ${LLVM_CONFIG_PATH} "--ldflags" "--libs" "testingsupport"
RESULT_VARIABLE HAD_ERROR
- OUTPUT_VARIABLE CONFIG_OUTPUT)
+ OUTPUT_VARIABLE CONFIG_OUTPUT
+ ERROR_QUIET)
if (HAD_ERROR)
message(WARNING "llvm-config finding testingsupport failed with status ${HAD_ERROR}")
else()
diff --git a/cmake/Modules/CustomLibcxx/CMakeLists.txt b/cmake/Modules/CustomLibcxx/CMakeLists.txt
new file mode 100644
index 000000000..3b1eb910e
--- /dev/null
+++ b/cmake/Modules/CustomLibcxx/CMakeLists.txt
@@ -0,0 +1,26 @@
+cmake_minimum_required(VERSION 3.4.3)
+project(custom-libcxx C CXX)
+
+# Build static libcxxabi.
+set(LIBCXXABI_STANDALONE_BUILD 1)
+set(LIBCXXABI_ENABLE_SHARED OFF CACHE BOOL "")
+set(LIBCXXABI_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
+set(LIBCXXABI_HERMETIC_STATIC_LIBRARY ON CACHE STRING "")
+set(LIBCXXABI_LIBCXX_PATH ${COMPILER_RT_LIBCXX_PATH} CACHE PATH "")
+set(LIBCXXABI_INCLUDE_TESTS OFF CACHE BOOL "")
+add_subdirectory(${COMPILER_RT_LIBCXXABI_PATH} ${CMAKE_CURRENT_BINARY_DIR}/cxxabi)
+
+# Build static libcxx without exceptions.
+set(LIBCXX_STANDALONE_BUILD 1)
+set(LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY OFF CACHE BOOL "")
+set(LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
+set(LIBCXX_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
+set(LIBCXX_HERMETIC_STATIC_LIBRARY ON CACHE BOOL "")
+
+# Use above libcxxabi.
+set(LIBCXX_CXX_ABI "libcxxabi" CACHE STRING "")
+set(LIBCXX_CXX_ABI_INTREE 1)
+set(LIBCXX_ENABLE_STATIC_ABI_LIBRARY ON CACHE BOOL "")
+set(LIBCXX_CXX_ABI_INCLUDE_PATHS ${COMPILER_RT_LIBCXXABI_PATH}/include CACHE PATH "")
+
+add_subdirectory(${COMPILER_RT_LIBCXX_PATH} ${CMAKE_CURRENT_BINARY_DIR}/cxx)