From 2e92358ca4b727f3109ecccf35ab96fbc5f4a064 Mon Sep 17 00:00:00 2001 From: Giovanni Petrantoni <7008900+sinkingsugar@users.noreply.github.com> Date: Sat, 18 Nov 2023 08:48:14 +0800 Subject: [PATCH] add fPIC only if CMAKE_POSITION_INDEPENDENT_CODE is ON --- cmake/compilers/Clang.cmake | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cmake/compilers/Clang.cmake b/cmake/compilers/Clang.cmake index 7ce4d46deb..15f2a39684 100644 --- a/cmake/compilers/Clang.cmake +++ b/cmake/compilers/Clang.cmake @@ -57,7 +57,11 @@ if (CMAKE_SYSTEM_PROCESSOR MATCHES "(AMD64|amd64|i.86|x86)") endif() # Clang flags to prevent compiler from optimizing out security checks -set(TBB_COMMON_COMPILE_FLAGS ${TBB_COMMON_COMPILE_FLAGS} -Wformat -Wformat-security -Werror=format-security -fPIC $<$>:-fstack-protector-strong>) +set(TBB_COMMON_COMPILE_FLAGS ${TBB_COMMON_COMPILE_FLAGS} -Wformat -Wformat-security -Werror=format-security $<$>:-fstack-protector-strong>) + +if(CMAKE_POSITION_INDEPENDENT_CODE) + set(TBB_COMMON_COMPILE_FLAGS ${TBB_COMMON_COMPILE_FLAGS} -fPIC) +endif() # -z switch is not supported on MacOS if (NOT APPLE)