CMakeLists.txt 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. # control where the static and shared libraries are built so that on windows
  8. # we don't need to tinker with the path to run the executable
  9. set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")
  10. set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")
  11. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")
  12. option(BUILD_SHARED_LIBS "Build using shared libraries" ON)
  13. # configure a header file to pass the version number only
  14. configure_file(TutorialConfig.h.in TutorialConfig.h)
  15. # add the MathFunctions library
  16. add_subdirectory(MathFunctions)
  17. # add the executable
  18. add_executable(Tutorial tutorial.cxx)
  19. target_link_libraries(Tutorial PUBLIC MathFunctions)
  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")
  54. include(InstallRequiredSystemLibraries)
  55. set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/License.txt")
  56. set(CPACK_PACKAGE_VERSION_MAJOR "${Tutorial_VERSION_MAJOR}")
  57. set(CPACK_PACKAGE_VERSION_MINOR "${Tutorial_VERSION_MINOR}")
  58. include(CPack)