Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[upstream_utils] Add Catch2 #6951

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,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
7 changes: 7 additions & 0 deletions shared/catch2.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
model {
binaries {
withType(GoogleTestTestSuiteBinarySpec).all {
lib project: ':thirdparty:catch2', library: 'catch2', linkage: 'static'
}
}
}
1 change: 1 addition & 0 deletions shared/javacpp/setupBuild.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ ext {
staticGtestConfigs["${nativeName}Test"] = []

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

model {
components {
Expand Down
1 change: 1 addition & 0 deletions shared/jni/setupBuild.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ ext {
staticGtestConfigs["${nativeName}Test"] = []

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

model {
components {
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::)
60 changes: 60 additions & 0 deletions thirdparty/catch2/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
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 = read.replace('@CATCH_CONFIG_DEFAULT_REPORTER@', "console")
read = read.replace('@CATCH_CONFIG_CONSOLE_WIDTH@', "80")
read = read.replaceAll("#cmakedefine", "//")

catch2UserConfigOutput.write(read)
}
}

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

project(':').libraryBuild.dependsOn build

tasks.withType(CppCompile) {
dependsOn generateCatchUserConfig
}

apply from: 'publish.gradle'
Loading
Loading