Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChris Thrasher2025-04-07 22:09:59 -0600
committerChris Thrasher2025-04-26 10:38:36 -0600
commit8cfca70ae879ba59699b224e8d371b8bb9fa12ff (patch)
treee53b243d3d2b7acc41c27cbd21624e1e28b655cb
parent6aac11e17d4fe662e430a8bbfd4bf6886ca7f935 (diff)
downloadcatch3-8cfca70ae879ba59699b224e8d371b8bb9fa12ff.tar.gz
Fix formatting of CMake files
2 spaces seems to be the more common indentation level so that's what I unified around.
-rw-r--r--CMake/Catch2Config.cmake.in7
-rw-r--r--CMake/CatchConfigOptions.cmake5
-rw-r--r--CMake/CatchMiscFunctions.cmake181
-rw-r--r--CMakeLists.txt180
-rw-r--r--examples/CMakeLists.txt54
-rw-r--r--extras/Catch.cmake6
-rw-r--r--extras/CatchAddTests.cmake6
-rw-r--r--extras/CatchShardTests.cmake6
-rw-r--r--extras/CatchShardTestsImpl.cmake4
-rw-r--r--extras/ParseAndAddCatchTests.cmake304
-rw-r--r--fuzzing/CMakeLists.txt4
-rw-r--r--src/CMakeLists.txt161
-rw-r--r--tests/CMakeLists.txt326
-rw-r--r--tests/ExtraTests/CMakeLists.txt202
-rw-r--r--tests/TestScripts/DiscoverTests/CMakeLists.txt20
-rw-r--r--tools/misc/CMakeLists.txt5
16 files changed, 684 insertions, 787 deletions
diff --git a/CMake/Catch2Config.cmake.in b/CMake/Catch2Config.cmake.in
index c485219c..9268138a 100644
--- a/CMake/Catch2Config.cmake.in
+++ b/CMake/Catch2Config.cmake.in
@@ -1,10 +1,9 @@
@PACKAGE_INIT@
-
# Avoid repeatedly including the targets
if(NOT TARGET Catch2::Catch2)
- # Provide path for scripts
- list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
+ # Provide path for scripts
+ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
- include(${CMAKE_CURRENT_LIST_DIR}/Catch2Targets.cmake)
+ include(${CMAKE_CURRENT_LIST_DIR}/Catch2Targets.cmake)
endif()
diff --git a/CMake/CatchConfigOptions.cmake b/CMake/CatchConfigOptions.cmake
index a2f2870b..f61a9657 100644
--- a/CMake/CatchConfigOptions.cmake
+++ b/CMake/CatchConfigOptions.cmake
@@ -14,7 +14,6 @@
#
# For detailed docs look into docs/configuration.md
-
macro(AddOverridableConfigOption OptionBaseName)
option(CATCH_CONFIG_${OptionBaseName} "Read docs/configuration.md for details" OFF)
option(CATCH_CONFIG_NO_${OptionBaseName} "Read docs/configuration.md for details" OFF)
@@ -74,9 +73,9 @@ foreach(OptionName ${_OtherConfigOptions})
AddConfigOption(${OptionName})
endforeach()
if(DEFINED BUILD_SHARED_LIBS)
- set(CATCH_CONFIG_SHARED_LIBRARY ${BUILD_SHARED_LIBS})
+ set(CATCH_CONFIG_SHARED_LIBRARY ${BUILD_SHARED_LIBS})
else()
- set(CATCH_CONFIG_SHARED_LIBRARY "")
+ set(CATCH_CONFIG_SHARED_LIBRARY "")
endif()
set(CATCH_CONFIG_DEFAULT_REPORTER "console" CACHE STRING "Read docs/configuration.md for details. The name of the reporter should be without quotes.")
diff --git a/CMake/CatchMiscFunctions.cmake b/CMake/CatchMiscFunctions.cmake
index 05bc83c0..d1cf5fc2 100644
--- a/CMake/CatchMiscFunctions.cmake
+++ b/CMake/CatchMiscFunctions.cmake
@@ -8,108 +8,107 @@
include(CheckCXXCompilerFlag)
function(add_cxx_flag_if_supported_to_targets flagname targets)
- string(MAKE_C_IDENTIFIER ${flagname} flag_identifier )
- check_cxx_compiler_flag("${flagname}" HAVE_FLAG_${flag_identifier})
+ string(MAKE_C_IDENTIFIER ${flagname} flag_identifier)
+ check_cxx_compiler_flag("${flagname}" HAVE_FLAG_${flag_identifier})
- if (HAVE_FLAG_${flag_identifier})
- foreach(target ${targets})
- target_compile_options(${target} PRIVATE ${flagname})
- endforeach()
- endif()
+ if(HAVE_FLAG_${flag_identifier})
+ foreach(target ${targets})
+ target_compile_options(${target} PRIVATE ${flagname})
+ endforeach()
+ endif()
endfunction()
# Assumes that it is only called for development builds, where warnings
# and Werror is desired, so it also enables Werror.
function(add_warnings_to_targets targets)
- LIST(LENGTH targets TARGETS_LEN)
- # For now we just assume 2 possibilities: msvc and msvc-like compilers,
- # and other.
- if (MSVC)
- foreach(target ${targets})
- # Force MSVC to consider everything as encoded in utf-8
- target_compile_options( ${target} PRIVATE /utf-8 )
- # Enable Werror equivalent
- if (CATCH_ENABLE_WERROR)
- target_compile_options( ${target} PRIVATE /WX )
- endif()
-
- # MSVC is currently handled specially
- if ( CMAKE_CXX_COMPILER_ID MATCHES "MSVC" )
- STRING(REGEX REPLACE "/W[0-9]" "/W4" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) # override default warning level
- target_compile_options( ${target} PRIVATE /w44265 /w44061 /w44062 /w45038 )
- endif()
- endforeach()
+ LIST(LENGTH targets TARGETS_LEN)
+ # For now we just assume 2 possibilities: msvc and msvc-like compilers,
+ # and other.
+ if(MSVC)
+ foreach(target ${targets})
+ # Force MSVC to consider everything as encoded in utf-8
+ target_compile_options(${target} PRIVATE /utf-8)
+ # Enable Werror equivalent
+ if(CATCH_ENABLE_WERROR)
+ target_compile_options(${target} PRIVATE /WX)
+ endif()
- endif()
+ # MSVC is currently handled specially
+ if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
+ STRING(REGEX REPLACE "/W[0-9]" "/W4" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) # override default warning level
+ target_compile_options(${target} PRIVATE /w44265 /w44061 /w44062 /w45038)
+ endif()
+ endforeach()
+ endif()
- if (NOT MSVC)
- set(CHECKED_WARNING_FLAGS
- "-Wabsolute-value"
- "-Wall"
- "-Wcall-to-pure-virtual-from-ctor-dtor"
- "-Wcast-align"
- "-Wcatch-value"
- "-Wdangling"
- "-Wdeprecated"
- "-Wdeprecated-register"
- "-Wexceptions"
- "-Wexit-time-destructors"
- "-Wextra"
- "-Wextra-semi"
- "-Wfloat-equal"
- "-Wglobal-constructors"
- "-Winit-self"
- "-Wmisleading-indentation"
- "-Wmismatched-new-delete"
- "-Wmismatched-return-types"
- "-Wmismatched-tags"
- "-Wmissing-braces"
- "-Wmissing-declarations"
- "-Wmissing-noreturn"
- "-Wmissing-prototypes"
- "-Wmissing-variable-declarations"
- "-Wnon-virtual-dtor"
- "-Wnull-dereference"
- "-Wold-style-cast"
- "-Woverloaded-virtual"
- "-Wparentheses"
- "-Wpedantic"
- "-Wredundant-decls"
- "-Wreorder"
- "-Wreturn-std-move"
- "-Wshadow"
- "-Wstrict-aliasing"
- "-Wsubobject-linkage"
- "-Wsuggest-destructor-override"
- "-Wsuggest-override"
- "-Wundef"
- "-Wuninitialized"
- "-Wunneeded-internal-declaration"
- "-Wunreachable-code-aggressive"
- "-Wunused"
- "-Wunused-function"
- "-Wunused-parameter"
- "-Wvla"
- "-Wweak-vtables"
+ if(NOT MSVC)
+ set(CHECKED_WARNING_FLAGS
+ "-Wabsolute-value"
+ "-Wall"
+ "-Wcall-to-pure-virtual-from-ctor-dtor"
+ "-Wcast-align"
+ "-Wcatch-value"
+ "-Wdangling"
+ "-Wdeprecated"
+ "-Wdeprecated-register"
+ "-Wexceptions"
+ "-Wexit-time-destructors"
+ "-Wextra"
+ "-Wextra-semi"
+ "-Wfloat-equal"
+ "-Wglobal-constructors"
+ "-Winit-self"
+ "-Wmisleading-indentation"
+ "-Wmismatched-new-delete"
+ "-Wmismatched-return-types"
+ "-Wmismatched-tags"
+ "-Wmissing-braces"
+ "-Wmissing-declarations"
+ "-Wmissing-noreturn"
+ "-Wmissing-prototypes"
+ "-Wmissing-variable-declarations"
+ "-Wnon-virtual-dtor"
+ "-Wnull-dereference"
+ "-Wold-style-cast"
+ "-Woverloaded-virtual"
+ "-Wparentheses"
+ "-Wpedantic"
+ "-Wredundant-decls"
+ "-Wreorder"
+ "-Wreturn-std-move"
+ "-Wshadow"
+ "-Wstrict-aliasing"
+ "-Wsubobject-linkage"
+ "-Wsuggest-destructor-override"
+ "-Wsuggest-override"
+ "-Wundef"
+ "-Wuninitialized"
+ "-Wunneeded-internal-declaration"
+ "-Wunreachable-code-aggressive"
+ "-Wunused"
+ "-Wunused-function"
+ "-Wunused-parameter"
+ "-Wvla"
+ "-Wweak-vtables"
- # This is a useful warning, but our tests sometimes rely on
- # functions being present, but not picked (e.g. various checks
- # for stringification implementation ordering).
- # Ergo, we should use it every now and then, but we cannot
- # enable it by default.
- # "-Wunused-member-function"
- )
- foreach(warning ${CHECKED_WARNING_FLAGS})
- add_cxx_flag_if_supported_to_targets(${warning} "${targets}")
- endforeach()
+ # This is a useful warning, but our tests sometimes rely on
+ # functions being present, but not picked (e.g. various checks
+ # for stringification implementation ordering).
+ # Ergo, we should use it every now and then, but we cannot
+ # enable it by default.
+ # "-Wunused-member-function"
+ )
+ foreach(warning ${CHECKED_WARNING_FLAGS})
+ add_cxx_flag_if_supported_to_targets(${warning} "${targets}")
+ endforeach()
- if (CATCH_ENABLE_WERROR)
- foreach(target ${targets})
- # Enable Werror equivalent
- target_compile_options( ${target} PRIVATE -Werror )
- endforeach()
- endif()
+ if(CATCH_ENABLE_WERROR)
+ foreach(target ${targets})
+ # Enable Werror equivalent
+ target_compile_options(${target} PRIVATE -Werror)
+ endforeach()
endif()
+ endif()
endfunction()
# Adds flags required for reproducible build to the target
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0d8226b9..e6199081 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -26,12 +26,11 @@ cmake_dependent_option(CATCH_BUILD_SURROGATES "Enable generating and building su
cmake_dependent_option(CATCH_ENABLE_CONFIGURE_TESTS "Enable CMake configuration tests. WARNING: VERY EXPENSIVE" OFF "CATCH_DEVELOPMENT_BUILD" OFF)
cmake_dependent_option(CATCH_ENABLE_CMAKE_HELPER_TESTS "Enable CMake helper tests. WARNING: VERY EXPENSIVE" OFF "CATCH_DEVELOPMENT_BUILD" OFF)
-
# Catch2's build breaks if done in-tree. You probably should not build
# things in tree anyway, but we can allow projects that include Catch2
# as a subproject to build in-tree as long as it is not in our tree.
-if (CMAKE_BINARY_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
- message(FATAL_ERROR "Building in-source is not supported! Create a build dir and remove ${CMAKE_SOURCE_DIR}/CMakeCache.txt")
+if(CMAKE_BINARY_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
+ message(FATAL_ERROR "Building in-source is not supported! Create a build dir and remove ${CMAKE_SOURCE_DIR}/CMakeCache.txt")
endif()
project(Catch2
@@ -46,7 +45,7 @@ project(Catch2
# Then we also add path that we use to configure the project, but is of
# no use to top level projects.
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/extras")
-if (NOT NOT_SUBPROJECT)
+if(NOT NOT_SUBPROJECT)
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" PARENT_SCOPE)
endif()
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CMake")
@@ -67,10 +66,9 @@ set(CATCH_CMAKE_CONFIG_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Catch2")
# are built during these tests, so this is required here, before
# the subdirectories are added.
if(CATCH_TEST_USE_WMAIN)
- set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /ENTRY:wmainCRTStartup")
+ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /ENTRY:wmainCRTStartup")
endif()
-
# Basic paths
set(CATCH_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(SOURCES_DIR ${CATCH_DIR}/src/catch2)
@@ -80,119 +78,117 @@ set(SELF_TEST_DIR ${CATCH_DIR}/tests/SelfTest)
add_subdirectory(src)
# Build tests only if requested
-if (BUILD_TESTING AND CATCH_BUILD_TESTING AND NOT_SUBPROJECT)
- find_package(PythonInterp 3 REQUIRED)
- if (NOT PYTHONINTERP_FOUND)
- message(FATAL_ERROR "Python not found, but required for tests")
- endif()
- set(CMAKE_FOLDER "tests")
- add_subdirectory(tests)
+if(BUILD_TESTING AND CATCH_BUILD_TESTING AND NOT_SUBPROJECT)
+ find_package(PythonInterp 3 REQUIRED)
+ if(NOT PYTHONINTERP_FOUND)
+ message(FATAL_ERROR "Python not found, but required for tests")
+ endif()
+ set(CMAKE_FOLDER "tests")
+ add_subdirectory(tests)
endif()
if(CATCH_BUILD_EXAMPLES)
- set(CMAKE_FOLDER "Examples")
- add_subdirectory(examples)
+ set(CMAKE_FOLDER "Examples")
+ add_subdirectory(examples)
endif()
if(CATCH_BUILD_EXTRA_TESTS)
- set(CMAKE_FOLDER "tests/ExtraTests")
- add_subdirectory(tests/ExtraTests)
+ set(CMAKE_FOLDER "tests/ExtraTests")
+ add_subdirectory(tests/ExtraTests)
endif()
if(CATCH_BUILD_FUZZERS)
- set(CMAKE_FOLDER "fuzzing")
- add_subdirectory(fuzzing)
+ set(CMAKE_FOLDER "fuzzing")
+ add_subdirectory(fuzzing)
endif()
-if (CATCH_DEVELOPMENT_BUILD)
- add_warnings_to_targets("${CATCH_WARNING_TARGETS}")
+if(CATCH_DEVELOPMENT_BUILD)
+ add_warnings_to_targets("${CATCH_WARNING_TARGETS}")
endif()
# Only perform the installation steps when Catch is not being used as
# a subproject via `add_subdirectory`, or the destinations will break,
# see https://github.com/catchorg/Catch2/issues/1373
-if (NOT_SUBPROJECT)
- configure_package_config_file(
- ${CMAKE_CURRENT_LIST_DIR}/CMake/Catch2Config.cmake.in
- ${CMAKE_CURRENT_BINARY_DIR}/Catch2Config.cmake
- INSTALL_DESTINATION
- ${CATCH_CMAKE_CONFIG_DESTINATION}
- )
-
- write_basic_package_version_file(
+if(NOT_SUBPROJECT)
+ configure_package_config_file(
+ ${CMAKE_CURRENT_LIST_DIR}/CMake/Catch2Config.cmake.in
+ ${CMAKE_CURRENT_BINARY_DIR}/Catch2Config.cmake
+ INSTALL_DESTINATION
+ ${CATCH_CMAKE_CONFIG_DESTINATION}
+ )
+
+ write_basic_package_version_file(
+ "${CMAKE_CURRENT_BINARY_DIR}/Catch2ConfigVersion.cmake"
+ COMPATIBILITY
+ SameMajorVersion
+ )
+
+ install(
+ FILES
+ "${CMAKE_CURRENT_BINARY_DIR}/Catch2Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/Catch2ConfigVersion.cmake"
- COMPATIBILITY
- SameMajorVersion
+ DESTINATION
+ ${CATCH_CMAKE_CONFIG_DESTINATION}
+ )
+
+ # Install documentation
+ if(CATCH_INSTALL_DOCS)
+ install(
+ DIRECTORY
+ docs/
+ DESTINATION
+ "${CMAKE_INSTALL_DOCDIR}"
+ PATTERN "doxygen" EXCLUDE
)
+ endif()
+ if(CATCH_INSTALL_EXTRAS)
+ # Install CMake scripts
install(
FILES
- "${CMAKE_CURRENT_BINARY_DIR}/Catch2Config.cmake"
- "${CMAKE_CURRENT_BINARY_DIR}/Catch2ConfigVersion.cmake"
+ "extras/ParseAndAddCatchTests.cmake"
+ "extras/Catch.cmake"
+ "extras/CatchAddTests.cmake"
+ "extras/CatchShardTests.cmake"
+ "extras/CatchShardTestsImpl.cmake"
DESTINATION
${CATCH_CMAKE_CONFIG_DESTINATION}
)
- # Install documentation
- if(CATCH_INSTALL_DOCS)
- install(
- DIRECTORY
- docs/
- DESTINATION
- "${CMAKE_INSTALL_DOCDIR}"
- PATTERN "doxygen" EXCLUDE
- )
- endif()
-
- if(CATCH_INSTALL_EXTRAS)
- # Install CMake scripts
- install(
- FILES
- "extras/ParseAndAddCatchTests.cmake"
- "extras/Catch.cmake"
- "extras/CatchAddTests.cmake"
- "extras/CatchShardTests.cmake"
- "extras/CatchShardTestsImpl.cmake"
- DESTINATION
- ${CATCH_CMAKE_CONFIG_DESTINATION}
- )
-
- # Install debugger helpers
- install(
- FILES
- "extras/gdbinit"
- "extras/lldbinit"
- DESTINATION
- ${CMAKE_INSTALL_DATAROOTDIR}/Catch2
- )
- endif()
-
- ## Provide some pkg-config integration
- set(PKGCONFIG_INSTALL_DIR
- "${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig"
- CACHE PATH "Path where catch2.pc is installed"
- )
- configure_file(
- ${CMAKE_CURRENT_SOURCE_DIR}/CMake/catch2.pc.in
- ${CMAKE_CURRENT_BINARY_DIR}/catch2.pc
- @ONLY
- )
- configure_file(
- ${CMAKE_CURRENT_SOURCE_DIR}/CMake/catch2-with-main.pc.in
- ${CMAKE_CURRENT_BINARY_DIR}/catch2-with-main.pc
- @ONLY
- )
+ # Install debugger helpers
install(
FILES
- "${CMAKE_CURRENT_BINARY_DIR}/catch2.pc"
- "${CMAKE_CURRENT_BINARY_DIR}/catch2-with-main.pc"
+ "extras/gdbinit"
+ "extras/lldbinit"
DESTINATION
- ${PKGCONFIG_INSTALL_DIR}
+ ${CMAKE_INSTALL_DATAROOTDIR}/Catch2
)
-
- set(CPACK_PACKAGE_CONTACT "https://github.com/catchorg/Catch2/")
-
-
- include( CPack )
-
+ endif()
+
+ ## Provide some pkg-config integration
+ set(PKGCONFIG_INSTALL_DIR
+ "${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig"
+ CACHE PATH "Path where catch2.pc is installed"
+ )
+ configure_file(
+ ${CMAKE_CURRENT_SOURCE_DIR}/CMake/catch2.pc.in
+ ${CMAKE_CURRENT_BINARY_DIR}/catch2.pc
+ @ONLY
+ )
+ configure_file(
+ ${CMAKE_CURRENT_SOURCE_DIR}/CMake/catch2-with-main.pc.in
+ ${CMAKE_CURRENT_BINARY_DIR}/catch2-with-main.pc
+ @ONLY
+ )
+ install(
+ FILES
+ "${CMAKE_CURRENT_BINARY_DIR}/catch2.pc"
+ "${CMAKE_CURRENT_BINARY_DIR}/catch2-with-main.pc"
+ DESTINATION
+ ${PKGCONFIG_INSTALL_DIR}
+ )
+
+ set(CPACK_PACKAGE_CONTACT "https://github.com/catchorg/Catch2/")
+
+ include(CPack)
endif()
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index d45ddfcb..4035a025 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -1,50 +1,47 @@
-cmake_minimum_required( VERSION 3.16 )
-
-project( Catch2Examples LANGUAGES CXX )
-
-message( STATUS "Examples included" )
+cmake_minimum_required(VERSION 3.16)
+project(Catch2Examples LANGUAGES CXX)
+message(STATUS "Examples included")
# Some one-offs first:
# 1) Tests and main in one file
-add_executable( 010-TestCase
+add_executable(010-TestCase
010-TestCase.cpp
)
# 2) Tests and main across two files
-add_executable( 020-MultiFile
+add_executable(020-MultiFile
020-TestCase-1.cpp
020-TestCase-2.cpp
)
add_executable(231-Cfg_OutputStreams
- 231-Cfg-OutputStreams.cpp
+ 231-Cfg-OutputStreams.cpp
)
target_link_libraries(231-Cfg_OutputStreams Catch2_buildall_interface)
target_compile_definitions(231-Cfg_OutputStreams PUBLIC CATCH_CONFIG_NOSTDOUT)
# These examples use the standard separate compilation
-set( SOURCES_IDIOMATIC_EXAMPLES
- 030-Asn-Require-Check.cpp
- 100-Fix-Section.cpp
- 110-Fix-ClassFixture.cpp
- 111-Fix-PersistentFixture.cpp
- 120-Bdd-ScenarioGivenWhenThen.cpp
- 210-Evt-EventListeners.cpp
- 232-Cfg-CustomMain.cpp
- 300-Gen-OwnGenerator.cpp
- 301-Gen-MapTypeConversion.cpp
- 302-Gen-Table.cpp
- 310-Gen-VariablesInGenerators.cpp
- 311-Gen-CustomCapture.cpp
+set(SOURCES_IDIOMATIC_EXAMPLES
+ 030-Asn-Require-Check.cpp
+ 100-Fix-Section.cpp
+ 110-Fix-ClassFixture.cpp
+ 111-Fix-PersistentFixture.cpp
+ 120-Bdd-ScenarioGivenWhenThen.cpp
+ 210-Evt-EventListeners.cpp
+ 232-Cfg-CustomMain.cpp
+ 300-Gen-OwnGenerator.cpp
+ 301-Gen-MapTypeConversion.cpp
+ 302-Gen-Table.cpp
+ 310-Gen-VariablesInGenerators.cpp
+ 311-Gen-CustomCapture.cpp
)
-string( REPLACE ".cpp" "" BASENAMES_IDIOMATIC_EXAMPLES "${SOURCES_IDIOMATIC_EXAMPLES}" )
-set( TARGETS_IDIOMATIC_EXAMPLES ${BASENAMES_IDIOMATIC_EXAMPLES} )
+string(REPLACE ".cpp" "" BASENAMES_IDIOMATIC_EXAMPLES "${SOURCES_IDIOMATIC_EXAMPLES}")
+set(TARGETS_IDIOMATIC_EXAMPLES ${BASENAMES_IDIOMATIC_EXAMPLES})
-
-foreach( name ${TARGETS_IDIOMATIC_EXAMPLES} )
- add_executable( ${name} ${name}.cpp )
+foreach(name ${TARGETS_IDIOMATIC_EXAMPLES})
+ add_executable(${name} ${name}.cpp)
endforeach()
set(ALL_EXAMPLE_TARGETS
@@ -53,10 +50,9 @@ set(ALL_EXAMPLE_TARGETS
020-MultiFile
)
-foreach( name ${ALL_EXAMPLE_TARGETS} )
- target_link_libraries( ${name} Catch2WithMain )
+foreach(name ${ALL_EXAMPLE_TARGETS})
+ target_link_libraries(${name} Catch2WithMain)
endforeach()
-
list(APPEND CATCH_WARNING_TARGETS ${ALL_EXAMPLE_TARGETS})
set(CATCH_WARNING_TARGETS ${CATCH_WARNING_TARGETS} PARENT_SCOPE)
diff --git a/extras/Catch.cmake b/extras/Catch.cmake
index 3d93fe20..fcdebd60 100644
--- a/extras/Catch.cmake
+++ b/extras/Catch.cmake
@@ -165,7 +165,7 @@ function(catch_discover_tests TARGET)
${ARGN}
)
- if (${CMAKE_VERSION} VERSION_LESS "3.19")
+ if(${CMAKE_VERSION} VERSION_LESS "3.19")
message(FATAL_ERROR "This script requires JSON support from CMake version 3.19 or greater.")
endif()
@@ -187,7 +187,7 @@ function(catch_discover_tests TARGET)
endif()
set(_DISCOVERY_MODE ${CMAKE_CATCH_DISCOVER_TESTS_DISCOVERY_MODE})
endif()
- if (NOT _DISCOVERY_MODE MATCHES "^(POST_BUILD|PRE_TEST)$")
+ if(NOT _DISCOVERY_MODE MATCHES "^(POST_BUILD|PRE_TEST)$")
message(FATAL_ERROR "Unknown DISCOVERY_MODE: ${_DISCOVERY_MODE}")
endif()
@@ -204,7 +204,7 @@ function(catch_discover_tests TARGET)
TARGET ${TARGET}
PROPERTY CROSSCOMPILING_EMULATOR
)
- if (NOT _SKIP_IS_FAILURE)
+ if(NOT _SKIP_IS_FAILURE)
set(_PROPERTIES ${_PROPERTIES} SKIP_RETURN_CODE 4)
endif()
diff --git a/extras/CatchAddTests.cmake b/extras/CatchAddTests.cmake
index 25342139..90fbd5e3 100644
--- a/extras/CatchAddTests.cmake
+++ b/extras/CatchAddTests.cmake
@@ -136,7 +136,7 @@ function(catch_discover_tests_impl)
# Parse JSON output for list of tests/class names/tags
string(JSON version GET "${listing_output}" "version")
- if (NOT version STREQUAL "1")
+ if(NOT version STREQUAL "1")
message(FATAL_ERROR "Unsupported catch output version: '${version}'")
endif()
@@ -186,11 +186,11 @@ function(catch_discover_tests_impl)
${properties}
)
- if (add_tags)
+ if(add_tags)
string(JSON num_tags LENGTH "${test_tags}")
math(EXPR num_tags "${num_tags} - 1")
set(tag_list "")
- if (num_tags GREATER_EQUAL "0")
+ if(num_tags GREATER_EQUAL "0")
foreach(tag_idx RANGE ${num_tags})
string(JSON a_tag GET "${test_tags}" "${tag_idx}")
# Catch2's tags can contain semicolons, which are list element separators
diff --git a/extras/CatchShardTests.cmake b/extras/CatchShardTests.cmake
index 68228f5a..89666d66 100644
--- a/extras/CatchShardTests.cmake
+++ b/extras/CatchShardTests.cmake
@@ -11,7 +11,7 @@
# * REPORTER - reporter spec to use for tests
# * TEST_SPEC - test spec used for filtering tests
function(catch_add_sharded_tests TARGET)
- if (${CMAKE_VERSION} VERSION_LESS "3.10.0")
+ if(${CMAKE_VERSION} VERSION_LESS "3.10.0")
message(FATAL_ERROR "add_sharded_catch_tests only supports CMake versions 3.10.0 and up")
endif()
@@ -23,7 +23,7 @@ function(catch_add_sharded_tests TARGET)
${ARGN}
)
- if (NOT DEFINED _SHARD_COUNT)
+ if(NOT DEFINED _SHARD_COUNT)
set(_SHARD_COUNT 2)
endif()
@@ -61,8 +61,6 @@ function(catch_add_sharded_tests TARGET)
-P "${shard_impl_script_file}"
VERBATIM
)
-
-
endfunction()
diff --git a/extras/CatchShardTestsImpl.cmake b/extras/CatchShardTestsImpl.cmake
index bb2fc3ef..83fac688 100644
--- a/extras/CatchShardTestsImpl.cmake
+++ b/extras/CatchShardTestsImpl.cmake
@@ -25,10 +25,10 @@ if(NOT EXISTS "${TEST_BINARY}")
endif()
set(other_args "")
-if (TEST_SPEC)
+if(TEST_SPEC)
set(other_args "${other_args} ${TEST_SPEC}")
endif()
-if (REPORTER_SPEC)
+if(REPORTER_SPEC)
set(other_args "${other_args} --reporter ${REPORTER_SPEC}")
endif()
diff --git a/extras/ParseAndAddCatchTests.cmake b/extras/ParseAndAddCatchTests.cmake
index 31fc193a..d7c17ace 100644
--- a/extras/ParseAndAddCatchTests.cmake
+++ b/extras/ParseAndAddCatchTests.cmake
@@ -56,7 +56,7 @@
# #
#==================================================================================================#
-if (CMAKE_MINIMUM_REQUIRED_VERSION VERSION_LESS 2.8.8)
+if(CMAKE_MINIMUM_REQUIRED_VERSION VERSION_LESS 2.8.8)
message(FATAL_ERROR "ParseAndAddCatchTests requires CMake 2.8.8 or newer")
endif()
@@ -67,9 +67,9 @@ option(PARSE_CATCH_TESTS_ADD_TARGET_IN_TEST_NAME "Add target name to the test na
option(PARSE_CATCH_TESTS_ADD_TO_CONFIGURE_DEPENDS "Add test file to CMAKE_CONFIGURE_DEPENDS property" OFF)
function(ParseAndAddCatchTests_PrintDebugMessage)
- if(PARSE_CATCH_TESTS_VERBOSE)
- message(STATUS "ParseAndAddCatchTests: ${ARGV}")
- endif()
+ if(PARSE_CATCH_TESTS_VERBOSE)
+ message(STATUS "ParseAndAddCatchTests: ${ARGV}")
+ endif()
endfunction()
# This removes the contents between
@@ -90,163 +90,161 @@ endfunction()
# Worker function
function(ParseAndAddCatchTests_ParseFile SourceFile TestTarget)
- # If SourceFile is an object library, do not scan it (as it is not a file). Exit without giving a warning about a missing file.
- if(SourceFile MATCHES "\\\$<TARGET_OBJECTS:.+>")
- ParseAndAddCatchTests_PrintDebugMessage("Detected OBJECT library: ${SourceFile} this will not be scanned for tests.")
- return()
- endif()
- # According to CMake docs EXISTS behavior is well-defined only for full paths.
- get_filename_component(SourceFile ${SourceFile} ABSOLUTE)
- if(NOT EXISTS ${SourceFile})
- message(WARNING "Cannot find source file: ${SourceFile}")
- return()
+ # If SourceFile is an object library, do not scan it (as it is not a file). Exit without giving a warning about a missing file.
+ if(SourceFile MATCHES "\\\$<TARGET_OBJECTS:.+>")
+ ParseAndAddCatchTests_PrintDebugMessage("Detected OBJECT library: ${SourceFile} this will not be scanned for tests.")
+ return()
+ endif()
+ # According to CMake docs EXISTS behavior is well-defined only for full paths.
+ get_filename_component(SourceFile ${SourceFile} ABSOLUTE)
+ if(NOT EXISTS ${SourceFile})
+ message(WARNING "Cannot find source file: ${SourceFile}")
+ return()
+ endif()
+ ParseAndAddCatchTests_PrintDebugMessage("parsing ${SourceFile}")
+ file(STRINGS ${SourceFile} Contents NEWLINE_CONSUME)
+
+ # Remove block and fullline comments
+ ParseAndAddCatchTests_RemoveComments(Contents)
+
+ # Find definition of test names
+ # https://regex101.com/r/JygOND/1
+ string(REGEX MATCHALL "[ \t]*(CATCH_)?(TEMPLATE_)?(TEST_CASE_METHOD|SCENARIO|TEST_CASE)[ \t]*\\([ \t\n]*\"[^\"]*\"[ \t\n]*(,[ \t\n]*\"[^\"]*\")?(,[ \t\n]*[^\,\)]*)*\\)[ \t\n]*\{+[ \t]*(//[^\n]*[Tt][Ii][Mm][Ee][Oo][Uu][Tt][ \t]*[0-9]+)*" Tests "${Contents}")
+
+ if(PARSE_CATCH_TESTS_ADD_TO_CONFIGURE_DEPENDS AND Tests)
+ ParseAndAddCatchTests_PrintDebugMessage("Adding ${SourceFile} to CMAKE_CONFIGURE_DEPENDS property")
+ set_property(
+ DIRECTORY
+ APPEND
+ PROPERTY CMAKE_CONFIGURE_DEPENDS ${SourceFile}
+ )
+ endif()
+
+ # check CMP0110 policy for new add_test() behavior
+ if(POLICY CMP0110)
+ cmake_policy(GET CMP0110 _cmp0110_value) # new add_test() behavior
+ else()
+ # just to be thorough explicitly set the variable
+ set(_cmp0110_value)
+ endif()
+
+ foreach(TestName ${Tests})
+ # Strip newlines
+ string(REGEX REPLACE "\\\\\n|\n" "" TestName "${TestName}")
+
+ # Get test type and fixture if applicable
+ string(REGEX MATCH "(CATCH_)?(TEMPLATE_)?(TEST_CASE_METHOD|SCENARIO|TEST_CASE)[ \t]*\\([^,^\"]*" TestTypeAndFixture "${TestName}")
+ string(REGEX MATCH "(CATCH_)?(TEMPLATE_)?(TEST_CASE_METHOD|SCENARIO|TEST_CASE)" TestType "${TestTypeAndFixture}")
+ string(REGEX REPLACE "${TestType}\\([ \t]*" "" TestFixture "${TestTypeAndFixture}")
+
+ # Get string parts of test definition
+ string(REGEX MATCHALL "\"+([^\\^\"]|\\\\\")+\"+" TestStrings "${TestName}")
+
+ # Strip wrapping quotation marks
+ string(REGEX REPLACE "^\"(.*)\"$" "\\1" TestStrings "${TestStrings}")
+ string(REPLACE "\";\"" ";" TestStrings "${TestStrings}")
+
+ # Validate that a test name and tags have been provided
+ list(LENGTH TestStrings TestStringsLength)
+ if(TestStringsLength GREATER 2 OR TestStringsLength LESS 1)
+ message(FATAL_ERROR "You must provide a valid test name and tags for all tests in ${SourceFile}")
endif()
- ParseAndAddCatchTests_PrintDebugMessage("parsing ${SourceFile}")
- file(STRINGS ${SourceFile} Contents NEWLINE_CONSUME)
-
- # Remove block and fullline comments
- ParseAndAddCatchTests_RemoveComments(Contents)
-
- # Find definition of test names
- # https://regex101.com/r/JygOND/1
- string(REGEX MATCHALL "[ \t]*(CATCH_)?(TEMPLATE_)?(TEST_CASE_METHOD|SCENARIO|TEST_CASE)[ \t]*\\([ \t\n]*\"[^\"]*\"[ \t\n]*(,[ \t\n]*\"[^\"]*\")?(,[ \t\n]*[^\,\)]*)*\\)[ \t\n]*\{+[ \t]*(//[^\n]*[Tt][Ii][Mm][Ee][Oo][Uu][Tt][ \t]*[0-9]+)*" Tests "${Contents}")
- if(PARSE_CATCH_TESTS_ADD_TO_CONFIGURE_DEPENDS AND Tests)
- ParseAndAddCatchTests_PrintDebugMessage("Adding ${SourceFile} to CMAKE_CONFIGURE_DEPENDS property")
- set_property(
- DIRECTORY
- APPEND
- PROPERTY CMAKE_CONFIGURE_DEPENDS ${SourceFile}
- )
+ # Assign name and tags
+ list(GET TestStrings 0 Name)
+ if("${TestType}" STREQUAL "SCENARIO")
+ set(Name "Scenario: ${Name}")
endif()
-
- # check CMP0110 policy for new add_test() behavior
- if(POLICY CMP0110)
- cmake_policy(GET CMP0110 _cmp0110_value) # new add_test() behavior
+ if(PARSE_CATCH_TESTS_ADD_FIXTURE_IN_TEST_NAME AND "${TestType}" MATCHES "(CATCH_)?TEST_CASE_METHOD" AND TestFixture)
+ set(CTestName "${TestFixture}:${Name}")
+ else()
+ set(CTestName "${Name}")
+ endif()
+ if(PARSE_CATCH_TESTS_ADD_TARGET_IN_TEST_NAME)
+ set(CTestName "${TestTarget}:${CTestName}")
+ endif()
+ # add target to labels to enable running all tests added from this target
+ set(Labels ${TestTarget})
+ if(TestStringsLength EQUAL 2)
+ list(GET TestStrings 1 Tags)
+ string(TOLOWER "${Tags}" Tags)
+ # remove target from labels if the test is hidden
+ if("${Tags}" MATCHES ".*\\[!?(hide|\\.)\\].*")
+ list(REMOVE_ITEM Labels ${TestTarget})
+ endif()
+ string(REPLACE "]" ";" Tags "${Tags}")
+ string(RE