CMakeLists.txt 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. cmake_minimum_required(VERSION 3.3)
  2. project(Tutorial)
  3. set(CMAKE_CXX_STANDARD 14)
  4. # set the version number
  5. set(Tutorial_VERSION_MAJOR 1)
  6. set(Tutorial_VERSION_MINOR 0)
  7. # does this system provide the log and exp functions?
  8. include(CheckSymbolExists)
  9. set(CMAKE_REQUIRED_LIBRARIES "m")
  10. check_symbol_exists(log "math.h" HAVE_LOG)
  11. check_symbol_exists(exp "math.h" HAVE_EXP)
  12. # should we use our own math functions
  13. option(USE_MYMATH "Use tutorial provided math implementation" ON)
  14. # configure a header file to pass some of the CMake settings
  15. # to the source code
  16. configure_file(
  17. "${PROJECT_SOURCE_DIR}/TutorialConfig.h.in"
  18. "${PROJECT_BINARY_DIR}/TutorialConfig.h"
  19. )
  20. # add the MathFunctions library?
  21. if(USE_MYMATH)
  22. add_subdirectory(MathFunctions)
  23. list(APPEND EXTRA_LIBS MathFunctions)
  24. endif()
  25. # add the executable
  26. add_executable(Tutorial tutorial.cxx)
  27. target_link_libraries(Tutorial PUBLIC ${EXTRA_LIBS})
  28. # add the binary tree to the search path for include files
  29. # so that we will find TutorialConfig.h
  30. target_include_directories(Tutorial PUBLIC
  31. "${PROJECT_BINARY_DIR}"
  32. )
  33. # add the install targets
  34. install(TARGETS Tutorial DESTINATION bin)
  35. install(FILES "${PROJECT_BINARY_DIR}/TutorialConfig.h"
  36. DESTINATION include
  37. )
  38. # enable testing
  39. enable_testing()
  40. # does the application run
  41. add_test(NAME Runs COMMAND Tutorial 25)
  42. # does the usage message work?
  43. add_test(NAME Usage COMMAND Tutorial)
  44. set_tests_properties(Usage
  45. PROPERTIES PASS_REGULAR_EXPRESSION "Usage:.*number"
  46. )
  47. # define a function to simplify adding tests
  48. function(do_test target arg result)
  49. add_test(NAME Comp${arg} COMMAND ${target} ${arg})
  50. set_tests_properties(Comp${arg}
  51. PROPERTIES PASS_REGULAR_EXPRESSION ${result}
  52. )
  53. endfunction(do_test)
  54. # do a bunch of result based tests
  55. do_test(Tutorial 4 "4 is 2")
  56. do_test(Tutorial 9 "9 is 3")
  57. do_test(Tutorial 5 "5 is 2.236")
  58. do_test(Tutorial 7 "7 is 2.645")
  59. do_test(Tutorial 25 "25 is 5")
  60. do_test(Tutorial -25 "-25 is [-nan|nan|0]")
  61. do_test(Tutorial 0.0001 "0.0001 is 0.01")