Skip to content

Commit 7caa7ed

Browse files
committed
CMake: PIC an option, set canonically
1 parent d43b44a commit 7caa7ed

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ project(openlibm
99
LANGUAGES C ASM)
1010

1111
option(BUILD_SHARED_LIBS "Build using shared libraries" ON)
12+
option(openlibm_PIC "Build openlibm with position independent code" ON)
1213

1314
add_library("${PROJECT_NAME}")
1415

@@ -35,7 +36,7 @@ endif()
3536

3637
# Compile flags
3738
list(APPEND C_ASM_COMPILE_FLAGS "-ffp-contract=off" "-fno-fast-math" "-fno-rounding-math" "-fno-math-errno")
38-
list(APPEND C_ASM_COMPILE_FLAGS "-fPIC" "-fno-builtin")
39+
list(APPEND C_ASM_COMPILE_FLAGS "-fno-builtin")
3940
list(APPEND C_ASM_COMPILE_FLAGS "-Wall" "-Wno-implicit-function-declaration")
4041
list(APPEND C_ASM_COMPILE_FLAGS "-DASSEMBLER" "-D__BSD_VISIBLE" "-O3")
4142

@@ -539,10 +540,16 @@ target_sources("${PROJECT_NAME}" PRIVATE ${OPENLIBM_C_SOURCE}
539540
${OPENLIBM_ASM_SOURCE}
540541
)
541542

543+
if(openlibm_PIC)
544+
include(CheckPIESupported)
545+
check_pie_supported()
546+
endif()
547+
542548
set_target_properties("${PROJECT_NAME}" PROPERTIES
543549
C_STANDARD 99
544550
C_STANDARD_REQUIRED ON
545551
C_EXTENSIONS OFF
552+
POSITION_INDEPENDENT_CODE ${openlibm_PIC}
546553
)
547554

548555

0 commit comments

Comments
 (0)