mirror of
https://github.com/google/sandboxed-api.git
synced 2024-03-22 13:11:30 +08:00
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:
parent
f91f843f50
commit
00e724fb8a
@ -14,6 +14,16 @@
|
|||||||
|
|
||||||
cmake_minimum_required(VERSION 3.12)
|
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)
|
project(SandboxedAPI C CXX ASM)
|
||||||
|
|
||||||
# SAPI-wide setting for the language level
|
# SAPI-wide setting for the language level
|
||||||
@ -31,15 +41,8 @@ include(SapiDeps)
|
|||||||
include(SapiUtil)
|
include(SapiUtil)
|
||||||
include(SapiBuildDefs)
|
include(SapiBuildDefs)
|
||||||
|
|
||||||
# Fix Ninja generator output to not rebuild entire sub-trees needlessly.
|
# Allow the header generator to auto-configure include paths
|
||||||
if(CMAKE_GENERATOR MATCHES "Ninja")
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
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()
|
|
||||||
|
|
||||||
if (SAPI_FORCE_COLOR_OUTPUT)
|
if (SAPI_FORCE_COLOR_OUTPUT)
|
||||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") # GCC
|
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") # GCC
|
||||||
|
@ -123,7 +123,7 @@ function(add_sapi_library)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Interface
|
# Interface
|
||||||
list_join(_sapi_FUNCTIONS "," _sapi_funcs)
|
list(JOIN _sapi_FUNCTIONS "," _sapi_funcs)
|
||||||
foreach(src IN LISTS _sapi_INPUTS)
|
foreach(src IN LISTS _sapi_INPUTS)
|
||||||
get_filename_component(src "${src}" ABSOLUTE)
|
get_filename_component(src "${src}" ABSOLUTE)
|
||||||
list(APPEND _sapi_full_inputs "${src}")
|
list(APPEND _sapi_full_inputs "${src}")
|
||||||
@ -149,7 +149,7 @@ function(add_sapi_library)
|
|||||||
)
|
)
|
||||||
else()
|
else()
|
||||||
set(_sapi_isystem "${_sapi_NAME}.isystem")
|
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(
|
add_custom_command(
|
||||||
OUTPUT "${_sapi_gen_header}" "${_sapi_isystem}"
|
OUTPUT "${_sapi_gen_header}" "${_sapi_isystem}"
|
||||||
COMMAND sh -c
|
COMMAND sh -c
|
||||||
|
@ -35,16 +35,6 @@ function(create_directory_symlink SOURCE DESTINATION)
|
|||||||
endif()
|
endif()
|
||||||
endfunction()
|
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(),
|
# Helper function that behaves just like Protobuf's protobuf_generate_cpp(),
|
||||||
# except that it strips import paths. This is necessary, because CMake's
|
# except that it strips import paths. This is necessary, because CMake's
|
||||||
# protobuf rules don't work well with imports across different directories.
|
# protobuf rules don't work well with imports across different directories.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user