From dc891f72996b2e46d38c4665d279f367cdb76a09 Mon Sep 17 00:00:00 2001 From: Philip Rideout Date: Mon, 13 Jul 2020 14:17:10 -0700 Subject: [PATCH] CMake: specify -fPIC at root level. Fixes #1881. --- CMakeLists.txt | 6 ++++++ filament/backend/CMakeLists.txt | 5 ----- java/gltfio/CMakeLists.txt | 2 -- libs/bluegl/CMakeLists.txt | 7 ------- libs/bluevk/CMakeLists.txt | 4 ---- libs/filabridge/CMakeLists.txt | 7 ------- libs/filaflat/CMakeLists.txt | 1 - libs/filamat/CMakeLists.txt | 2 -- libs/filamentapp/CMakeLists.txt | 4 ---- libs/geometry/CMakeLists.txt | 4 ---- libs/gltfio/CMakeLists.txt | 2 -- libs/ibl/CMakeLists.txt | 2 +- libs/matdbg/CMakeLists.txt | 2 -- libs/utils/CMakeLists.txt | 1 - 14 files changed, 7 insertions(+), 42 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3eef6ec6b1..1ed412a508 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -230,6 +230,12 @@ if (LINUX) link_libraries(libc++.a) link_libraries(libc++abi.a) endif() + + # Only linux, clang doesn't want to use a shared library that is not PIC. + # /usr/bin/ld: ../bluegl/libbluegl.a(BlueGL.cpp.o): relocation R_X86_64_32S + # against `.bss' can not be used when making a shared object; recompile with -fPIC + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") + endif() if (CYGWIN) diff --git a/filament/backend/CMakeLists.txt b/filament/backend/CMakeLists.txt index 04ab2d7cdd..bf636fc1ef 100644 --- a/filament/backend/CMakeLists.txt +++ b/filament/backend/CMakeLists.txt @@ -254,10 +254,6 @@ set(LINUX_LINKER_OPTIMIZATION_FLAGS -Wl,--exclude-libs,bluegl ) -set(LINUX_COMPILER_FLAGS - -fPIC -) - if (MSVC) set(FILAMENT_WARNINGS /W3) else() @@ -279,7 +275,6 @@ target_compile_options(${TARGET} PRIVATE ${FILAMENT_WARNINGS} $<$:${OPTIMIZATION_FLAGS}> $<$,$>:${DARWIN_OPTIMIZATION_FLAGS}> - $<$:${LINUX_COMPILER_FLAGS}> ) target_link_libraries(${TARGET} PRIVATE diff --git a/java/gltfio/CMakeLists.txt b/java/gltfio/CMakeLists.txt index 4f1669ad3d..0a862ecec9 100644 --- a/java/gltfio/CMakeLists.txt +++ b/java/gltfio/CMakeLists.txt @@ -53,8 +53,6 @@ set(JNI_SOURCE_FILES add_library(${TARGET} SHARED ${JNI_SOURCE_FILES}) target_link_libraries(${TARGET} gltfio_core gltfio_resources) -target_compile_options(${TARGET} PRIVATE $<$:-fPIC>) - set(INSTALL_TYPE LIBRARY) if (WIN32 OR CYGWIN) set(INSTALL_TYPE RUNTIME) diff --git a/libs/bluegl/CMakeLists.txt b/libs/bluegl/CMakeLists.txt index d63cb4e7d0..c5e6af1311 100644 --- a/libs/bluegl/CMakeLists.txt +++ b/libs/bluegl/CMakeLists.txt @@ -34,13 +34,6 @@ if (NOT WIN32) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden") endif() -# Only linux, clang doesn't want to use a shared library that is not PIC. -# /usr/bin/ld: ../bluegl/libbluegl.a(BlueGL.cpp.o): relocation R_X86_64_32S -# against `.bss' can not be used when making a shared object; recompile with -fPIC -if (LINUX) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") -endif() - # specify where our headers are include_directories(${PUBLIC_HDR_DIR}) diff --git a/libs/bluevk/CMakeLists.txt b/libs/bluevk/CMakeLists.txt index bfd06c7d44..b6c72af387 100644 --- a/libs/bluevk/CMakeLists.txt +++ b/libs/bluevk/CMakeLists.txt @@ -21,10 +21,6 @@ endif() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden") -if (LINUX) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") -endif() - include_directories(${PUBLIC_HDR_DIR}) add_library(${TARGET} STATIC ${PUBLIC_HDRS} ${SRCS}) diff --git a/libs/filabridge/CMakeLists.txt b/libs/filabridge/CMakeLists.txt index 2e49a6286f..bef8f198cf 100644 --- a/libs/filabridge/CMakeLists.txt +++ b/libs/filabridge/CMakeLists.txt @@ -29,13 +29,6 @@ target_link_libraries(${TARGET} utils) target_link_libraries(${TARGET} math) target_link_libraries(${TARGET} backend_headers) -# ================================================================================================== -# Compiler flags -# ================================================================================================== -if (NOT WIN32) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") -endif() - # ================================================================================================== # Installation # ================================================================================================== diff --git a/libs/filaflat/CMakeLists.txt b/libs/filaflat/CMakeLists.txt index 591321499d..e3b4be7a65 100644 --- a/libs/filaflat/CMakeLists.txt +++ b/libs/filaflat/CMakeLists.txt @@ -36,7 +36,6 @@ endif() if (NOT WIN32) target_compile_options(${TARGET} PRIVATE -fvisibility=hidden - $<$:-fPIC> ) endif() diff --git a/libs/filamat/CMakeLists.txt b/libs/filamat/CMakeLists.txt index 4efeda8a21..111c8a14c9 100644 --- a/libs/filamat/CMakeLists.txt +++ b/libs/filamat/CMakeLists.txt @@ -114,13 +114,11 @@ target_compile_options(${TARGET} PRIVATE -DAMD_EXTENSIONS -DNV_EXTENSIONS ) target_compile_options(${TARGET} PRIVATE # TODO: use hidden by default and expose what we need (we'll need to do the same in dependencies) # -fvisibility=hidden - $<$:-fPIC> ) target_compile_options(filamat_lite PRIVATE # TODO: use hidden by default and expose what we need (we'll need to do the same in dependencies) # -fvisibility=hidden - $<$:-fPIC> ) target_compile_definitions(filamat_lite PRIVATE FILAMAT_LITE) diff --git a/libs/filamentapp/CMakeLists.txt b/libs/filamentapp/CMakeLists.txt index 508f47da94..2907ab9a7a 100644 --- a/libs/filamentapp/CMakeLists.txt +++ b/libs/filamentapp/CMakeLists.txt @@ -153,7 +153,3 @@ if (_isMultiConfig) else() target_compile_definitions(${TARGET} PRIVATE RELATIVE_ASSET_PATH=".") endif() - -if (LINUX) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") -endif() diff --git a/libs/geometry/CMakeLists.txt b/libs/geometry/CMakeLists.txt index 3482defe31..e755177f5b 100644 --- a/libs/geometry/CMakeLists.txt +++ b/libs/geometry/CMakeLists.txt @@ -36,10 +36,6 @@ else() target_compile_options(${TARGET} PRIVATE -Wno-deprecated-register) endif() -if (LINUX) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") -endif() - # ================================================================================================== # Installation # ================================================================================================== diff --git a/libs/gltfio/CMakeLists.txt b/libs/gltfio/CMakeLists.txt index 3c95c3c84e..a7e4a9db8b 100644 --- a/libs/gltfio/CMakeLists.txt +++ b/libs/gltfio/CMakeLists.txt @@ -163,7 +163,6 @@ link_libraries(math utils filament cgltf stb geometry gltfio_resources tsl trie) add_library(gltfio_core STATIC ${PUBLIC_HDRS} ${SRCS}) target_include_directories(gltfio_core PUBLIC ${PUBLIC_HDR_DIR}) -target_compile_options(gltfio_core PRIVATE $<$:-fPIC>) target_compile_definitions(gltfio_core PUBLIC -DGLTFIO_DRACO_SUPPORTED=1) target_link_libraries(gltfio_core PUBLIC dracodec) @@ -186,7 +185,6 @@ if (NOT WEBGL AND NOT ANDROID AND NOT IOS) target_compile_options(${TARGET} PRIVATE $<$:-ffast-math>) target_compile_options(${TARGET} PRIVATE -Wno-deprecated-register) endif() - target_compile_options(${TARGET} PRIVATE $<$:-fPIC>) # ================================================================================================== # Installation diff --git a/libs/ibl/CMakeLists.txt b/libs/ibl/CMakeLists.txt index 8094b507ab..1679b9aa87 100644 --- a/libs/ibl/CMakeLists.txt +++ b/libs/ibl/CMakeLists.txt @@ -44,7 +44,7 @@ target_link_libraries(${TARGET} math utils) if (MSVC) target_compile_options(${TARGET} PRIVATE /fp:fast) else() - target_compile_options(${TARGET} PRIVATE -ffast-math $<$:-fPIC>) + target_compile_options(${TARGET} PRIVATE -ffast-math) endif() diff --git a/libs/matdbg/CMakeLists.txt b/libs/matdbg/CMakeLists.txt index 784d6c4e7b..e57af9754e 100644 --- a/libs/matdbg/CMakeLists.txt +++ b/libs/matdbg/CMakeLists.txt @@ -87,8 +87,6 @@ target_include_directories(${TARGET} PUBLIC ${PUBLIC_HDR_DIR}) # Compiler flags # ================================================================================================== -target_compile_options(${TARGET} PRIVATE $<$:-fPIC>) - if (MSVC) target_compile_options(${TARGET} PRIVATE $<$:/fp:fast>) else() diff --git a/libs/utils/CMakeLists.txt b/libs/utils/CMakeLists.txt index 3d7e544a97..0cf9059e5c 100644 --- a/libs/utils/CMakeLists.txt +++ b/libs/utils/CMakeLists.txt @@ -104,7 +104,6 @@ target_compile_options(${TARGET} PRIVATE # TODO: use hidden by default and expose what we need # -fvisibility=hidden # -fvisibility-inlines-hidden - $<$:-fPIC> ) # ==================================================================================================