cmake/Help/guide/tutorial/Step5/CMakeLists.txt

60 lines
2.0 KiB
CMake
Raw Normal View History

2022-11-16 20:14:03 +01:00
cmake_minimum_required(VERSION 3.15)
2020-02-01 23:06:01 +01:00
# set the project name and version
project(Tutorial VERSION 1.0)
# specify the C++ standard
2022-11-16 20:14:03 +01:00
add_library(tutorial_compiler_flags INTERFACE)
target_compile_features(tutorial_compiler_flags INTERFACE cxx_std_11)
# add compiler warning flags just when building this project via
# the BUILD_INTERFACE genex
set(gcc_like_cxx "$<COMPILE_LANG_AND_ID:CXX,ARMClang,AppleClang,Clang,GNU,LCC>")
set(msvc_cxx "$<COMPILE_LANG_AND_ID:CXX,MSVC>")
target_compile_options(tutorial_compiler_flags INTERFACE
"$<${gcc_like_cxx}:$<BUILD_INTERFACE:-Wall;-Wextra;-Wshadow;-Wformat=2;-Wunused>>"
"$<${msvc_cxx}:$<BUILD_INTERFACE:-W3>>"
)
# configure a header file to pass some of the CMake settings
# to the source code
2020-02-01 23:06:01 +01:00
configure_file(TutorialConfig.h.in TutorialConfig.h)
2020-02-01 23:06:01 +01:00
# add the MathFunctions library
2023-07-02 19:51:09 +02:00
add_subdirectory(MathFunctions)
# add the executable
2019-11-11 23:01:05 +01:00
add_executable(Tutorial tutorial.cxx)
2023-07-02 19:51:09 +02:00
target_link_libraries(Tutorial PUBLIC MathFunctions tutorial_compiler_flags)
2019-11-11 23:01:05 +01:00
# add the binary tree to the search path for include files
# so that we will find TutorialConfig.h
target_include_directories(Tutorial PUBLIC
"${PROJECT_BINARY_DIR}"
)
2022-11-16 20:14:03 +01:00
# TODO 3: Install Tutorial in the bin directory
# Hint: Use the TARGETS and DESTINATION parameters
2023-05-23 16:38:00 +02:00
# TODO 4: Install TutorialConfig.h to the include directory
2022-11-16 20:14:03 +01:00
# Hint: Use the FILES and DESTINATION parameters
2022-11-16 20:14:03 +01:00
# TODO 5: Enable testing
2022-11-16 20:14:03 +01:00
# TODO 6: Add a test called Runs which runs the following command:
# $ Tutorial 25
2022-11-16 20:14:03 +01:00
# TODO 7: Add a test called Usage which runs the following command:
# $ Tutorial
# Make sure the expected output is displayed.
# Hint: Use the PASS_REGULAR_EXPRESSION property with "Usage.*number"
2022-11-16 20:14:03 +01:00
# TODO 8: Add a test which runs the following command:
# $ Tutorial 4
# Make sure the result is correct.
# Hint: Use the PASS_REGULAR_EXPRESSION property with "4 is 2"
2022-11-16 20:14:03 +01:00
# TODO 9: Add more tests. Create a function called do_test to avoid copy +
2023-05-23 16:38:00 +02:00
# paste. Test the following values: 4, 9, 5, 7, 25, -25 and 0.0001.