Skip to content

Commit

Permalink
Catch2 is now downloaded with FetchContent if BUILD_TESTING is set to ON
Browse files Browse the repository at this point in the history
  • Loading branch information
GiulioRomualdi committed Apr 20, 2023
1 parent 1668701 commit cdfce83
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
21 changes: 19 additions & 2 deletions cmake/AddBipedalLocomotionUnitTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,23 @@
# This software may be modified and distributed under the terms of the
# BSD-3-Clause license. See the accompanying LICENSE file for details.

# This software may be modified and distributed under the terms of the
# GNU Lesser General Public License v2.1 or any later version.

# Fetch catch2 only if the testing are built
if (BUILD_TESTING)
include(FetchContent)
FetchContent_Declare(Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v2.13.8)

FetchContent_GetProperties(Catch2)
if(NOT Catch2_POPULATED)
message(STATUS "Fetching Catch2...")
FetchContent_MakeAvailable(Catch2)
endif()
endif()

if (FRAMEWORK_RUN_Valgrind_tests)
set(CTEST_MEMORYCHECK_COMMAND ${VALGRIND_PROGRAM})
set(MEMORYCHECK_COMMAND ${VALGRIND_PROGRAM})
Expand All @@ -21,7 +38,7 @@ if (FRAMEWORK_RUN_Valgrind_tests)
separate_arguments(MEMCHECK_COMMAND_COMPLETE)
endif()

if (FRAMEWORK_COMPILE_tests)
if (BUILD_TESTING)
configure_file(cmake/Catch2Main.cpp.in ${CMAKE_BINARY_DIR}/Testing/Catch2Main.cpp)
add_library(CatchTestMain ${CMAKE_BINARY_DIR}/Testing/Catch2Main.cpp)
target_link_libraries(CatchTestMain PUBLIC Catch2::Catch2)
Expand All @@ -30,7 +47,7 @@ endif()

function(add_bipedal_test)

if(FRAMEWORK_COMPILE_tests)
if(BUILD_TESTING)

set(options )
set(oneValueArgs NAME)
Expand Down
7 changes: 0 additions & 7 deletions cmake/BipedalLocomotionFrameworkDependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,13 @@ dependency_classifier(robometry MINIMUM_VERSION 1.1.0 IS_USED ${FRAMEWORK_USE_ro
find_package(icub-models 1.23.3 QUIET)
checkandset_dependency(icub-models)

find_package(Catch2 QUIET)
checkandset_dependency(Catch2)

find_package(VALGRIND QUIET)
checkandset_dependency(VALGRIND)

find_package(UnicyclePlanner QUIET)
checkandset_dependency(UnicyclePlanner)

########################## Components ##############################
framework_dependent_option(FRAMEWORK_COMPILE_tests
"Compile tests?" ON
"FRAMEWORK_USE_Catch2;BUILD_TESTING" OFF)

framework_dependent_option(FRAMEWORK_RUN_Valgrind_tests
"Run Valgrind tests?" OFF
"FRAMEWORK_COMPILE_tests;VALGRIND_FOUND" OFF)
Expand Down

0 comments on commit cdfce83

Please sign in to comment.