Progmasoft Git

catch3

Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.

Clonegit clone https://git.progmasoft.com/catch3

Don't build Catch2WithMain target by default for v2

The `Catch2WithMain` target was added experimentally for v2.13.4
to provide potentially better compilation (and link) times to users.
However, having it compiled by default causes worse experience for
people who do not use it, and for the v2 versions the single include
distribution is still the main one.

Closes #2142
Commit
cec35630fb08ce9631a92e7a06c9b655a850caa8
Author
Martin Hořeňovský ·
Parents
b8b03da534ef

Files · Download .tar.gz

Changes

 CMakeLists.txt | 30 +++++++++++++++++++-----------
 1 file changed, 19 insertions(+), 11 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 05acead3..727aa186 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -25,12 +25,12 @@ option(CATCH_USE_VALGRIND "Perform SelfTests with Valgrind" OFF)
 option(CATCH_BUILD_TESTING "Build SelfTest project" ON)
 option(CATCH_BUILD_EXAMPLES "Build documentation examples" OFF)
 option(CATCH_BUILD_EXTRA_TESTS "Build extra tests" OFF)
+option(CATCH_BUILD_STATIC_LIBRARY "Builds static library from the main implementation. EXPERIMENTAL" OFF)
 option(CATCH_ENABLE_COVERAGE "Generate coverage for codecov.io" OFF)
 option(CATCH_ENABLE_WERROR "Enable all warnings as errors" ON)
 option(CATCH_INSTALL_DOCS "Install documentation alongside library" ON)
 option(CATCH_INSTALL_HELPERS "Install contrib alongside library" ON)
 
-
 # define some folders
 set(CATCH_DIR ${CMAKE_CURRENT_SOURCE_DIR})
 set(SELF_TEST_DIR ${CATCH_DIR}/projects/SelfTest)
@@ -104,15 +104,17 @@ endif()
 add_library(Catch2::Catch2 ALIAS Catch2)
 
 # Hacky support for compiling the impl into a static lib
-add_library(Catch2WithMain ${CMAKE_CURRENT_LIST_DIR}/src/catch_with_main.cpp)
-target_link_libraries(Catch2WithMain PUBLIC Catch2)
-add_library(Catch2::Catch2WithMain ALIAS Catch2WithMain)
-
-# Make the build reproducible on versions of g++ and clang that supports -ffile-prefix-map
-if(("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND NOT ${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 8) OR
-   ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND NOT ${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 10))
-  target_compile_options(Catch2WithMain PRIVATE "-ffile-prefix-map=${CMAKE_SOURCE_DIR}=.")
-endif()
+if (CATCH_BUILD_STATIC_LIBRARY)
+  add_library(Catch2WithMain ${CMAKE_CURRENT_LIST_DIR}/src/catch_with_main.cpp)
+  target_link_libraries(Catch2WithMain PUBLIC Catch2)
+  add_library(Catch2::Catch2WithMain ALIAS Catch2WithMain)
+
+  # Make the build reproducible on versions of g++ and clang that supports -ffile-prefix-map
+  if(("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND NOT ${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 8) OR
+     ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND NOT ${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 10))
+    target_compile_options(Catch2WithMain PRIVATE "-ffile-prefix-map=${CMAKE_SOURCE_DIR}=.")
+  endif()
+endif(CATCH_BUILD_STATIC_LIBRARY)
 
 # Only perform the installation steps when Catch is not being used as
 # a subproject via `add_subdirectory`, or the destinations will break,
@@ -128,11 +130,17 @@ if (NOT_SUBPROJECT)
           ${CATCH_CMAKE_CONFIG_DESTINATION}
     )
 
+    # Workaround lack of generator expressions in install(TARGETS
+    set(InstallationTargets Catch2)
+    if (TARGET Catch2WithMain)
+      list(APPEND InstallationTargets Catch2WithMain)
+    endif()
+
 
     # create and install an export set for catch target as Catch2::Catch
     install(
       TARGETS
-        Catch2 Catch2WithMain
+        ${InstallationTargets}
       EXPORT
         Catch2Targets
       DESTINATION