CMakeLists.txt 2.01 KB
Newer Older
Betsy McPhail's avatar
Betsy McPhail committed
1 2
cmake_minimum_required(VERSION 3.3)
project(Tutorial)
3

4
set(CMAKE_CXX_STANDARD 14)
Betsy McPhail's avatar
Betsy McPhail committed
5 6 7 8

# the version number.
set(Tutorial_VERSION_MAJOR 1)
set(Tutorial_VERSION_MINOR 0)
9 10

# does this system provide the log and exp functions?
Betsy McPhail's avatar
Betsy McPhail committed
11 12 13 14
include(CheckSymbolExists)
set(CMAKE_REQUIRED_LIBRARIES "m")
check_symbol_exists(log "math.h" HAVE_LOG)
check_symbol_exists(exp "math.h" HAVE_EXP)
15 16 17 18 19 20

# should we use our own math functions
option(USE_MYMATH "Use tutorial provided math implementation" ON)

# configure a header file to pass some of the CMake settings
# to the source code
Betsy McPhail's avatar
Betsy McPhail committed
21
configure_file(
22 23 24 25 26
  "${PROJECT_SOURCE_DIR}/TutorialConfig.h.in"
  "${PROJECT_BINARY_DIR}/TutorialConfig.h"
  )

# add the MathFunctions library?
Betsy McPhail's avatar
Betsy McPhail committed
27 28 29 30
if(USE_MYMATH)
  add_subdirectory(MathFunctions)
  list(APPEND EXTRA_LIBS MathFunctions)
endif()
31 32

# add the executable
Betsy McPhail's avatar
Betsy McPhail committed
33 34 35 36 37 38 39 40
add_executable(Tutorial tutorial.cxx)
target_link_libraries(Tutorial PUBLIC ${EXTRA_LIBS})

# add the binary tree to the search path for include files
# so that we will find TutorialConfig.h
target_include_directories(Tutorial PUBLIC
                           "${PROJECT_BINARY_DIR}"
                           )
41 42

# add the install targets
Betsy McPhail's avatar
Betsy McPhail committed
43 44 45 46
install(TARGETS Tutorial DESTINATION bin)
install(FILES "${PROJECT_BINARY_DIR}/TutorialConfig.h"
  DESTINATION include
  )
47 48

# enable testing
Betsy McPhail's avatar
Betsy McPhail committed
49
enable_testing()
50 51

# does the application run
Betsy McPhail's avatar
Betsy McPhail committed
52
add_test(NAME Runs COMMAND Tutorial 25)
53 54

# does the usage message work?
Betsy McPhail's avatar
Betsy McPhail committed
55 56 57
add_test(NAME Usage COMMAND Tutorial)
set_tests_properties(Usage
  PROPERTIES PASS_REGULAR_EXPRESSION "Usage:.*number"
58 59
  )

Betsy McPhail's avatar
Betsy McPhail committed
60 61 62 63
# define a function to simplify adding tests
function(do_test target arg result)
  add_test(NAME Comp${arg} COMMAND ${target} ${arg})
  set_tests_properties(Comp${arg}
64 65
    PROPERTIES PASS_REGULAR_EXPRESSION ${result}
    )
Betsy McPhail's avatar
Betsy McPhail committed
66
endfunction(do_test)
67 68

# do a bunch of result based tests
Betsy McPhail's avatar
Betsy McPhail committed
69 70 71 72 73 74 75
do_test(Tutorial 4 "4 is 2")
do_test(Tutorial 9 "9 is 3")
do_test(Tutorial 5 "5 is 2.236")
do_test(Tutorial 7 "7 is 2.645")
do_test(Tutorial 25 "25 is 5")
do_test(Tutorial -25 "-25 is [-nan|nan|0]")
do_test(Tutorial 0.0001 "0.0001 is 0.01")