CMakeLists.txt 1.8 KB

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