From c4f5b046ad981990b84c96801414a764d02214b9 Mon Sep 17 00:00:00 2001 From: Hans Wennborg Date: Thu, 13 Nov 2014 00:35:23 +0000 Subject: [PATCH] CMake: Set HOST_LINK_VERSION on Darwin (PR21268) The Autoconf build already does this, but it was never ported to CMake. The host linker version affects the flags that Clang pass to the linker, notably whether it passes -demangle or not. http://reviews.llvm.org/D6239 llvm-svn: 221844 --- clang/CMakeLists.txt | 20 ++++++++++++++++++++ clang/include/clang/Config/config.h.cmake | 3 +++ clang/include/clang/Config/config.h.in | 6 +++--- clang/test/Driver/darwin-ld-demangle.c | 8 ++++++++ 4 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 clang/test/Driver/darwin-ld-demangle.c diff --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt index fbff5ad..fe0d5f2 100644 --- a/clang/CMakeLists.txt +++ b/clang/CMakeLists.txt @@ -253,6 +253,26 @@ if (LLVM_COMPILER_IS_GCC_COMPATIBLE) endif() endif () +# Determine HOST_LINK_VERSION on Darwin. +set(HOST_LINK_VERSION) +if (APPLE) + set(LD_V_OUTPUT) + execute_process( + COMMAND sh -c "${CMAKE_LINKER} -v 2>&1 | head -1" + RESULT_VARIABLE HAD_ERROR + OUTPUT_VARIABLE LD_V_OUTPUT + ) + if (NOT HAD_ERROR) + if ("${LD_V_OUTPUT}" MATCHES ".*ld64.*") + string(REGEX REPLACE ".*ld64-([0-9.]*).*" "\\1" HOST_LINK_VERSION ${LD_V_OUTPUT}) + else() + string(REGEX REPLACE "[^0-9]*([0-9.]*).*" "\\1" HOST_LINK_VERSION ${LD_V_OUTPUT}) + endif() + else() + message(FATAL_ERROR "${CMAKE_LINKER} failed with status ${HAD_ERROR}") + endif() +endif() + configure_file( ${CLANG_SOURCE_DIR}/include/clang/Config/config.h.cmake ${CLANG_BINARY_DIR}/include/clang/Config/config.h) diff --git a/clang/include/clang/Config/config.h.cmake b/clang/include/clang/Config/config.h.cmake index 7629ef9..38b398c 100644 --- a/clang/include/clang/Config/config.h.cmake +++ b/clang/include/clang/Config/config.h.cmake @@ -26,4 +26,7 @@ /* The LLVM product name and version */ #define BACKEND_PACKAGE_STRING "${BACKEND_PACKAGE_STRING}" +/* Linker version detected at compile time. */ +#cmakedefine HOST_LINK_VERSION "${HOST_LINK_VERSION}" + #endif diff --git a/clang/include/clang/Config/config.h.in b/clang/include/clang/Config/config.h.in index 1530fef..3c2cb07 100644 --- a/clang/include/clang/Config/config.h.in +++ b/clang/include/clang/Config/config.h.in @@ -14,9 +14,6 @@ /* Directories clang will search for headers */ #undef C_INCLUDE_DIRS -/* Linker version detected at compile time. */ -#undef HOST_LINK_VERSION - /* Default to all compiler invocations for --sysroot=. */ #undef DEFAULT_SYSROOT @@ -31,4 +28,7 @@ /* The LLVM product name and version */ #define BACKEND_PACKAGE_STRING PACKAGE_STRING +/* Linker version detected at compile time. */ +#undef HOST_LINK_VERSION + #endif diff --git a/clang/test/Driver/darwin-ld-demangle.c b/clang/test/Driver/darwin-ld-demangle.c new file mode 100644 index 0000000..1eef3c7 --- /dev/null +++ b/clang/test/Driver/darwin-ld-demangle.c @@ -0,0 +1,8 @@ +// REQUIRES: system-darwin + +// On Darwin, -demangle is passed to the linker of HOST_LINK_VERSION +// is high enough. It is assumed to be high enough on systems where +// this test gets run. + +// RUN: %clang -### %s 2>&1 | FileCheck %s +// CHECK: -demangle -- 2.7.4