Skip to content

Commit 550e141

Browse files
committed
[upstream_utils] Add Catch2
Resolves #6946
1 parent 05e955f commit 550e141

File tree

291 files changed

+28861
-0
lines changed

Some content is hidden

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

291 files changed

+28861
-0
lines changed

CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,9 @@ if(WITH_TESTS)
247247
enable_testing()
248248
add_subdirectory(thirdparty/googletest)
249249
include(GoogleTest)
250+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/catch2/cmake/modules")
251+
add_subdirectory(thirdparty/catch2)
252+
include(extras/Catch)
250253
endif()
251254

252255
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 = {

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.replace('${CATCH_CONFIG_DEFAULT_REPORTER}', "console")
30+
read.replace('${CATCH_CONFIG_CONSOLE_WIDTH}', "80")
31+
32+
catch2UserConfigOutput.write(read)
33+
}
34+
}
35+
36+
model {
37+
components {
38+
"${nativeName}"(NativeLibrarySpec) {
39+
sources.cpp {
40+
source {
41+
srcDirs "src/main/native/cpp/**/*.cpp"
42+
include '*.cpp'
43+
}
44+
exportedHeaders {
45+
srcDirs 'src/main/native/include',
46+
"$buildDir/generated-includes/"
47+
}
48+
}
49+
binaries.all {
50+
tasks.withType(CppCompile) {
51+
dependsOn generateCatchUserConfig
52+
}
53+
}
54+
}
55+
}
56+
}
57+
58+
apply from: 'publish.gradle'

0 commit comments

Comments
 (0)