Imported Upstream version 3.25.0
[platform/upstream/cmake.git] / Help / guide / tutorial / Step4 / CMakeLists.txt
1 # TODO 4: Update the minimum required version to 3.15
2
3 cmake_minimum_required(VERSION 3.10)
4
5 # set the project name and version
6 project(Tutorial VERSION 1.0)
7
8 # TODO 1: Replace the following code by:
9 # * Creating an interface library called tutorial_compiler_flags
10 #   Hint: use add_library() with the INTERFACE signature
11 # * Add compiler feature cxx_std_11 to tutorial_compiler_flags
12 #   Hint: Use target_compile_features()
13
14 # specify the C++ standard
15 set(CMAKE_CXX_STANDARD 11)
16 set(CMAKE_CXX_STANDARD_REQUIRED True)
17
18 # TODO 5: Create helper variables to determine which compiler we are using:
19 # * Create a new variable gcc_like_cxx that is true if we are using CXX and
20 #   any of the following compilers: ARMClang, AppleClang, Clang, GNU, LCC
21 # * Create a new variable msvc_cxx that is true if we are using CXX and MSVC
22 # Hint: Use set() and COMPILE_LANG_AND_ID
23
24 # TODO 6: Add warning flag compile options to the interface library
25 # tutorial_compiler_flags.
26 # * For gcc_like_cxx, add flags -Wall;-Wextra;-Wshadow;-Wformat=2;-Wunused
27 # * For msvc_cxx, add flags -W3
28 # Hint: Use target_compile_options()
29
30 # TODO 7: With nested generator expressions, only use the flags for the
31 # build-tree
32 # Hint: Use BUILD_INTERFACE
33
34 # should we use our own math functions
35 option(USE_MYMATH "Use tutorial provided math implementation" ON)
36
37 # configure a header file to pass some of the CMake settings
38 # to the source code
39 configure_file(TutorialConfig.h.in TutorialConfig.h)
40
41 # add the MathFunctions library
42 if(USE_MYMATH)
43   add_subdirectory(MathFunctions)
44   list(APPEND EXTRA_LIBS MathFunctions)
45 endif()
46
47 # add the executable
48 add_executable(Tutorial tutorial.cxx)
49
50 # TODO 2: Link to tutorial_compiler_flags
51
52 target_link_libraries(Tutorial PUBLIC ${EXTRA_LIBS})
53
54 # add the binary tree to the search path for include files
55 # so that we will find TutorialConfig.h
56 target_include_directories(Tutorial PUBLIC
57                            "${PROJECT_BINARY_DIR}"
58                            )