Skip to content

Commit 7806502

Browse files
WilliamTambellinigchatelet
authored andcommitted
Add PIC option (#66)
1 parent 9613390 commit 7806502

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ endif(NOT CMAKE_BUILD_TYPE)
1414
option(BUILD_TESTING "Enable test (depends on googletest)." OFF)
1515
# BUILD_SHARED_LIBS is a standard CMake variable, but we declare it here to make
1616
# it prominent in the GUI.
17+
# cpu_features uses bit-fields which are - to some extends - implementation-defined (see https://en.cppreference.com/w/c/language/bit_field).
18+
# As a consequence it is discouraged to use cpu_features as a shared library because different compilers may interpret the code in different ways.
19+
# Prefer static linking from source whenever possible.
1720
option(BUILD_SHARED_LIBS "Build library as shared." OFF)
21+
# PIC
22+
option(BUILD_PIC "Build with Position Independant Code." OFF) # Default is off at least for GCC
1823

1924
include(CheckIncludeFile)
2025
include(CheckSymbolExists)
@@ -106,6 +111,7 @@ if(UNIX)
106111
if(HAVE_STRONG_GETAUXVAL)
107112
target_compile_definitions(unix_based_hardware_detection PRIVATE HAVE_STRONG_GETAUXVAL)
108113
endif()
114+
set_property(TARGET unix_based_hardware_detection PROPERTY POSITION_INDEPENDENT_CODE ${BUILD_PIC})
109115
endif()
110116

111117
#
@@ -122,6 +128,7 @@ add_library(cpu_features ${CPU_FEATURES_HDRS} ${CPU_FEATURES_SRCS})
122128
set_target_properties(cpu_features PROPERTIES PUBLIC_HEADER "${CPU_FEATURES_HDRS}")
123129
setup_include_and_definitions(cpu_features)
124130
target_link_libraries(cpu_features PUBLIC ${CMAKE_DL_LIBS})
131+
set_property(TARGET cpu_features PROPERTY POSITION_INDEPENDENT_CODE ${BUILD_PIC})
125132
target_include_directories(cpu_features
126133
PUBLIC $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/cpu_features>
127134
)

0 commit comments

Comments
 (0)