From 00e724fb8a240cd7f5e510327263026f64ed7550 Mon Sep 17 00:00:00 2001 From: Christian Blichmann Date: Wed, 23 Sep 2020 06:42:34 -0700 Subject: [PATCH] CMake build improvements - Try to fix Ninja needlessly rebuilding everything every time See https://stackoverflow.com/questions/47087237/cmake-and-ninja-rebuild-unnecessary-files/47100426#47100426 - Since SAPI requires CMake >= 3.12, remove custom `list_join` PiperOrigin-RevId: 333281764 Change-Id: I334d67d7ee54d21824b19e60a7a7f1e43bb5a057 --- CMakeLists.txt | 21 ++++++++++++--------- cmake/SapiBuildDefs.cmake | 4 ++-- cmake/SapiUtil.cmake | 10 ---------- 3 files changed, 14 insertions(+), 21 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7c993f4..20b732e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,6 +14,16 @@ cmake_minimum_required(VERSION 3.12) +# Fix Ninja generator output to not rebuild entire sub-trees needlessly. +if(CMAKE_GENERATOR MATCHES "Ninja") + file(WRITE "${CMAKE_BINARY_DIR}/UserMakeRulesOverride.cmake" + "string(REPLACE \"-MD\" \"-MMD\" CMAKE_DEPFILE_FLAGS_C \"\${CMAKE_DEPFILE_FLAGS_C}\")\n" + "string(REPLACE \"-MD\" \"-MMD\" CMAKE_DEPFILE_FLAGS_CXX \"\${CMAKE_DEPFILE_FLAGS_CXX}\")\n" + ) + set(CMAKE_USER_MAKE_RULES_OVERRIDE + "${CMAKE_BINARY_DIR}/UserMakeRulesOverride.cmake" CACHE INTERNAL "") +endif() + project(SandboxedAPI C CXX ASM) # SAPI-wide setting for the language level @@ -31,15 +41,8 @@ include(SapiDeps) include(SapiUtil) include(SapiBuildDefs) -# Fix Ninja generator output to not rebuild entire sub-trees needlessly. -if(CMAKE_GENERATOR MATCHES "Ninja") - file(WRITE "${SAPI_BINARY_DIR}/UserMakeRulesOverride.cmake" - "STRING(REPLACE \"-MD\" \"-MMD\" CMAKE_DEPFILE_FLAGS_C \"\${CMAKE_DEPFILE_FLAGS_C}\")\n" - "STRING(REPLACE \"-MD\" \"-MMD\" CMAKE_DEPFILE_FLAGS_CXX \"\${CMAKE_DEPFILE_FLAGS_CXX}\")\n" - ) - set(CMAKE_USER_MAKE_RULES_OVERRIDE - "${SAPI_BINARY_DIR}/UserMakeRulesOverride.cmake" CACHE INTERNAL "") -endif() +# Allow the header generator to auto-configure include paths +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) if (SAPI_FORCE_COLOR_OUTPUT) if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") # GCC diff --git a/cmake/SapiBuildDefs.cmake b/cmake/SapiBuildDefs.cmake index 62583ec..5b9ce28 100644 --- a/cmake/SapiBuildDefs.cmake +++ b/cmake/SapiBuildDefs.cmake @@ -123,7 +123,7 @@ function(add_sapi_library) endif() # Interface - list_join(_sapi_FUNCTIONS "," _sapi_funcs) + list(JOIN _sapi_FUNCTIONS "," _sapi_funcs) foreach(src IN LISTS _sapi_INPUTS) get_filename_component(src "${src}" ABSOLUTE) list(APPEND _sapi_full_inputs "${src}") @@ -149,7 +149,7 @@ function(add_sapi_library) ) else() set(_sapi_isystem "${_sapi_NAME}.isystem") - list_join(_sapi_full_inputs "," _sapi_full_inputs) + list(JOIN _sapi_full_inputs "," _sapi_full_inputs) add_custom_command( OUTPUT "${_sapi_gen_header}" "${_sapi_isystem}" COMMAND sh -c diff --git a/cmake/SapiUtil.cmake b/cmake/SapiUtil.cmake index 8773f59..f4e891f 100644 --- a/cmake/SapiUtil.cmake +++ b/cmake/SapiUtil.cmake @@ -35,16 +35,6 @@ function(create_directory_symlink SOURCE DESTINATION) endif() endfunction() -# Implements list(JOIN ...) for CMake < 3.12. -function(list_join LIST SEP OUTPUT) - foreach(item IN LISTS ${LIST}) - set(_concat "${_concat}${SEP}${item}") - endforeach() - string(LENGTH "${SEP}" _len) - string(SUBSTRING "${_concat}" ${_len} -1 _concat) - set(${OUTPUT} "${_concat}" PARENT_SCOPE) -endfunction() - # Helper function that behaves just like Protobuf's protobuf_generate_cpp(), # except that it strips import paths. This is necessary, because CMake's # protobuf rules don't work well with imports across different directories.