mirror of
https://github.com/google/sandboxed-api.git
synced 2024-03-22 13:11:30 +08:00
cmake: Use configure_file()
to implement forced C++ linkage
This finally prevents Ninja from rebuilding everything needlessly each time a CMake reconfiguration was triggered. The root cause is that we used `file(WRITE ...)`, which always unconditionally overwrites, so Ninja sees those files as "dirty". PiperOrigin-RevId: 453849514 Change-Id: Ib878df21371387baa7bf791a0a054e1ea5d6b6ae
This commit is contained in:
parent
598b00103a
commit
de836031d4
|
@ -90,9 +90,10 @@ configure_file(cmake/libcap_capability.h.in
|
||||||
|
|
||||||
# Library with basic project settings. The empty file is there to be able to
|
# Library with basic project settings. The empty file is there to be able to
|
||||||
# define header-only libraries without cumbersome target_sources() hacks.
|
# define header-only libraries without cumbersome target_sources() hacks.
|
||||||
file(WRITE "${SAPI_BINARY_DIR}/sapi_base_force_cxx_linkage.cc" "")
|
configure_file(cmake/sapi_force_cxx_linkage.cc.in
|
||||||
|
"${SAPI_BINARY_DIR}/sapi_force_cxx_linkage.cc" COPYONLY)
|
||||||
add_library(sapi_base STATIC
|
add_library(sapi_base STATIC
|
||||||
"${SAPI_BINARY_DIR}/sapi_base_force_cxx_linkage.cc"
|
"${SAPI_BINARY_DIR}/sapi_force_cxx_linkage.cc"
|
||||||
)
|
)
|
||||||
add_library(sapi::base ALIAS sapi_base)
|
add_library(sapi::base ALIAS sapi_base)
|
||||||
target_compile_features(sapi_base PUBLIC
|
target_compile_features(sapi_base PUBLIC
|
||||||
|
|
|
@ -111,10 +111,9 @@ function(add_sapi_library)
|
||||||
|
|
||||||
# The sandboxed binary
|
# The sandboxed binary
|
||||||
set(_sapi_bin "${_sapi_NAME}.bin")
|
set(_sapi_bin "${_sapi_NAME}.bin")
|
||||||
set(_sapi_force_cxx_linkage
|
add_executable("${_sapi_bin}"
|
||||||
"${CMAKE_CURRENT_BINARY_DIR}/${_sapi_bin}_force_cxx_linkage.cc")
|
"${SAPI_BINARY_DIR}/sapi_force_cxx_linkage.cc"
|
||||||
file(WRITE "${_sapi_force_cxx_linkage}" "")
|
)
|
||||||
add_executable("${_sapi_bin}" "${_sapi_force_cxx_linkage}")
|
|
||||||
target_link_libraries("${_sapi_bin}" PRIVATE
|
target_link_libraries("${_sapi_bin}" PRIVATE
|
||||||
-fuse-ld=gold
|
-fuse-ld=gold
|
||||||
-Wl,--whole-archive "${_sapi_LIBRARY}" -Wl,--no-whole-archive
|
-Wl,--whole-archive "${_sapi_LIBRARY}" -Wl,--no-whole-archive
|
||||||
|
@ -192,10 +191,9 @@ function(add_sapi_library)
|
||||||
|
|
||||||
# Library with the interface
|
# Library with the interface
|
||||||
if(NOT _sapi_SOURCES)
|
if(NOT _sapi_SOURCES)
|
||||||
set(_sapi_force_cxx_linkage
|
list(APPEND _sapi_SOURCES
|
||||||
"${CMAKE_CURRENT_BINARY_DIR}/${_sapi_NAME}_force_cxx_linkage.cc")
|
"${SAPI_BINARY_DIR}/sapi_force_cxx_linkage.cc"
|
||||||
file(WRITE "${_sapi_force_cxx_linkage}" "")
|
)
|
||||||
list(APPEND _sapi_SOURCES "${_sapi_force_cxx_linkage}")
|
|
||||||
endif()
|
endif()
|
||||||
add_library("${_sapi_NAME}" STATIC
|
add_library("${_sapi_NAME}" STATIC
|
||||||
"${_sapi_gen_header}"
|
"${_sapi_gen_header}"
|
||||||
|
|
0
cmake/sapi_force_cxx_linkage.cc.in
Normal file
0
cmake/sapi_force_cxx_linkage.cc.in
Normal file
|
@ -48,10 +48,9 @@ target_link_libraries(sapi_util_fileops PRIVATE
|
||||||
)
|
)
|
||||||
|
|
||||||
# sandboxed_api/util:flag
|
# sandboxed_api/util:flag
|
||||||
file(WRITE "${SAPI_BINARY_DIR}/sapi_util_flags_force_cxx_linkage.cc" "")
|
|
||||||
add_library(sapi_util_flags ${SAPI_LIB_TYPE}
|
add_library(sapi_util_flags ${SAPI_LIB_TYPE}
|
||||||
flag.h
|
flag.h
|
||||||
"${SAPI_BINARY_DIR}/sapi_util_flags_force_cxx_linkage.cc"
|
"${SAPI_BINARY_DIR}/sapi_force_cxx_linkage.cc"
|
||||||
)
|
)
|
||||||
add_library(sapi::flags ALIAS sapi_util_flags)
|
add_library(sapi::flags ALIAS sapi_util_flags)
|
||||||
target_link_libraries(sapi_util_flags PUBLIC
|
target_link_libraries(sapi_util_flags PUBLIC
|
||||||
|
|
Loading…
Reference in New Issue
Block a user