[PATCH] D31098: [compiler-rt] respect CMAKE_EXE_LINKER_FLAGS in compiler and library tests

Bob Haarman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 17 13:30:56 PDT 2017


inglorion created this revision.
Herald added subscribers: mehdi_amini, mgorny, dberris.

check_cxx_compiler_flag and check_library_exists could fail because they ignored CMAKE_EXE_LINKER_FLAGS and therefore would always fail to produce executables. Cmake policy CMP0056 fixes this, but was explicitly set to OLD in our CMakeLists because it caused problems with test_target_arch. This change sets the policy to NEW to fix the problem with the compiler and library tests, and temporarily clears CMAKE_EXE_LINKER_FLAGS inside test_target_arch to emulate the old behavior there. This allows, for example, LTO builds that require lld to succeed.


https://reviews.llvm.org/D31098

Files:
  CMakeLists.txt
  cmake/Modules/CompilerRTUtils.cmake


Index: cmake/Modules/CompilerRTUtils.cmake
===================================================================
--- cmake/Modules/CompilerRTUtils.cmake
+++ cmake/Modules/CompilerRTUtils.cmake
@@ -125,6 +125,8 @@
 #   2) simple file can be successfully built.
 # If successful, saves target flags for this architecture.
 macro(test_target_arch arch def)
+  set(SAVED_CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS})
+  set(CMAKE_EXE_LINKER_FLAGS "")
   set(TARGET_${arch}_CFLAGS ${ARGN})
   set(TARGET_${arch}_LINK_FLAGS ${ARGN})
   set(argstring "")
@@ -156,6 +158,7 @@
     # Bail out if we cannot target the architecture we plan to test.
     message(FATAL_ERROR "Cannot compile for ${arch}:\n${TARGET_${arch}_OUTPUT}")
   endif()
+  set(CMAKE_EXE_LINKER_FLAGS ${SAVED_CMAKE_EXE_LINKER_FLAGS})
 endmacro()
 
 macro(detect_target_arch)
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -14,16 +14,7 @@
 endif()
 
 cmake_minimum_required(VERSION 3.4.3)
-# FIXME:
-# The OLD behavior (pre 3.2) for this policy is to not set the value of the 
-# CMAKE_EXE_LINKER_FLAGS variable in the generated test project. The NEW behavior
-# for this policy is to set the value of the CMAKE_EXE_LINKER_FLAGS variable 
-# in the test project to the same as it is in the calling project. The new 
-# behavior cause the compiler_rt test to fail during try_compile: see
-# projects/compiler-rt/cmake/Modules/CompilerRTUtils.cmake:121 such that
-# CAN_TARGET_${arch} is not set properly. This results in COMPILER_RT_SUPPORTED_ARCH
-# not being updated properly leading to poblems.
-cmake_policy(SET CMP0056 OLD)
+cmake_policy(SET CMP0056 NEW)
 
 # Add path for custom compiler-rt modules.
 list(INSERT CMAKE_MODULE_PATH 0


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31098.92188.patch
Type: text/x-patch
Size: 1783 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170317/647eb999/attachment.bin>


More information about the llvm-commits mailing list