From 981e12769881ca6b596b15595850c2b6751b4f6f Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Mon, 29 Jun 2020 14:06:35 +0100 Subject: [PATCH] CMake: Compile with -fPIC when building SOs Without this embedding static libraries into shared libraries may result in link time errors. Issue: #2283 --- CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index bb5205e..79bc1b8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -119,6 +119,9 @@ if(${CMAKE_CXX_COMPILER_ID} MATCHES "GNU") add_compile_options(-Wall -Wmaybe-uninitialized -Wuninitialized -Wunused -Wunused-local-typedefs -Wunused-parameter -Wunused-value -Wunused-variable -Wunused-but-set-parameter -Wunused-but-set-variable -fno-exceptions) add_compile_options(-Wno-reorder) # disable this from -Wall, since it happens all over. + if(BUILD_SHARED_LIBS) + add_compile_options(-fPIC) + endif() if(NOT ENABLE_RTTI) add_compile_options(-fno-rtti) endif() @@ -132,6 +135,9 @@ elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang" AND NOT MSVC) add_compile_options(-Wall -Wuninitialized -Wunused -Wunused-local-typedefs -Wunused-parameter -Wunused-value -Wunused-variable) add_compile_options(-Wno-reorder) # disable this from -Wall, since it happens all over. + if(BUILD_SHARED_LIBS) + add_compile_options(-fPIC) + endif() if(NOT ENABLE_RTTI) add_compile_options(-fno-rtti) endif() -- 2.7.4