CMake: Properly inherit sapi_base propterties

- `SKIP_BUILD_RPATH` needs to be set per directory (not allow-listed for
  `INTERFACE` properties)
- Use correct name for position independent code
- `-pie`/`-fPIE` will only propagate fully on 3.14+

PiperOrigin-RevId: 428986266
Change-Id: Idf9d7fc184fbeec8ec1b77505246e262d9b8d880
This commit is contained in:
Christian Blichmann 2022-02-16 01:47:46 -08:00 committed by Copybara-Service
parent aefdb94575
commit cef861a0f2

View File

@ -44,7 +44,7 @@ endif()
include(CheckCXXCompilerFlag) include(CheckCXXCompilerFlag)
# Sapi CMake modules, order matters # SAPI CMake modules, order matters
list(APPEND CMAKE_MODULE_PATH "${SAPI_SOURCE_DIR}/cmake" list(APPEND CMAKE_MODULE_PATH "${SAPI_SOURCE_DIR}/cmake"
"${SAPI_SOURCE_DIR}/cmake/modules") "${SAPI_SOURCE_DIR}/cmake/modules")
include(SapiOptions) include(SapiOptions)
@ -56,6 +56,13 @@ include(GNUInstallDirs)
# Allow the header generator to auto-configure include paths # Allow the header generator to auto-configure include paths
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_SKIP_BUILD_RPATH ON)
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.14)
include(CheckPIESupported)
check_pie_supported()
endif()
if(SAPI_HARDENED_SOURCE) if(SAPI_HARDENED_SOURCE)
add_compile_options(-fstack-protector -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2) add_compile_options(-fstack-protector -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2)
add_link_options(-Wl,-z,relro -Wl,-z,now) add_link_options(-Wl,-z,relro -Wl,-z,now)
@ -76,7 +83,7 @@ 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 "") file(WRITE "${SAPI_BINARY_DIR}/sapi_base_force_cxx_linkage.cc" "")
add_library(sapi_base STATIC add_library(sapi_base STATIC
"${SAPI_BINARY_DIR}/sapi_base_force_cxx_linkage.cc" "${SAPI_BINARY_DIR}/sapi_base_force_cxx_linkage.cc"
) )
@ -85,8 +92,7 @@ target_compile_features(sapi_base PUBLIC
cxx_std_${SAPI_CXX_STANDARD} cxx_std_${SAPI_CXX_STANDARD}
) )
set_target_properties(sapi_base PROPERTIES set_target_properties(sapi_base PROPERTIES
SKIP_BUILD_RPATH ON INTERFACE_POSITION_INDEPENDENT_CODE ON
POSITION_INDEPENDENT_CODE ON
) )
target_include_directories(sapi_base PUBLIC target_include_directories(sapi_base PUBLIC
"${SAPI_BINARY_DIR}" "${SAPI_BINARY_DIR}"