Skip to content

Commit 3fbdfb8

Browse files
committed
Cleanup CMake logic
1 parent f5700ae commit 3fbdfb8

1 file changed

Lines changed: 20 additions & 17 deletions

File tree

cmake/dependencies/catch.cmake

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
function(catch_preconfigure)
2+
set(_old_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})
3+
set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
4+
endfunction()
5+
6+
function(catch_postconfigure)
7+
set(BUILD_SHARED_LIBS ${_old_BUILD_SHARED_LIBS})
8+
# Mark Catch2 as system code to suppress warnings and set position independent code
9+
# Ensure Catch2 is built with PIC so it can be linked into shared libraries
10+
set_target_properties(Catch2 PROPERTIES
11+
POSITION_INDEPENDENT_CODE ON
12+
INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "$<TARGET_PROPERTY:Catch2,INTERFACE_INCLUDE_DIRECTORIES>"
13+
)
14+
unset(_old_BUILD_SHARED_LIBS)
15+
endfunction()
16+
117
function(find_catch2)
218
if(TARGET Catch2::Catch2)
319
message(STATUS "Catch2::Catch2 target already imported")
@@ -19,22 +35,14 @@ function(find_catch2)
1935
if(TARGET Catch2::Catch2)
2036
# nothing to do, target already exists in the superbuild
2137
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(_old_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})
24-
set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
38+
catch_preconfigure()
2539
add_subdirectory(${openPMD_catch_src} _deps/localCatch2-build/)
26-
set(BUILD_SHARED_LIBS ${_old_BUILD_SHARED_LIBS})
27-
# Mark Catch2 as system code to suppress warnings and set position independent code
28-
set_target_properties(Catch2 PROPERTIES
29-
POSITION_INDEPENDENT_CODE ON
30-
INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "$<TARGET_PROPERTY:Catch2,INTERFACE_INCLUDE_DIRECTORIES>"
31-
)
40+
catch_postconfigure()
3241
if(CMAKE_CXX_CLANG_TIDY)
3342
set_target_properties(Catch2 PROPERTIES CXX_CLANG_TIDY "")
3443
endif()
3544
elseif(openPMD_USE_INTERNAL_CATCH AND (openPMD_catch_tar OR openPMD_catch_branch))
36-
set(_old_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})
37-
set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
45+
catch_preconfigure()
3846
include(FetchContent)
3947
if(openPMD_catch_tar)
4048
FetchContent_Declare(fetchedCatch2
@@ -50,12 +58,7 @@ function(find_catch2)
5058
)
5159
endif()
5260
FetchContent_MakeAvailable(fetchedCatch2)
53-
set(BUILD_SHARED_LIBS ${_old_BUILD_SHARED_LIBS})
54-
# Ensure Catch2 is built with PIC and mark as system code to suppress warnings
55-
set_target_properties(Catch2 PROPERTIES
56-
POSITION_INDEPENDENT_CODE ON
57-
INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "$<TARGET_PROPERTY:Catch2,INTERFACE_INCLUDE_DIRECTORIES>"
58-
)
61+
catch_postconfigure()
5962
if(CMAKE_CXX_CLANG_TIDY)
6063
set_target_properties(Catch2 PROPERTIES CXX_CLANG_TIDY "")
6164
endif()

0 commit comments

Comments
 (0)