CMakeLists.txt 1.8 KB

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