summaryrefslogtreecommitdiff
path: root/cmake
diff options
context:
space:
mode:
authorDan Liew <dan@su-root.co.uk>2019-04-26 13:22:39 +0000
committerDan Liew <dan@su-root.co.uk>2019-04-26 13:22:39 +0000
commit1bcdbd68616dc7f8debe126caafef7a7242a0e6b (patch)
tree77b60c4ce38ad4e563bb5d3672a90c4b68c593f2 /cmake
parentb4c647a71c6a67d744981e8b84e154b5e0252850 (diff)
downloadcompiler-rt-1bcdbd68616dc7f8debe126caafef7a7242a0e6b.tar.gz
[CMake] Fix the value of `config.target_cflags` for non-macOS Apple
platforms. The main problem here is that `-*-version_min=` was not being passed to the compiler when building test cases. This can cause problems when testing on devices running older OSs because Clang would previously assume the minimum deployment target is the the latest OS in the SDK which could be much newer than what the device is running. Previously the generated value looked like this: `-arch arm64 -isysroot <path_to_xcode>/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.1.sdk` With this change it now looks like: `-arch arm64 -stdlib=libc++ -miphoneos-version-min=8.0 -isysroot <path_to_xcode>/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.1.sdk` This mirrors the setting of `config.target_cflags` on macOS. This change is made for ASan, LibFuzzer, TSan, and UBSan. To implement this a new `get_test_cflags_for_apple_platform()` function has been added that when given an Apple platform name and architecture returns a string containing the C compiler flags to use when building tests. This also calls a new helper function `is_valid_apple_platform()` that validates Apple platform names. rdar://problem/50124489 Differential Revision: https://reviews.llvm.org/D58578 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@359305 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'cmake')
-rw-r--r--cmake/config-ix.cmake26
1 files changed, 26 insertions, 0 deletions
diff --git a/cmake/config-ix.cmake b/cmake/config-ix.cmake
index b072c1180..2050b139e 100644
--- a/cmake/config-ix.cmake
+++ b/cmake/config-ix.cmake
@@ -205,6 +205,32 @@ macro(get_test_cc_for_arch arch cc_out cflags_out)
endif()
endmacro()
+# Returns CFLAGS that should be used to run tests for the
+# specific apple platform and architecture.
+function(get_test_cflags_for_apple_platform platform arch cflags_out)
+ is_valid_apple_platform("${platform}" is_valid_platform)
+ if (NOT is_valid_platform)
+ message(FATAL_ERROR "\"${platform}\" is not a valid apple platform")
+ endif()
+ set(test_cflags "")
+ get_target_flags_for_arch(${arch} test_cflags)
+ list(APPEND test_cflags ${DARWIN_${platform}_CFLAGS})
+ string(REPLACE ";" " " test_cflags_str "${test_cflags}")
+ string(APPEND test_cflags_str "${COMPILER_RT_TEST_COMPILER_CFLAGS}")
+ set(${cflags_out} "${test_cflags_str}" PARENT_SCOPE)
+endfunction()
+
+function(is_valid_apple_platform platform is_valid_out)
+ set(is_valid FALSE)
+ if ("${platform}" STREQUAL "")
+ message(FATAL_ERROR "platform cannot be empty")
+ endif()
+ if ("${platform}" MATCHES "^(osx|((ios|watchos|tvos)(sim)?))$")
+ set(is_valid TRUE)
+ endif()
+ set(${is_valid_out} ${is_valid} PARENT_SCOPE)
+endfunction()
+
set(ARM64 aarch64)
set(ARM32 arm armhf)
set(HEXAGON hexagon)