1 cmake_minimum_required(VERSION 3.10)
3 # set the project name and version
4 project(Tutorial VERSION 1.0)
6 # specify the C++ standard
7 set(CMAKE_CXX_STANDARD 11)
8 set(CMAKE_CXX_STANDARD_REQUIRED True)
10 # should we use our own math functions
11 option(USE_MYMATH "Use tutorial provided math implementation" ON)
13 # configure a header file to pass some of the CMake settings
15 configure_file(TutorialConfig.h.in TutorialConfig.h)
17 # add the MathFunctions library
19 add_subdirectory(MathFunctions)
20 list(APPEND EXTRA_LIBS MathFunctions)
24 add_executable(Tutorial tutorial.cxx)
25 target_link_libraries(Tutorial PUBLIC ${EXTRA_LIBS})
27 # add the binary tree to the search path for include files
28 # so that we will find TutorialConfig.h
29 target_include_directories(Tutorial PUBLIC
30 "${PROJECT_BINARY_DIR}"
33 # add the install targets
34 install(TARGETS Tutorial DESTINATION bin)
35 install(FILES "${PROJECT_BINARY_DIR}/TutorialConfig.h"
42 # does the application run
43 add_test(NAME Runs COMMAND Tutorial 25)
45 # does the usage message work?
46 add_test(NAME Usage COMMAND Tutorial)
47 set_tests_properties(Usage
48 PROPERTIES PASS_REGULAR_EXPRESSION "Usage:.*number"
51 # define a function to simplify adding tests
52 function(do_test target arg result)
53 add_test(NAME Comp${arg} COMMAND ${target} ${arg})
54 set_tests_properties(Comp${arg}
55 PROPERTIES PASS_REGULAR_EXPRESSION ${result}
59 # do a bunch of result based tests
60 do_test(Tutorial 4 "4 is 2")
61 do_test(Tutorial 9 "9 is 3")
62 do_test(Tutorial 5 "5 is 2.236")
63 do_test(Tutorial 7 "7 is 2.645")
64 do_test(Tutorial 25 "25 is 5")
65 do_test(Tutorial -25 "-25 is (-nan|nan|0)")
66 do_test(Tutorial 0.0001 "0.0001 is 0.01")