aboutsummaryrefslogtreecommitdiff
path: root/cmake/Modules
diff options
context:
space:
mode:
authorDan Liew <dan@su-root.co.uk>2019-03-15 20:14:46 +0000
committerDan Liew <dan@su-root.co.uk>2019-03-15 20:14:46 +0000
commit9f496373305ea9aff3ef6780dbfa116f8bf92ee4 (patch)
treeedeb96402a814e8330158d29a96f127143cd8dac /cmake/Modules
parent1df89e2348efbee3dbbbd7fa21e3a18a33019dc4 (diff)
[CMake] Fix broken uses of `try_compile_only()` and improve the function.
Summary: There were existing calls to `try_compile_only()` with arguments not prefixed by `SOURCE` or `FLAGS`. These were silently being ignored. It looks like the `SOURCE` and `FLAGS` arguments were first introduced in r278454. One implication of this is that for a builtins only build for Darwin (see `darwin_test_archs()`) it would mean we weren't actually passing `-arch <arch>` to the compiler). This would result in compiler-rt claiming all supplied architectures could be targetted provided the compiler could build for Clang's default architecture. This patch fixes this in several ways. * Fixes all incorrect calls to `try_compile_only()`. * Adds code to `try_compile_only()` to check for unhandled arguments and raises a fatal error if this occurs. This should stop any incorrect calls in the future. * Improve the documentation on `try_compile_only()` which seemed completely wrong. rdar://problem/48928526 Reviewers: beanz, fjricci, dsanders, kubamracek, yln, dcoughlin Subscribers: mgorny, jdoerfert, #sanitizers, llvm-commits Tags: #llvm, #sanitizers Differential Revision: https://reviews.llvm.org/D59429 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@356295 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'cmake/Modules')
-rw-r--r--cmake/Modules/BuiltinTests.cmake36
-rw-r--r--cmake/Modules/CompilerRTDarwinUtils.cmake2
-rw-r--r--cmake/Modules/CompilerRTUtils.cmake2
3 files changed, 36 insertions, 4 deletions
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/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 3ebd92739..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)