diff options
Diffstat (limited to 'cmake/Modules')
-rw-r--r-- | cmake/Modules/AddCompilerRT.cmake | 26 | ||||
-rw-r--r-- | cmake/Modules/BuiltinTests.cmake | 23 | ||||
-rw-r--r-- | cmake/Modules/CompilerRTDarwinUtils.cmake | 34 | ||||
-rw-r--r-- | cmake/Modules/CompilerRTUtils.cmake | 119 |
4 files changed, 152 insertions, 50 deletions
diff --git a/cmake/Modules/AddCompilerRT.cmake b/cmake/Modules/AddCompilerRT.cmake index 334224854ba2..42ae7ad1ecd5 100644 --- a/cmake/Modules/AddCompilerRT.cmake +++ b/cmake/Modules/AddCompilerRT.cmake @@ -77,6 +77,15 @@ macro(format_object_libs output suffix) endforeach() endmacro() +function(add_compiler_rt_component name) + add_custom_target(${name}) + set_target_properties(${name} PROPERTIES FOLDER "Compiler-RT Misc") + if(COMMAND runtime_register_component) + runtime_register_component(${name}) + endif() + add_dependencies(compiler-rt ${name}) +endfunction() + # 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> @@ -164,6 +173,7 @@ function(add_compiler_rt_runtime name type) -P "${CMAKE_BINARY_DIR}/cmake_install.cmake") set_target_properties(install-${LIB_PARENT_TARGET} PROPERTIES FOLDER "Compiler-RT Misc") + add_dependencies(install-compiler-rt install-${LIB_PARENT_TARGET}) endif() endif() @@ -185,8 +195,14 @@ function(add_compiler_rt_runtime name type) set_target_properties(${libname} PROPERTIES OUTPUT_NAME ${output_name_${libname}}) set_target_properties(${libname} PROPERTIES FOLDER "Compiler-RT Runtime") - if(LIB_LINK_LIBS AND ${type} STREQUAL "SHARED") - target_link_libraries(${libname} ${LIB_LINK_LIBS}) + if(${type} STREQUAL "SHARED") + if(LIB_LINK_LIBS) + target_link_libraries(${libname} ${LIB_LINK_LIBS}) + endif() + if(WIN32 AND NOT CYGWIN AND NOT MINGW) + set_target_properties(${libname} PROPERTIES IMPORT_PREFIX "") + set_target_properties(${libname} PROPERTIES IMPORT_SUFFIX ".lib") + endif() endif() install(TARGETS ${libname} ARCHIVE DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR} @@ -253,12 +269,6 @@ if(MSVC) # gtest use a lot of stuff marked as deprecated on Windows. list(APPEND COMPILER_RT_GTEST_CFLAGS -Wno-deprecated-declarations) - - # Visual Studio 2012 only supports up to 8 template parameters in - # std::tr1::tuple by default, but gtest requires 10 - if(MSVC_VERSION EQUAL 1700) - list(APPEND COMPILER_RT_GTEST_CFLAGS -D_VARIADIC_MAX=10) - endif() endif() # Link objects into a single executable with COMPILER_RT_TEST_COMPILER, diff --git a/cmake/Modules/BuiltinTests.cmake b/cmake/Modules/BuiltinTests.cmake index a229145d9b91..a6bf8644ad52 100644 --- a/cmake/Modules/BuiltinTests.cmake +++ b/cmake/Modules/BuiltinTests.cmake @@ -1,3 +1,4 @@ +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. @@ -10,7 +11,13 @@ function(try_compile_only output) file(WRITE ${SIMPLE_C} "${ARG_SOURCE}\n") string(REGEX MATCHALL "<[A-Za-z0-9_]*>" substitutions ${CMAKE_C_COMPILE_OBJECT}) - string(REPLACE ";" " " extra_flags "${ARG_FLAGS}") + + set(TRY_COMPILE_FLAGS "${ARG_FLAGS}") + if(CMAKE_C_COMPILER_ID MATCHES Clang AND CMAKE_C_COMPILER_TARGET) + list(APPEND TRY_COMPILE_FLAGS "-target ${CMAKE_C_COMPILER_TARGET}") + endif() + + string(REPLACE ";" " " extra_flags "${TRY_COMPILE_FLAGS}") set(test_compile_command "${CMAKE_C_COMPILE_OBJECT}") foreach(substitution ${substitutions}) @@ -41,7 +48,19 @@ function(try_compile_only output) OUTPUT_VARIABLE TEST_OUTPUT ERROR_VARIABLE TEST_ERROR ) - if(result EQUAL 0) + + CHECK_COMPILER_FLAG_COMMON_PATTERNS(_CheckCCompilerFlag_COMMON_PATTERNS) + set(ERRORS_FOUND OFF) + foreach(var ${_CheckCCompilerFlag_COMMON_PATTERNS}) + if("${var}" STREQUAL "FAIL_REGEX") + continue() + endif() + if("${TEST_ERROR}" MATCHES "${var}" OR "${TEST_OUTPUT}" MATCHES "${var}") + set(ERRORS_FOUND ON) + endif() + endforeach() + + if(result EQUAL 0 AND NOT ERRORS_FOUND) set(${output} True PARENT_SCOPE) else() file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log diff --git a/cmake/Modules/CompilerRTDarwinUtils.cmake b/cmake/Modules/CompilerRTDarwinUtils.cmake index fd19ff9f6568..28d398672121 100644 --- a/cmake/Modules/CompilerRTDarwinUtils.cmake +++ b/cmake/Modules/CompilerRTDarwinUtils.cmake @@ -7,13 +7,15 @@ function(find_darwin_sdk_dir var sdk_name) # Let's first try the internal SDK, otherwise use the public SDK. execute_process( COMMAND xcodebuild -version -sdk ${sdk_name}.internal Path + RESULT_VARIABLE result_process OUTPUT_VARIABLE var_internal OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_FILE /dev/null ) - if("" STREQUAL "${var_internal}") + if((NOT result_process EQUAL 0) OR "" STREQUAL "${var_internal}") execute_process( COMMAND xcodebuild -version -sdk ${sdk_name} Path + RESULT_VARIABLE result_process OUTPUT_VARIABLE var_internal OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_FILE /dev/null @@ -21,7 +23,9 @@ function(find_darwin_sdk_dir var sdk_name) else() set(${var}_INTERNAL ${var_internal} PARENT_SCOPE) endif() - set(${var} ${var_internal} PARENT_SCOPE) + if(result_process EQUAL 0) + set(${var} ${var_internal} PARENT_SCOPE) + endif() endfunction() # There isn't a clear mapping of what architectures are supported with a given @@ -256,30 +260,6 @@ function(darwin_filter_builtin_sources output_var exclude_or_include excluded_li set(${output_var} ${intermediate} PARENT_SCOPE) endfunction() -function(darwin_add_eprintf_library) - cmake_parse_arguments(LIB - "" - "" - "CFLAGS" - ${ARGN}) - - add_library(clang_rt.eprintf STATIC eprintf.c) - set_target_compile_flags(clang_rt.eprintf - -isysroot ${DARWIN_osx_SYSROOT} - ${DARWIN_osx_BUILTIN_MIN_VER_FLAG} - -arch i386 - ${LIB_CFLAGS}) - set_target_properties(clang_rt.eprintf PROPERTIES - OUTPUT_NAME clang_rt.eprintf${COMPILER_RT_OS_SUFFIX}) - set_target_properties(clang_rt.eprintf PROPERTIES - OSX_ARCHITECTURES i386) - add_dependencies(builtins clang_rt.eprintf) - set_target_properties(clang_rt.eprintf PROPERTIES - ARCHIVE_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR}) - install(TARGETS clang_rt.eprintf - ARCHIVE DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR}) -endfunction() - # Generates builtin libraries for all operating systems specified in ARGN. Each # OS library is constructed by lipo-ing together single-architecture libraries. macro(darwin_add_builtin_libraries) @@ -350,8 +330,6 @@ macro(darwin_add_builtin_libraries) endif() endforeach() - darwin_add_eprintf_library(CFLAGS ${CFLAGS}) - # We put the x86 sim slices into the archives for their base OS foreach (os ${ARGN}) if(NOT ${os} MATCHES ".*sim$") diff --git a/cmake/Modules/CompilerRTUtils.cmake b/cmake/Modules/CompilerRTUtils.cmake index 78b6dceef887..cedaaeeb3580 100644 --- a/cmake/Modules/CompilerRTUtils.cmake +++ b/cmake/Modules/CompilerRTUtils.cmake @@ -49,7 +49,7 @@ macro(append_string_if condition value) endmacro() macro(append_rtti_flag polarity list) - if(polarity) + if(${polarity}) append_list_if(COMPILER_RT_HAS_FRTTI_FLAG -frtti ${list}) append_list_if(COMPILER_RT_HAS_GR_FLAG /GR ${list}) else() @@ -76,6 +76,18 @@ macro(list_intersect output input1 input2) endforeach() endmacro() +function(list_replace input_list old new) + set(replaced_list) + foreach(item ${${input_list}}) + if(${item} STREQUAL ${old}) + list(APPEND replaced_list ${new}) + else() + list(APPEND replaced_list ${item}) + endif() + endforeach() + set(${input_list} "${replaced_list}" PARENT_SCOPE) +endfunction() + # Takes ${ARGN} and puts only supported architectures in @out_var list. function(filter_available_targets out_var) set(archs ${${out_var}}) @@ -88,6 +100,13 @@ function(filter_available_targets out_var) set(${out_var} ${archs} PARENT_SCOPE) endfunction() +# Add $arch as supported with no additional flags. +macro(add_default_target_arch arch) + set(TARGET_${arch}_CFLAGS "") + set(CAN_TARGET_${arch} 1) + list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch}) +endmacro() + function(check_compile_definition def argstring out_var) if("${def}" STREQUAL "") set(${out_var} TRUE PARENT_SCOPE) @@ -113,20 +132,26 @@ macro(test_target_arch arch def) set(argstring "${argstring} ${arg}") endforeach() check_compile_definition("${def}" "${argstring}" HAS_${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}) - else() - set(argstring "${CMAKE_EXE_LINKER_FLAGS} ${argstring}") - try_compile(CAN_TARGET_${arch} ${CMAKE_BINARY_DIR} ${SIMPLE_SOURCE} - COMPILE_DEFINITIONS "${TARGET_${arch}_CFLAGS}" - OUTPUT_VARIABLE TARGET_${arch}_OUTPUT - CMAKE_FLAGS "-DCMAKE_EXE_LINKER_FLAGS:STRING=${argstring}") + if(NOT DEFINED CAN_TARGET_${arch}) + if(NOT HAS_${arch}_DEF) + set(CAN_TARGET_${arch} FALSE) + elseif(TEST_COMPILE_ONLY) + try_compile_only(CAN_TARGET_${arch} ${TARGET_${arch}_CFLAGS}) + else() + set(argstring "${CMAKE_EXE_LINKER_FLAGS} ${argstring}") + set(FLAG_NO_EXCEPTIONS "") + if(COMPILER_RT_HAS_FNO_EXCEPTIONS_FLAG) + set(FLAG_NO_EXCEPTIONS " -fno-exceptions ") + endif() + try_compile(CAN_TARGET_${arch} ${CMAKE_BINARY_DIR} ${SIMPLE_SOURCE} + COMPILE_DEFINITIONS "${TARGET_${arch}_CFLAGS} ${FLAG_NO_EXCEPTIONS}" + OUTPUT_VARIABLE TARGET_${arch}_OUTPUT + CMAKE_FLAGS "-DCMAKE_EXE_LINKER_FLAGS:STRING=${argstring}") + endif() endif() if(${CAN_TARGET_${arch}}) list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch}) - elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "${arch}" AND + elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" STREQUAL "${arch}" AND COMPILER_RT_HAS_EXPLICIT_DEFAULT_TARGET_TRIPLE) # Bail out if we cannot target the architecture we plan to test. message(FATAL_ERROR "Cannot compile for ${arch}:\n${TARGET_${arch}_OUTPUT}") @@ -166,3 +191,73 @@ macro(detect_target_arch) add_default_target_arch(wasm64) endif() endmacro() + +macro(load_llvm_config) + if (NOT LLVM_CONFIG_PATH) + find_program(LLVM_CONFIG_PATH "llvm-config" + DOC "Path to llvm-config binary") + if (NOT LLVM_CONFIG_PATH) + message(FATAL_ERROR "llvm-config not found: specify LLVM_CONFIG_PATH") + endif() + endif() + execute_process( + COMMAND ${LLVM_CONFIG_PATH} "--obj-root" "--bindir" "--libdir" "--src-root" + RESULT_VARIABLE HAD_ERROR + OUTPUT_VARIABLE CONFIG_OUTPUT) + if (HAD_ERROR) + message(FATAL_ERROR "llvm-config failed with status ${HAD_ERROR}") + endif() + string(REGEX REPLACE "[ \t]*[\r\n]+[ \t]*" ";" CONFIG_OUTPUT ${CONFIG_OUTPUT}) + list(GET CONFIG_OUTPUT 0 BINARY_DIR) + list(GET CONFIG_OUTPUT 1 TOOLS_BINARY_DIR) + list(GET CONFIG_OUTPUT 2 LIBRARY_DIR) + list(GET CONFIG_OUTPUT 3 MAIN_SRC_DIR) + + set(LLVM_BINARY_DIR ${BINARY_DIR} CACHE PATH "Path to LLVM build tree") + set(LLVM_TOOLS_BINARY_DIR ${TOOLS_BINARY_DIR} CACHE PATH "Path to llvm/bin") + set(LLVM_LIBRARY_DIR ${LIBRARY_DIR} CACHE PATH "Path to llvm/lib") + set(LLVM_MAIN_SRC_DIR ${MAIN_SRC_DIR} CACHE PATH "Path to LLVM source tree") + + # Make use of LLVM CMake modules. + file(TO_CMAKE_PATH ${LLVM_BINARY_DIR} LLVM_BINARY_DIR_CMAKE_STYLE) + set(LLVM_CMAKE_PATH "${LLVM_BINARY_DIR_CMAKE_STYLE}/lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm") + list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_PATH}") + # Get some LLVM variables from LLVMConfig. + include("${LLVM_CMAKE_PATH}/LLVMConfig.cmake") + + set(LLVM_LIBRARY_OUTPUT_INTDIR + ${LLVM_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX}) +endmacro() + +macro(construct_compiler_rt_default_triple) + if(COMPILER_RT_DEFAULT_TARGET_ONLY) + if(DEFINED COMPILER_RT_DEFAULT_TARGET_TRIPLE) + message(FATAL_ERROR "COMPILER_RT_DEFAULT_TARGET_TRIPLE isn't supported when building for default target only") + endif() + set(COMPILER_RT_DEFAULT_TARGET_TRIPLE ${CMAKE_C_COMPILER_TARGET}) + else() + set(COMPILER_RT_DEFAULT_TARGET_TRIPLE ${TARGET_TRIPLE} CACHE STRING + "Default triple for which compiler-rt runtimes will be built.") + endif() + + if(DEFINED COMPILER_RT_TEST_TARGET_TRIPLE) + # Backwards compatibility: this variable used to be called + # COMPILER_RT_TEST_TARGET_TRIPLE. + set(COMPILER_RT_DEFAULT_TARGET_TRIPLE ${COMPILER_RT_TEST_TARGET_TRIPLE}) + endif() + + string(REPLACE "-" ";" TARGET_TRIPLE_LIST ${COMPILER_RT_DEFAULT_TARGET_TRIPLE}) + list(GET TARGET_TRIPLE_LIST 0 COMPILER_RT_DEFAULT_TARGET_ARCH) + list(GET TARGET_TRIPLE_LIST 1 COMPILER_RT_DEFAULT_TARGET_OS) + list(LENGTH TARGET_TRIPLE_LIST TARGET_TRIPLE_LIST_LENGTH) + if(TARGET_TRIPLE_LIST_LENGTH GREATER 2) + list(GET TARGET_TRIPLE_LIST 2 COMPILER_RT_DEFAULT_TARGET_ABI) + endif() + # Determine if test target triple is specified explicitly, and doesn't match the + # default. + if(NOT COMPILER_RT_DEFAULT_TARGET_TRIPLE STREQUAL TARGET_TRIPLE) + set(COMPILER_RT_HAS_EXPLICIT_DEFAULT_TARGET_TRIPLE TRUE) + else() + set(COMPILER_RT_HAS_EXPLICIT_DEFAULT_TARGET_TRIPLE FALSE) + endif() +endmacro() |