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
This commit is contained in:
Christian Blichmann 2020-09-23 06:42:34 -07:00 committed by Copybara-Service
parent f91f843f50
commit 00e724fb8a
3 changed files with 14 additions and 21 deletions

View File

@ -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

View File

@ -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

View File

@ -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.