Skip to content

Commit

Permalink
[upstream_utils] Add Catch2
Browse files Browse the repository at this point in the history
Resolves #6946
  • Loading branch information
spacey-sooty committed Aug 14, 2024
1 parent 05e955f commit 0e6710b
Show file tree
Hide file tree
Showing 291 changed files with 28,869 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,9 @@ if(WITH_TESTS)
enable_testing()
add_subdirectory(thirdparty/googletest)
include(GoogleTest)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/catch2/cmake/modules")
add_subdirectory(thirdparty/catch2)
include(extras/Catch)
endif()

if(USE_SYSTEM_LIBUV)
Expand Down
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ include 'epilogue-processor'
include 'epilogue-runtime'
include 'thirdparty:googletest'
include 'thirdparty:imgui_suite'
include 'thirdparty:catch2'

buildCache {
def cred = {
Expand Down
38 changes: 38 additions & 0 deletions thirdparty/catch2/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
project(catch2)

include(CompileWarnings)

file(
GLOB_RECURSE catch2_src
src/main/native/cpp/*.cpp
)

add_library(catch2 ${catch2_src})
set_target_properties(catch2 PROPERTIES DEBUG_POSTFIX "d")

set_property(TARGET catch2 PROPERTY FOLDER "libraries")
target_compile_features(catch2 PUBLIC cxx_std_20)

set(CATCH_CONFIG_DEFAULT_REPORTER "console" CACHE STRING "Read docs/configuration.md for details. The name of the reporter should be without quotes.")
set(CATCH_CONFIG_CONSOLE_WIDTH "80" CACHE STRING "Read docs/configuration.md for details. Must form a valid integer literal.")

include_directories(
"${CMAKE_CURRENT_SOURCE_DIR}/src/main/native/include"
)

configure_file(
"src/main/native/include/catch2/catch_user_config.hpp.in"
"${CMAKE_CURRENT_BINARY_DIR}/generated-includes/catch2/catch_user_config.hpp"
)

target_include_directories(
catch2
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/main/native/include>
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/generated-includes>
)

wpilib_target_warnings(catch2)

install(TARGETS catch2 EXPORT catch2)
export(TARGETS catch2 FILE catch2.cmake NAMESPACE Catch::)
66 changes: 66 additions & 0 deletions thirdparty/catch2/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
apply plugin: 'cpp'
apply plugin: 'visual-studio'
apply plugin: 'edu.wpi.first.NativeUtils'

ext {
nativeName = 'Catch2'
}

apply from: "${rootDir}/shared/config.gradle"

def catch2UserConfigInput = file("src/main/native/include/catch2/catch_user_config.hpp.in")
def catch2UserConfigOutput = file("$buildDir/generated-includes/catch2/catch_user_config.hpp")

task generateCatchUserConfig() {
description = 'Generates the Catch2 user config file.'
group = 'Catch2'

outputs.file catch2UserConfigOutput
inputs.file catch2UserConfigInput

doLast {
println "Writing config to $catch2UserConfigOutput"

if (catch2UserConfigOutput.exists()) {
catch2UserConfigOutput.delete()
}

def read = catch2UserConfigInput.text
read.replace('${CATCH_CONFIG_DEFAULT_REPORTER}', "console")
read.replace('${CATCH_CONFIG_CONSOLE_WIDTH}', "80")

catch2UserConfigOutput.write(read)
}
}

model {
components {
"${nativeName}"(NativeLibrarySpec) {
sources.cpp {
source {
srcDirs "src/main/native/cpp/**/*.cpp"
include '*.cpp'
}
exportedHeaders {
srcDirs 'src/main/native/include',
"$buildDir/generated-includes/"
}
}
binaries {
all {
tasks.withType(CppCompile) {
dependsOn generateCatchUserConfig
}
}
}
}
binaries {
all {
tasks.withType(CppCompile) {
dependsOn generateCatchUserConfig
}
}
}
}

apply from: 'publish.gradle'
Loading

0 comments on commit 0e6710b

Please sign in to comment.