]> granicus.if.org Git - clang/commitdiff
[CMake] Improve the clang order-file generation workflow
authorChris Bieneman <beanz@apple.com>
Fri, 5 Feb 2016 01:22:03 +0000 (01:22 +0000)
committerChris Bieneman <beanz@apple.com>
Fri, 5 Feb 2016 01:22:03 +0000 (01:22 +0000)
Summary:
With this change generating clang order files using dtrace uses the following workflow:

cmake <whatever options you want>

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/D16896

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@259862 91177308-0d34-0410-b5e6-96231b3b80d8

CMakeLists.txt
tools/driver/CMakeLists.txt
utils/perf-training/CMakeLists.txt

index 7ac3df49a0af305d3c7c097f01a9bd3b0619450d..d7a498d12819dfcfb13bb4e122a97a5920c051e3 100644 (file)
@@ -586,9 +586,19 @@ if( CLANG_INCLUDE_DOCS )
   add_subdirectory(docs)
 endif()
 
-set(CLANG_ORDER_FILE "" CACHE FILEPATH
+# this line is needed as a cleanup to ensure that any CMakeCaches with the old
+# default value get updated to the new default.
+if(CLANG_ORDER_FILE STREQUAL "")
+  unset(CLANG_ORDER_FILE CACHE)
+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})
+endif()
+
 if (CLANG_BUILT_STANDALONE OR CMAKE_VERSION VERSION_EQUAL 3 OR
     CMAKE_VERSION VERSION_GREATER 3)
   # Generate a list of CMake library targets so that other CMake projects can
index ffcfbb505ae391fb48101c60a9c8a663b3a4da85..2971bf868efed10a5986b31a6de75752a0ef93e4 100644 (file)
@@ -87,8 +87,12 @@ if (APPLE)
   set(TOOL_INFO_BUILD_VERSION)
 endif()
 
-if(CLANG_ORDER_FILE)
+check_cxx_compiler_flag("-Wl,-order_file,${CLANG_ORDER_FILE}"
+  LINKER_HAS_ORDER_FILE_FLAG)
+
+if(LINKER_HAS_ORDER_FILE_FLAG)
   target_link_libraries(clang "-Wl,-order_file,${CLANG_ORDER_FILE}")
+  set_target_properties(clang PROPERTIES LINK_DEPENDS ${CLANG_ORDER_FILE})
 endif()
 
 if(WITH_POLLY AND LINK_POLLY_INTO_TOOLS)
index 32f7c84555b441a6451d8e09d4426ada7415aa18..f8647a0e44f7fae908936400475b03e9ddd9ec71 100644 (file)
@@ -55,9 +55,8 @@ if(DTRACE)
     COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py clean ${CMAKE_CURRENT_BINARY_DIR} dtrace
     COMMENT "Clearing old dtrace data")
 
-
   add_custom_target(generate-order-file
-    COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py gen-order-file --binary $<TARGET_FILE:clang> --output ${CMAKE_CURRENT_BINARY_DIR}/clang.order ${CMAKE_CURRENT_BINARY_DIR}
+    COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py gen-order-file --binary $<TARGET_FILE:clang> --output ${CLANG_ORDER_FILE} ${CMAKE_CURRENT_BINARY_DIR}
     COMMENT "Generating order file"
     DEPENDS generate-dtrace-logs)
 endif()