Skip to content

Commit

Permalink
Propagate CMake flags correctly
Browse files Browse the repository at this point in the history
* Refs 13853: Propagate BUILD_SHARED_LIBS and CMAKE_POSITION_INDEPENDENT_CODE correctly

Signed-off-by: Eduardo Ponz <eduardoponz@eprosima.com>

* Refs 13853: Apply suggestions

Signed-off-by: Eduardo Ponz <eduardoponz@eprosima.com>
  • Loading branch information
EduPonz authored Feb 22, 2022
1 parent da062db commit 6df3bcf
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,16 @@ if(NOT foonathan_memory_FOUND)
" or BUILD_MEMORY_TESTS are set")
endif()

if(BUILD_SHARED_LIBS)
# Library will be statically created with PIC code
list(APPEND extra_cmake_args -DCMAKE_POSITION_INDEPENDENT_CODE=ON)
# Propagate BUILD_SHARED_LIBS
if(DEFINED BUILD_SHARED_LIBS)
list(APPEND extra_cmake_args -DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS})
endif()

# Propagate CMAKE_POSITION_INDEPENDENT_CODE
if(DEFINED CMAKE_POSITION_INDEPENDENT_CODE)
list(APPEND extra_cmake_args -DCMAKE_POSITION_INDEPENDENT_CODE=${CMAKE_POSITION_INDEPENDENT_CODE})
elseif(BUILD_SHARED_LIBS)
list(APPEND extra_cmake_args -DCMAKE_POSITION_INDEPENDENT_CODE=ON})
endif()

if(DEFINED CMAKE_BUILD_TYPE)
Expand Down

0 comments on commit 6df3bcf

Please sign in to comment.