[PATCH] D59429: [CMake] Fix broken uses of `try_compile_only()` and improve the function.

Dan Liew via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 15 12:49:50 PDT 2019


delcypher updated this revision to Diff 190882.
delcypher added a comment.

Fix missing unused arguments checks.


Repository:
  rCRT Compiler Runtime

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59429/new/

https://reviews.llvm.org/D59429

Files:
  cmake/Modules/BuiltinTests.cmake
  cmake/Modules/CompilerRTDarwinUtils.cmake
  cmake/Modules/CompilerRTUtils.cmake


Index: cmake/Modules/CompilerRTUtils.cmake
===================================================================
--- cmake/Modules/CompilerRTUtils.cmake
+++ cmake/Modules/CompilerRTUtils.cmake
@@ -128,7 +128,7 @@
     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)
Index: cmake/Modules/CompilerRTDarwinUtils.cmake
===================================================================
--- cmake/Modules/CompilerRTDarwinUtils.cmake
+++ cmake/Modules/CompilerRTDarwinUtils.cmake
@@ -93,7 +93,7 @@
    
     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}")
Index: cmake/Modules/BuiltinTests.cmake
===================================================================
--- cmake/Modules/BuiltinTests.cmake
+++ 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()


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59429.190882.patch
Type: text/x-patch
Size: 2996 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190315/3b83cbca/attachment.bin>


More information about the llvm-commits mailing list