CMakeLists.txt 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. cmake_minimum_required(VERSION 3.15)
  2. # set the project name and version
  3. project(Tutorial VERSION 1.0)
  4. # specify the C++ standard
  5. add_library(tutorial_compiler_flags INTERFACE)
  6. target_compile_features(tutorial_compiler_flags INTERFACE cxx_std_11)
  7. # add compiler warning flags just when building this project via
  8. # the BUILD_INTERFACE genex
  9. set(gcc_like_cxx "$<COMPILE_LANG_AND_ID:CXX,ARMClang,AppleClang,Clang,GNU,LCC>")
  10. set(msvc_cxx "$<COMPILE_LANG_AND_ID:CXX,MSVC>")
  11. target_compile_options(tutorial_compiler_flags INTERFACE
  12. "$<${gcc_like_cxx}:$<BUILD_INTERFACE:-Wall;-Wextra;-Wshadow;-Wformat=2;-Wunused>>"
  13. "$<${msvc_cxx}:$<BUILD_INTERFACE:-W3>>"
  14. )
  15. # should we use our own math functions
  16. option(USE_MYMATH "Use tutorial provided math implementation" ON)
  17. # configure a header file to pass some of the CMake settings
  18. # to the source code
  19. configure_file(TutorialConfig.h.in TutorialConfig.h)
  20. # add the MathFunctions library
  21. if(USE_MYMATH)
  22. add_subdirectory(MathFunctions)
  23. list(APPEND EXTRA_LIBS MathFunctions)
  24. endif()
  25. # add the executable
  26. add_executable(Tutorial tutorial.cxx)
  27. target_link_libraries(Tutorial PUBLIC ${EXTRA_LIBS} tutorial_compiler_flags)
  28. # add the binary tree to the search path for include files
  29. # so that we will find TutorialConfig.h
  30. target_include_directories(Tutorial PUBLIC
  31. "${PROJECT_BINARY_DIR}"
  32. )
  33. # TODO 3: Install Tutorial in the bin directory
  34. # Hint: Use the TARGETS and DESTINATION parameters
  35. # TODO 4: Install TutorialConfig.h to the include directory
  36. # Hint: Use the FILES and DESTINATION parameters
  37. # TODO 5: Enable testing
  38. # TODO 6: Add a test called Runs which runs the following command:
  39. # $ Tutorial 25
  40. # TODO 7: Add a test called Usage which runs the following command:
  41. # $ Tutorial
  42. # Make sure the expected output is displayed.
  43. # Hint: Use the PASS_REGULAR_EXPRESSION property with "Usage.*number"
  44. # TODO 8: Add a test which runs the following command:
  45. # $ Tutorial 4
  46. # Make sure the result is correct.
  47. # Hint: Use the PASS_REGULAR_EXPRESSION property with "4 is 2"
  48. # TODO 9: Add more tests. Create a function called do_test to avoid copy +
  49. # paste. Test the following values: 4, 9, 5, 7, 25, -25 and 0.0001.