1
0
mirror of https://github.com/google/cpu_features.git synced 2025-04-27 23:22:31 +02:00

cmake: Use of CMAKE_POSITION_INDEPENDENT_CODE instead of BUILD_PIC (Fix #143)

This commit is contained in:
Corentin Le Molgat 2021-10-25 11:10:00 +02:00 committed by Mizux
parent 769287c384
commit 545b2e84ec

View File

@ -23,13 +23,11 @@ endif(NOT CMAKE_BUILD_TYPE)
# As a consequence it is discouraged to use cpu_features as a shared library because different compilers may interpret the code in different ways. # As a consequence it is discouraged to use cpu_features as a shared library because different compilers may interpret the code in different ways.
# Prefer static linking from source whenever possible. # Prefer static linking from source whenever possible.
option(BUILD_SHARED_LIBS "Build library as shared." OFF) option(BUILD_SHARED_LIBS "Build library as shared." OFF)
# PIC
option(BUILD_PIC "Build with Position Independant Code." OFF) # Default is off at least for GCC
# Force PIC on unix when building shared libs # Force PIC on unix when building shared libs
# see: https://en.wikipedia.org/wiki/Position-independent_code # see: https://en.wikipedia.org/wiki/Position-independent_code
if(BUILD_SHARED_LIBS AND UNIX) if(BUILD_SHARED_LIBS AND UNIX)
set(BUILD_PIC ON) option(CMAKE_POSITION_INDEPENDENT_CODE "Build with Position Independant Code." ON)
endif() endif()
include(CheckIncludeFile) include(CheckIncludeFile)
@ -101,7 +99,6 @@ add_library(utils OBJECT
${PROJECT_SOURCE_DIR}/src/stack_line_reader.c ${PROJECT_SOURCE_DIR}/src/stack_line_reader.c
${PROJECT_SOURCE_DIR}/src/string_view.c ${PROJECT_SOURCE_DIR}/src/string_view.c
) )
set_property(TARGET utils PROPERTY POSITION_INDEPENDENT_CODE ${BUILD_PIC})
setup_include_and_definitions(utils) setup_include_and_definitions(utils)
# #
@ -122,7 +119,6 @@ if(UNIX)
if(HAVE_STRONG_GETAUXVAL) if(HAVE_STRONG_GETAUXVAL)
target_compile_definitions(unix_based_hardware_detection PRIVATE HAVE_STRONG_GETAUXVAL) target_compile_definitions(unix_based_hardware_detection PRIVATE HAVE_STRONG_GETAUXVAL)
endif() endif()
set_property(TARGET unix_based_hardware_detection PROPERTY POSITION_INDEPENDENT_CODE ${BUILD_PIC})
endif() endif()
# #
@ -139,7 +135,6 @@ add_library(cpu_features ${CPU_FEATURES_HDRS} ${CPU_FEATURES_SRCS})
set_target_properties(cpu_features PROPERTIES PUBLIC_HEADER "${CPU_FEATURES_HDRS}") set_target_properties(cpu_features PROPERTIES PUBLIC_HEADER "${CPU_FEATURES_HDRS}")
setup_include_and_definitions(cpu_features) setup_include_and_definitions(cpu_features)
target_link_libraries(cpu_features PUBLIC ${CMAKE_DL_LIBS}) target_link_libraries(cpu_features PUBLIC ${CMAKE_DL_LIBS})
set_property(TARGET cpu_features PROPERTY POSITION_INDEPENDENT_CODE ${BUILD_PIC})
target_include_directories(cpu_features target_include_directories(cpu_features
PUBLIC $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/cpu_features> PUBLIC $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/cpu_features>
) )