CMakeLists.txt 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. cmake_minimum_required (VERSION 2.6)
  2. project (Tutorial)
  3. # The version number.
  4. set (Tutorial_VERSION_MAJOR 1)
  5. set (Tutorial_VERSION_MINOR 0)
  6. # does this system provide the log and exp functions?
  7. include (${CMAKE_ROOT}/Modules/CheckFunctionExists.cmake)
  8. check_function_exists (log HAVE_LOG)
  9. check_function_exists (exp HAVE_EXP)
  10. # should we use our own math functions
  11. option(USE_MYMATH "Use tutorial provided math implementation" ON)
  12. # configure a header file to pass some of the CMake settings
  13. # to the source code
  14. configure_file (
  15. "${PROJECT_SOURCE_DIR}/TutorialConfig.h.in"
  16. "${PROJECT_BINARY_DIR}/TutorialConfig.h"
  17. )
  18. # add the binary tree to the search path for include files
  19. # so that we will find TutorialConfig.h
  20. include_directories ("${PROJECT_BINARY_DIR}")
  21. # add the MathFunctions library?
  22. if (USE_MYMATH)
  23. include_directories ("${PROJECT_SOURCE_DIR}/MathFunctions")
  24. add_subdirectory (MathFunctions)
  25. set (EXTRA_LIBS ${EXTRA_LIBS} MathFunctions)
  26. endif ()
  27. # add the executable
  28. add_executable (Tutorial tutorial.cxx)
  29. target_link_libraries (Tutorial ${EXTRA_LIBS})
  30. # add the install targets
  31. install (TARGETS Tutorial DESTINATION bin)
  32. install (FILES "${PROJECT_BINARY_DIR}/TutorialConfig.h"
  33. DESTINATION include)
  34. # enable testing
  35. enable_testing ()
  36. # does the application run
  37. add_test (TutorialRuns Tutorial 25)
  38. # does the usage message work?
  39. add_test (TutorialUsage Tutorial)
  40. set_tests_properties (TutorialUsage
  41. PROPERTIES
  42. PASS_REGULAR_EXPRESSION "Usage:.*number"
  43. )
  44. #define a macro to simplify adding tests
  45. macro (do_test arg result)
  46. add_test (TutorialComp${arg} Tutorial ${arg})
  47. set_tests_properties (TutorialComp${arg}
  48. PROPERTIES PASS_REGULAR_EXPRESSION ${result}
  49. )
  50. endmacro ()
  51. # do a bunch of result based tests
  52. do_test (4 "4 is 2")
  53. do_test (9 "9 is 3")
  54. do_test (5 "5 is 2.236")
  55. do_test (7 "7 is 2.645")
  56. do_test (25 "25 is 5")
  57. do_test (-25 "-25 is 0")
  58. do_test (0.0001 "0.0001 is 0.01")
  59. # build a CPack driven installer package
  60. include (InstallRequiredSystemLibraries)
  61. set (CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/License.txt")
  62. set (CPACK_PACKAGE_VERSION_MAJOR "${Tutorial_VERSION_MAJOR}")
  63. set (CPACK_PACKAGE_VERSION_MINOR "${Tutorial_VERSION_MINOR}")
  64. set (CPACK_PACKAGE_CONTACT "foo@bar.org")
  65. include (CPack)
  66. # enable dashboard scripting
  67. include (CTest)