feat: new example
This commit is contained in:
parent
4517453d66
commit
571a244dbd
@ -1,4 +1,4 @@
|
|||||||
cmake_minimum_required(VERSION 3.11...3.16)
|
cmake_minimum_required(VERSION 3.11...3.18)
|
||||||
|
|
||||||
project(ModernCMakeExamples)
|
project(ModernCMakeExamples)
|
||||||
set(MODERN_CMAKE_BUILD_TESTING ON)
|
set(MODERN_CMAKE_BUILD_TESTING ON)
|
||||||
@ -7,6 +7,7 @@ include(CTest)
|
|||||||
|
|
||||||
add_subdirectory(simple-project)
|
add_subdirectory(simple-project)
|
||||||
add_subdirectory(extended-project)
|
add_subdirectory(extended-project)
|
||||||
|
add_subdirectory(fetch)
|
||||||
|
|
||||||
add_subdirectory(root-usefile)
|
add_subdirectory(root-usefile)
|
||||||
add_subdirectory(root-simple)
|
add_subdirectory(root-simple)
|
||||||
|
19
examples/fetch/CMakeLists.txt
Normal file
19
examples/fetch/CMakeLists.txt
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.14...3.18)
|
||||||
|
|
||||||
|
project(FetchExample LANGUAGES CXX)
|
||||||
|
|
||||||
|
include(FetchContent)
|
||||||
|
include(CTest)
|
||||||
|
|
||||||
|
FetchContent_Declare(
|
||||||
|
catch
|
||||||
|
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
|
||||||
|
GIT_TAG v2.13.0
|
||||||
|
)
|
||||||
|
|
||||||
|
# CMake 3.14+
|
||||||
|
FetchContent_MakeAvailable(catch)
|
||||||
|
|
||||||
|
add_executable(fetch_example main.cpp)
|
||||||
|
target_link_libraries(fetch_example PRIVATE Catch2::Catch2)
|
||||||
|
add_test(NAME fetch_example COMMAND fetch_example)
|
13
examples/fetch/main.cpp
Normal file
13
examples/fetch/main.cpp
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
|
||||||
|
#include "catch2/catch.hpp"
|
||||||
|
|
||||||
|
unsigned int Factorial( unsigned int number ) {
|
||||||
|
return number <= 1 ? number : Factorial(number-1)*number;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE( "Factorials are computed", "[factorial]" ) {
|
||||||
|
REQUIRE( Factorial(1) == 1 );
|
||||||
|
REQUIRE( Factorial(2) == 2 );
|
||||||
|
REQUIRE( Factorial(3) == 6 );
|
||||||
|
REQUIRE( Factorial(10) == 3628800 );
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user