Skip to content

Commit bea58bf

Browse files
committed
Allow building Catch2 as dynamic library
Also have a check that warns users if they try to combined dynamic library with hidden visibility, which we do not support. Closes #2397 Closes #2398
1 parent 34d9724 commit bea58bf

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/CMakeLists.txt

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,7 @@ set(REPORTER_SOURCES
285285
)
286286
set(REPORTER_FILES ${REPORTER_HEADERS} ${REPORTER_SOURCES})
287287

288-
# Fixme: STATIC because for dynamic, we would need to handle visibility
289-
# and I don't want to do the annotations right now
290-
add_library(Catch2 STATIC
288+
add_library(Catch2
291289
${REPORTER_FILES}
292290
${INTERNAL_FILES}
293291
${BENCHMARK_HEADERS}
@@ -340,7 +338,7 @@ target_include_directories(Catch2
340338
)
341339

342340

343-
add_library(Catch2WithMain STATIC
341+
add_library(Catch2WithMain
344342
${SOURCES_DIR}/internal/catch_main.cpp
345343
)
346344
add_build_reproducibility_settings(Catch2WithMain)
@@ -431,3 +429,20 @@ endif()
431429

432430
list(APPEND CATCH_WARNING_TARGETS Catch2 Catch2WithMain)
433431
set(CATCH_WARNING_TARGETS ${CATCH_WARNING_TARGETS} PARENT_SCOPE)
432+
433+
434+
# We still do not support building dynamic library with hidden visibility
435+
# so we want to check & warn users if they do this. However, we won't abort
436+
# the configuration step so that we don't have to also provide an override.
437+
if (BUILD_SHARED_LIBS)
438+
get_target_property(_VisPreset Catch2 CXX_VISIBILITY_PRESET)
439+
get_target_property(_ExportAll Catch2 WINDOWS_EXPORT_ALL_SYMBOLS)
440+
if (MSVC AND NOT _ExportAll
441+
OR _VisPreset STREQUAL "hidden")
442+
443+
message(WARNING
444+
"Catch2 does not support being built as a dynamic library with hidden"
445+
" visibility. You have to ensure that visibility is handled yourself."
446+
)
447+
endif()
448+
endif()

0 commit comments

Comments
 (0)