2016-04-29 02:22:01 +08:00
|
|
|
include(CMakePushCheckState)
|
|
|
|
include(CheckSymbolExists)
|
|
|
|
|
2013-01-19 00:05:21 +08:00
|
|
|
# Because compiler-rt spends a lot of time setting up custom compile flags,
|
|
|
|
# define a handy helper function for it. The compile flags setting in CMake
|
|
|
|
# has serious issues that make its syntax challenging at best.
|
|
|
|
function(set_target_compile_flags target)
|
2014-10-24 06:13:52 +08:00
|
|
|
set(argstring "")
|
2013-01-19 00:05:21 +08:00
|
|
|
foreach(arg ${ARGN})
|
|
|
|
set(argstring "${argstring} ${arg}")
|
|
|
|
endforeach()
|
|
|
|
set_property(TARGET ${target} PROPERTY COMPILE_FLAGS "${argstring}")
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
function(set_target_link_flags target)
|
2014-10-24 06:13:52 +08:00
|
|
|
set(argstring "")
|
2013-01-19 00:05:21 +08:00
|
|
|
foreach(arg ${ARGN})
|
|
|
|
set(argstring "${argstring} ${arg}")
|
|
|
|
endforeach()
|
|
|
|
set_property(TARGET ${target} PROPERTY LINK_FLAGS "${argstring}")
|
|
|
|
endfunction()
|
|
|
|
|
2013-10-26 07:03:34 +08:00
|
|
|
# Set the variable var_PYBOOL to True if var holds a true-ish string,
|
|
|
|
# otherwise set it to False.
|
|
|
|
macro(pythonize_bool var)
|
|
|
|
if (${var})
|
|
|
|
set(${var}_PYBOOL True)
|
|
|
|
else()
|
|
|
|
set(${var}_PYBOOL False)
|
|
|
|
endif()
|
|
|
|
endmacro()
|
2014-02-18 15:52:40 +08:00
|
|
|
|
2014-03-13 17:31:36 +08:00
|
|
|
# Appends value to all lists in ARGN, if the condition is true.
|
2014-10-16 06:47:54 +08:00
|
|
|
macro(append_list_if condition value)
|
2014-03-13 17:31:36 +08:00
|
|
|
if(${condition})
|
|
|
|
foreach(list ${ARGN})
|
|
|
|
list(APPEND ${list} ${value})
|
|
|
|
endforeach()
|
2014-02-18 15:52:40 +08:00
|
|
|
endif()
|
|
|
|
endmacro()
|
|
|
|
|
2014-03-13 19:31:10 +08:00
|
|
|
# Appends value to all strings in ARGN, if the condition is true.
|
|
|
|
macro(append_string_if condition value)
|
|
|
|
if(${condition})
|
|
|
|
foreach(str ${ARGN})
|
|
|
|
set(${str} "${${str}} ${value}")
|
|
|
|
endforeach()
|
|
|
|
endif()
|
|
|
|
endmacro()
|
|
|
|
|
2016-03-05 18:01:04 +08:00
|
|
|
macro(append_rtti_flag polarity list)
|
|
|
|
if(polarity)
|
|
|
|
append_list_if(COMPILER_RT_HAS_FRTTI_FLAG -frtti ${list})
|
|
|
|
append_list_if(COMPILER_RT_HAS_GR_FLAG /GR ${list})
|
|
|
|
else()
|
|
|
|
append_list_if(COMPILER_RT_HAS_FNO_RTTI_FLAG -fno-rtti ${list})
|
|
|
|
append_list_if(COMPILER_RT_HAS_GR_FLAG /GR- ${list})
|
|
|
|
endif()
|
2014-02-18 15:52:40 +08:00
|
|
|
endmacro()
|
2015-04-09 16:06:49 +08:00
|
|
|
|
|
|
|
macro(append_have_file_definition filename varname list)
|
|
|
|
check_include_file("${filename}" "${varname}")
|
2015-05-21 00:56:17 +08:00
|
|
|
if (NOT ${varname})
|
2015-04-09 16:06:49 +08:00
|
|
|
set("${varname}" 0)
|
|
|
|
endif()
|
|
|
|
list(APPEND ${list} "${varname}=${${varname}}")
|
|
|
|
endmacro()
|
[CMake] Add experimental support for building compiler-rt for iOS
Summary:
This is a reunification of three separate reviews D11073, D11082, D11083.
Having them separate was not constructive even though the patches were smaller because it led to fragmented conversations, and this is really all about one change.
This patch incorporates feedback from samsonov, and refactors the hacky darwin code out of the root CMakeLists.txt and int config-ix.cmake.
Reviewers: zaks.anna, bogner, kubabrecka, chandlerc, samsonov
Subscribers: jevinskie, filcab, llvm-commits
Differential Revision: http://reviews.llvm.org/D11820
llvm-svn: 244948
2015-08-14 04:38:16 +08:00
|
|
|
|
2016-01-27 17:28:01 +08:00
|
|
|
macro(list_intersect output input1 input2)
|
[CMake] Add experimental support for building compiler-rt for iOS
Summary:
This is a reunification of three separate reviews D11073, D11082, D11083.
Having them separate was not constructive even though the patches were smaller because it led to fragmented conversations, and this is really all about one change.
This patch incorporates feedback from samsonov, and refactors the hacky darwin code out of the root CMakeLists.txt and int config-ix.cmake.
Reviewers: zaks.anna, bogner, kubabrecka, chandlerc, samsonov
Subscribers: jevinskie, filcab, llvm-commits
Differential Revision: http://reviews.llvm.org/D11820
llvm-svn: 244948
2015-08-14 04:38:16 +08:00
|
|
|
set(${output})
|
|
|
|
foreach(it ${${input1}})
|
|
|
|
list(FIND ${input2} ${it} index)
|
|
|
|
if( NOT (index EQUAL -1))
|
|
|
|
list(APPEND ${output} ${it})
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
endmacro()
|
2016-02-18 00:57:38 +08:00
|
|
|
|
|
|
|
# Takes ${ARGN} and puts only supported architectures in @out_var list.
|
|
|
|
function(filter_available_targets out_var)
|
|
|
|
set(archs ${${out_var}})
|
|
|
|
foreach(arch ${ARGN})
|
|
|
|
list(FIND COMPILER_RT_SUPPORTED_ARCH ${arch} ARCH_INDEX)
|
|
|
|
if(NOT (ARCH_INDEX EQUAL -1) AND CAN_TARGET_${arch})
|
|
|
|
list(APPEND archs ${arch})
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
set(${out_var} ${archs} PARENT_SCOPE)
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
function(check_compile_definition def argstring out_var)
|
|
|
|
if("${def}" STREQUAL "")
|
|
|
|
set(${out_var} TRUE PARENT_SCOPE)
|
|
|
|
return()
|
|
|
|
endif()
|
|
|
|
cmake_push_check_state()
|
|
|
|
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${argstring}")
|
|
|
|
check_symbol_exists(${def} "" ${out_var})
|
|
|
|
cmake_pop_check_state()
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
# test_target_arch(<arch> <def> <target flags...>)
|
|
|
|
# Checks if architecture is supported: runs host compiler with provided
|
|
|
|
# flags to verify that:
|
|
|
|
# 1) <def> is defined (if non-empty)
|
|
|
|
# 2) simple file can be successfully built.
|
|
|
|
# If successful, saves target flags for this architecture.
|
|
|
|
macro(test_target_arch arch def)
|
|
|
|
set(TARGET_${arch}_CFLAGS ${ARGN})
|
2016-06-21 22:46:32 +08:00
|
|
|
set(TARGET_${arch}_LINKFLAGS ${ARGN})
|
2016-02-18 00:57:38 +08:00
|
|
|
set(argstring "")
|
|
|
|
foreach(arg ${ARGN})
|
|
|
|
set(argstring "${argstring} ${arg}")
|
|
|
|
endforeach()
|
|
|
|
check_compile_definition("${def}" "${argstring}" HAS_${arch}_DEF)
|
2016-07-22 18:15:09 +08:00
|
|
|
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}")
|
|
|
|
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}")
|
|
|
|
endif()
|
2016-02-18 00:57:38 +08:00
|
|
|
endif()
|
|
|
|
if(${CAN_TARGET_${arch}})
|
|
|
|
list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch})
|
2016-07-21 02:06:31 +08:00
|
|
|
elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" STREQUAL "${arch}" AND
|
2016-02-18 00:57:38 +08:00
|
|
|
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}")
|
|
|
|
endif()
|
|
|
|
endmacro()
|
2016-06-04 01:34:02 +08:00
|
|
|
|
|
|
|
macro(detect_target_arch)
|
|
|
|
check_symbol_exists(__arm__ "" __ARM)
|
|
|
|
check_symbol_exists(__aarch64__ "" __AARCH64)
|
|
|
|
check_symbol_exists(__x86_64__ "" __X86_64)
|
|
|
|
check_symbol_exists(__i686__ "" __I686)
|
|
|
|
check_symbol_exists(__i386__ "" __I386)
|
|
|
|
check_symbol_exists(__mips__ "" __MIPS)
|
|
|
|
check_symbol_exists(__mips64__ "" __MIPS64)
|
|
|
|
check_symbol_exists(__s390x__ "" __S390X)
|
|
|
|
check_symbol_exists(__wasm32__ "" __WEBASSEMBLY32)
|
|
|
|
check_symbol_exists(__wasm64__ "" __WEBASSEMBLY64)
|
|
|
|
if(__ARM)
|
|
|
|
add_default_target_arch(arm)
|
|
|
|
elseif(__AARCH64)
|
|
|
|
add_default_target_arch(aarch64)
|
|
|
|
elseif(__X86_64)
|
|
|
|
add_default_target_arch(x86_64)
|
|
|
|
elseif(__I686)
|
|
|
|
add_default_target_arch(i686)
|
|
|
|
elseif(__I386)
|
|
|
|
add_default_target_arch(i386)
|
|
|
|
elseif(__MIPS64) # must be checked before __MIPS
|
|
|
|
add_default_target_arch(mips64)
|
|
|
|
elseif(__MIPS)
|
|
|
|
add_default_target_arch(mips)
|
|
|
|
elseif(__S390X)
|
|
|
|
add_default_target_arch(s390x)
|
|
|
|
elseif(__WEBASSEMBLY32)
|
|
|
|
add_default_target_arch(wasm32)
|
|
|
|
elseif(__WEBASSEMBLY64)
|
|
|
|
add_default_target_arch(wasm64)
|
|
|
|
endif()
|
|
|
|
endmacro()
|