|
| 1 | +cmake_minimum_required(VERSION 3.10) |
| 2 | + |
| 3 | +#set project name and version |
| 4 | +project(Tutorial VERSION 1.0) |
| 5 | + |
| 6 | +# add option |
| 7 | +option(USE_MYMATH "Use tutorial provided math implementation" ON) |
| 8 | +######################################################################################### |
| 9 | + |
| 10 | +######################################### test config ################################### |
| 11 | +#set config file |
| 12 | +configure_file(TutorialConfig.h.in TutorialConfig.h) |
| 13 | +add_executable(Tutorial Tutorial.cpp) |
| 14 | +#this line must after add_executable, or will be error! |
| 15 | +target_include_directories(Tutorial PUBLIC "${PROJECT_BINARY_DIR}") |
| 16 | +######################################################################################## |
| 17 | + |
| 18 | +######################################### test standard ################################ |
| 19 | +#set c++ standard |
| 20 | +#if comment this line, the default compiler will be use |
| 21 | +set(CMAKE_CXX_STANDARD 11) |
| 22 | +set(CMAKE_CXX_STANDARD_REQUIRED True) |
| 23 | +add_executable(TestStd TestStd.cpp) |
| 24 | +######################################################################################## |
| 25 | + |
| 26 | +# if USE_MYMATH is true |
| 27 | +if(USE_MYMATH) |
| 28 | + add_subdirectory(MathFunctions) |
| 29 | + list(APPEND EXTRA_LIBS MathFunctions) |
| 30 | + list(APPEND EXTRA_INCLUDES "${PROJECT_SOURCE_DIR}/MathFunctions") |
| 31 | + message("USE_MYMATH is True") |
| 32 | +endif() |
| 33 | +######################################################################################## |
| 34 | + |
| 35 | +# tesr sqrt |
| 36 | +add_executable(TestSqrt TestSqrt.cpp) |
| 37 | + |
| 38 | +target_link_libraries(TestSqrt PUBLIC ${EXTRA_LIBS}) |
| 39 | + |
| 40 | +target_include_directories(TestSqrt PUBLIC |
| 41 | + "${PROJECT_BINARY_DIR}" |
| 42 | + ${EXTRA_INCLUDES} |
| 43 | + ) |
| 44 | +######################################################################################## |
| 45 | + |
| 46 | + |
0 commit comments