CMakeLists.txt 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 the version number only
  10. configure_file(TutorialConfig.h.in TutorialConfig.h)
  11. # add the MathFunctions library
  12. if(USE_MYMATH)
  13. add_subdirectory(MathFunctions)
  14. list(APPEND EXTRA_LIBS MathFunctions)
  15. endif()
  16. # add the executable
  17. add_executable(Tutorial tutorial.cxx)
  18. target_link_libraries(Tutorial PUBLIC ${EXTRA_LIBS})
  19. # add the binary tree to the search path for include files
  20. # so that we will find TutorialConfig.h
  21. target_include_directories(Tutorial PUBLIC
  22. "${PROJECT_BINARY_DIR}"
  23. )
  24. # add the install targets
  25. install(TARGETS Tutorial DESTINATION bin)
  26. install(FILES "${PROJECT_BINARY_DIR}/TutorialConfig.h"
  27. DESTINATION include
  28. )
  29. # enable testing
  30. include(CTest)
  31. # does the application run
  32. add_test(NAME Runs COMMAND Tutorial 25)
  33. # does the usage message work?
  34. add_test(NAME Usage COMMAND Tutorial)
  35. set_tests_properties(Usage
  36. PROPERTIES PASS_REGULAR_EXPRESSION "Usage:.*number"
  37. )
  38. # define a function to simplify adding tests
  39. function(do_test target arg result)
  40. add_test(NAME Comp${arg} COMMAND ${target} ${arg})
  41. set_tests_properties(Comp${arg}
  42. PROPERTIES PASS_REGULAR_EXPRESSION ${result}
  43. )
  44. endfunction(do_test)
  45. # do a bunch of result based tests
  46. do_test(Tutorial 4 "4 is 2")
  47. do_test(Tutorial 9 "9 is 3")
  48. do_test(Tutorial 5 "5 is 2.236")
  49. do_test(Tutorial 7 "7 is 2.645")
  50. do_test(Tutorial 25 "25 is 5")
  51. do_test(Tutorial -25 "-25 is [-nan|nan|0]")
  52. do_test(Tutorial 0.0001 "0.0001 is 0.01")
  53. include(InstallRequiredSystemLibraries)
  54. set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/License.txt")
  55. set(CPACK_PACKAGE_VERSION_MAJOR "${Tutorial_VERSION_MAJOR}")
  56. set(CPACK_PACKAGE_VERSION_MINOR "${Tutorial_VERSION_MINOR}")
  57. include(CPack)