Skip to content

Commit 11ebe36

Browse files
committed
[upstream_utils] Add Catch2
Resolves #6946
1 parent 9ccd731 commit 11ebe36

File tree

296 files changed

+28880
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

296 files changed

+28880
-1
lines changed

CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,9 @@ if(WITH_TESTS)
269269
enable_testing()
270270
add_subdirectory(thirdparty/googletest)
271271
include(GoogleTest)
272+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/catch2/cmake/modules")
273+
add_subdirectory(thirdparty/catch2)
274+
include(extras/Catch)
272275
endif()
273276

274277
if(USE_SYSTEM_LIBUV)

settings.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ include 'epilogue-processor'
6262
include 'epilogue-runtime'
6363
include 'thirdparty:googletest'
6464
include 'thirdparty:imgui_suite'
65+
include 'thirdparty:catch2'
6566

6667
buildCache {
6768
def cred = {

shared/catch2.gradle

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
model {
2+
binaries {
3+
withType(GoogleTestTestSuiteBinarySpec).all {
4+
lib project: ':thirdparty:catch2', library: 'catch2', linkage: 'static'
5+
}
6+
}
7+
}

shared/javacpp/setupBuild.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ ext {
2323
staticGtestConfigs["${nativeName}Test"] = []
2424

2525
apply from: "${rootDir}/shared/googletest.gradle"
26+
apply from: "${rootDir}/shared/catch2.gradle"
2627

2728
model {
2829
components {

shared/jni/setupBuild.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ ext {
3131
staticGtestConfigs["${nativeName}Test"] = []
3232

3333
apply from: "${rootDir}/shared/googletest.gradle"
34+
apply from: "${rootDir}/shared/catch2.gradle"
3435

3536
model {
3637
components {

thirdparty/catch2/CMakeLists.txt

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
project(catch2)
2+
3+
include(CompileWarnings)
4+
5+
file(
6+
GLOB_RECURSE catch2_src
7+
src/main/native/cpp/*.cpp
8+
)
9+
10+
add_library(catch2 ${catch2_src})
11+
set_target_properties(catch2 PROPERTIES DEBUG_POSTFIX "d")
12+
13+
set_property(TARGET catch2 PROPERTY FOLDER "libraries")
14+
target_compile_features(catch2 PUBLIC cxx_std_20)
15+
16+
set(CATCH_CONFIG_DEFAULT_REPORTER "console" CACHE STRING "Read docs/configuration.md for details. The name of the reporter should be without quotes.")
17+
set(CATCH_CONFIG_CONSOLE_WIDTH "80" CACHE STRING "Read docs/configuration.md for details. Must form a valid integer literal.")
18+
19+
include_directories(
20+
"${CMAKE_CURRENT_SOURCE_DIR}/src/main/native/include"
21+
)
22+
23+
configure_file(
24+
"src/main/native/include/catch2/catch_user_config.hpp.in"
25+
"${CMAKE_CURRENT_BINARY_DIR}/generated-includes/catch2/catch_user_config.hpp"
26+
)
27+
28+
target_include_directories(
29+
catch2
30+
PUBLIC
31+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/main/native/include>
32+
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/generated-includes>
33+
)
34+
35+
wpilib_target_warnings(catch2)
36+
37+
install(TARGETS catch2 EXPORT catch2)
38+
export(TARGETS catch2 FILE catch2.cmake NAMESPACE Catch::)

thirdparty/catch2/build.gradle

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
apply plugin: 'cpp'
2+
apply plugin: 'visual-studio'
3+
apply plugin: 'edu.wpi.first.NativeUtils'
4+
5+
ext {
6+
nativeName = 'catch2'
7+
}
8+
9+
apply from: "${rootDir}/shared/config.gradle"
10+
11+
def catch2UserConfigInput = file("src/main/native/include/catch2/catch_user_config.hpp.in")
12+
def catch2UserConfigOutput = file("$buildDir/generated-includes/catch2/catch_user_config.hpp")
13+
14+
task generateCatchUserConfig() {
15+
description = 'Generates the Catch2 user config file.'
16+
group = 'catch2'
17+
18+
outputs.file catch2UserConfigOutput
19+
inputs.file catch2UserConfigInput
20+
21+
doLast {
22+
println "Writing config to $catch2UserConfigOutput"
23+
24+
if (catch2UserConfigOutput.exists()) {
25+
catch2UserConfigOutput.delete()
26+
}
27+
28+
def read = catch2UserConfigInput.text
29+
read = read.replace('${CATCH_CONFIG_DEFAULT_REPORTER}', "console")
30+
read = read.replace('${CATCH_CONFIG_CONSOLE_WIDTH}', "80")
31+
read = read.replaceAll("#cmakedefine", "#define")
32+
33+
catch2UserConfigOutput.write(read)
34+
}
35+
}
36+
37+
model {
38+
components {
39+
"${nativeName}"(NativeLibrarySpec) {
40+
sources.cpp {
41+
source {
42+
srcDirs "src/main/native/cpp"
43+
include '**/*.cpp'
44+
}
45+
exportedHeaders {
46+
srcDirs 'src/main/native/include',
47+
"$buildDir/generated-includes/"
48+
}
49+
}
50+
}
51+
}
52+
}
53+
54+
tasks.withType(CppCompile) {
55+
dependsOn generateCatchUserConfig
56+
}
57+
58+
apply from: 'publish.gradle'

0 commit comments

Comments
 (0)