From 2b99e2cd3c09e4a57be0ef2a01cfc8426e949f29 Mon Sep 17 00:00:00 2001 From: Chris Bieneman Date: Fri, 12 Feb 2016 21:36:55 +0000 Subject: [PATCH 1/2] [CMake] Improve the clang order-file generation workflow Summary: This commit re-lands r259862. The underlying cause of the build breakage was an incorrectly written capabilities test. In tools/Driver/CMakeLists.txt I was attempting to check if a linker flag worked, the test was passing it to the compiler, not the linker. CMake doesn't have a linker test, so we have a hand-rolled one. Original Patch Review: http://reviews.llvm.org/D16896 Original Summary: With this change generating clang order files using dtrace uses the following workflow: cmake ninja generate-order-file ninja clang This patch works by setting a default path to the order file (which can be overridden by the user). If the order file doesn't exist during configuration CMake will create an empty one. CMake then ties up the dependencies between the clang link job and the order file, and generate-order-file overwrites CLANG_ORDER_FILE with the new order file. Reviewers: bogner Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D16999 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@260742 91177308-0d34-0410-b5e6-96231b3b80d8 --- CMakeLists.txt | 9 +++++++-- tools/driver/CMakeLists.txt | 22 +++++++++++++++++----- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bb6194385b5..61ea154391b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -595,8 +595,13 @@ endif() set(CLANG_ORDER_FILE ${CMAKE_CURRENT_BINARY_DIR}/clang.order CACHE FILEPATH "Order file to use when compiling clang in order to improve startup time.") -if(NOT EXISTS ${CLANG_ORDER_FILE}) - execute_process(COMMAND ${CMAKE_COMMAND} -E touch ${CLANG_ORDER_FILE}) +if(CLANG_ORDER_FILE AND NOT EXISTS ${CLANG_ORDER_FILE}) + string(FIND CLANG_ORDER_FILE "${CMAKE_CURRENT_BINARY_DIR}" PATH_START) + if(PATH_START EQUAL 0) + file(WRITE ${CLANG_ORDER_FILE} "\n") + else() + message(FATAL_ERROR "Specified order file '${CLANG_ORDER_FILE}' does not exist.") + endif() endif() if (CLANG_BUILT_STANDALONE OR CMAKE_VERSION VERSION_EQUAL 3 OR diff --git a/tools/driver/CMakeLists.txt b/tools/driver/CMakeLists.txt index 36457340569..dc6cd4db86d 100644 --- a/tools/driver/CMakeLists.txt +++ b/tools/driver/CMakeLists.txt @@ -89,12 +89,24 @@ if (APPLE) set(TOOL_INFO_BUILD_VERSION) endif() -check_cxx_compiler_flag("-Wl,-order_file,${CLANG_ORDER_FILE}" - LINKER_HAS_ORDER_FILE_FLAG) +if(CLANG_ORDER_FILE) + include(CMakePushCheckState) -if(LINKER_HAS_ORDER_FILE_FLAG AND CLANG_ORDER_FILE) - target_link_libraries(clang "-Wl,-order_file,${CLANG_ORDER_FILE}") - set_target_properties(clang PROPERTIES LINK_DEPENDS ${CLANG_ORDER_FILE}) + function(check_linker_flag flag out_var) + cmake_push_check_state() + set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${flag}") + check_cxx_compiler_flag("" ${out_var}) + cmake_pop_check_state() + endfunction() + + # This is a test to ensure the actual order file works with the linker. + check_linker_flag("-Wl,-order_file,${CLANG_ORDER_FILE}" + LINKER_ORDER_FILE_WORKS) + + if(LINKER_ORDER_FILE_WORKS) + target_link_libraries(clang "-Wl,-order_file,${CLANG_ORDER_FILE}") + set_target_properties(clang PROPERTIES LINK_DEPENDS ${CLANG_ORDER_FILE}) + endif() endif() if(WITH_POLLY AND LINK_POLLY_INTO_TOOLS) From 8fc756a91c459c4108100116bbce5d5885989514 Mon Sep 17 00:00:00 2001 From: Chris Bieneman Date: Fri, 12 Feb 2016 21:46:25 +0000 Subject: [PATCH 2/2] [CMake] Fixing bots I broke. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@260744 91177308-0d34-0410-b5e6-96231b3b80d8 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 61ea154391b..8bf9e26e3cc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -596,7 +596,7 @@ set(CLANG_ORDER_FILE ${CMAKE_CURRENT_BINARY_DIR}/clang.order CACHE FILEPATH "Order file to use when compiling clang in order to improve startup time.") if(CLANG_ORDER_FILE AND NOT EXISTS ${CLANG_ORDER_FILE}) - string(FIND CLANG_ORDER_FILE "${CMAKE_CURRENT_BINARY_DIR}" PATH_START) + string(FIND "${CLANG_ORDER_FILE}" "${CMAKE_CURRENT_BINARY_DIR}" PATH_START) if(PATH_START EQUAL 0) file(WRITE ${CLANG_ORDER_FILE} "\n") else()