Skip to content

Commit 418f1e6

Browse files
committed
CMake: -fPIC for Catch2
1 parent 2da91c4 commit 418f1e6

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

cmake/dependencies/catch.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,16 @@ function(find_catch2)
1919
if(TARGET Catch2::Catch2)
2020
# nothing to do, target already exists in the superbuild
2121
elseif(openPMD_USE_INTERNAL_CATCH AND openPMD_catch_src)
22+
# Ensure Catch2 is built with PIC so it can be linked into shared libraries
23+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
2224
add_subdirectory(${openPMD_catch_src} _deps/localCatch2-build/)
2325
elseif(openPMD_USE_INTERNAL_CATCH AND (openPMD_catch_tar OR openPMD_catch_branch))
2426
include(FetchContent)
27+
# Ensure Catch2 is built with PIC so it can be linked into shared libraries
28+
# Set as cache variable (only if not already set) so it's picked up by Catch2's CMakeLists.txt
29+
if(NOT DEFINED CMAKE_POSITION_INDEPENDENT_CODE)
30+
set(CMAKE_POSITION_INDEPENDENT_CODE ON CACHE BOOL "Position independent code")
31+
endif()
2532
if(openPMD_catch_tar)
2633
FetchContent_Declare(fetchedCatch2
2734
URL ${openPMD_catch_tar}

0 commit comments

Comments
 (0)