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)