|
| 1 | +cmake_minimum_required(VERSION 3.8.2) |
| 2 | +project(CPP-Stream) |
| 3 | + |
| 4 | +set(CMAKE_CXX_STANDARD 17) |
| 5 | + |
| 6 | +include_directories(include) |
| 7 | + |
| 8 | +find_package(Threads) |
| 9 | + |
| 10 | +if (CMAKE_VERSION VERSION_LESS 3.2) |
| 11 | + set(UPDATE_DISCONNECTED_IF_AVAILABLE "") |
| 12 | +else() |
| 13 | + set(UPDATE_DISCONNECTED_IF_AVAILABLE "UPDATE_DISCONNECTED 1") |
| 14 | +endif() |
| 15 | +include(third-party/DownloadProject/DownloadProject.cmake) |
| 16 | + |
| 17 | +# =============================== CMAKE MODULES ========================================= |
| 18 | +download_project(PROJ cmake-modules |
| 19 | + GIT_REPOSITORY https://github.com/NikitkoCent/cmake-modules |
| 20 | + GIT_TAG changes |
| 21 | + ${UPDATE_DISCONNECTED_IF_AVAILABLE} |
| 22 | + ) |
| 23 | +# =============================== END CMAKE MODULES ===================================== |
| 24 | + |
| 25 | +# ================================ SETUP WARNINGS ======================================= |
| 26 | +include(${cmake-modules_SOURCE_DIR}/EnableExtraCompilerWarnings.cmake) |
| 27 | +globally_enable_extra_compiler_warnings() |
| 28 | +# ============================== END SETUP WARNINGS ===================================== |
| 29 | + |
| 30 | +# ================================== GOOGLETEST ========================================= |
| 31 | +enable_testing() |
| 32 | + |
| 33 | +download_project(PROJ googletest |
| 34 | + GIT_REPOSITORY https://github.com/google/googletest.git |
| 35 | + GIT_TAG master |
| 36 | + ${UPDATE_DISCONNECTED_IF_AVAILABLE} |
| 37 | + ) |
| 38 | + |
| 39 | +# Prevent GoogleTest from overriding our compiler/linker options |
| 40 | +# when building with Visual Studio |
| 41 | +set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) |
| 42 | + |
| 43 | +add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR}) |
| 44 | + |
| 45 | +# When using CMake 2.8.11 or later, header path dependencies |
| 46 | +# are automatically added to the gtest and gmock targets. |
| 47 | +# For earlier CMake versions, we have to explicitly add the |
| 48 | +# required directories to the header search path ourselves. |
| 49 | +if (CMAKE_VERSION VERSION_LESS 2.8.11) |
| 50 | + include_directories("${gtest_SOURCE_DIR}/include" |
| 51 | + "${gmock_SOURCE_DIR}/include") |
| 52 | +endif() |
| 53 | +# ================================ GOOGLETEST END ======================================= |
| 54 | + |
| 55 | +add_executable(unittesting tests/empty.cpp) |
| 56 | +target_link_libraries(unittesting gtest gmock_main Threads::Threads) |
| 57 | + |
| 58 | +add_test(NAME do_unittests COMMAND unittesting) |
| 59 | + |
| 60 | +# ================================= TEST COVERAGE ======================================= |
| 61 | +if (CMAKE_BUILD_TYPE STREQUAL "Debug") |
| 62 | + include(${cmake-modules_SOURCE_DIR}/CodeCoverage.cmake) |
| 63 | + |
| 64 | + if (CMAKE_CXX_FLAGS_COVERAGE) |
| 65 | + APPEND_COVERAGE_COMPILER_FLAGS() |
| 66 | + SETUP_TARGET_FOR_COVERAGE(NAME collect_coverage |
| 67 | + EXECUTABLE ctest |
| 68 | + DEPENDENCIES unittesting) |
| 69 | + endif() |
| 70 | +endif() |
| 71 | +# =============================== END TEST COVERAGE ==================================== |
| 72 | + |
| 73 | +MESSAGE("Build type : ${CMAKE_BUILD_TYPE}") |
| 74 | +MESSAGE("Used compiler : ${CMAKE_CXX_COMPILER}") |
| 75 | +if (CMAKE_BUILD_TYPE EQUAL "Debug") |
| 76 | + MESSAGE("Compiler flags : ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG}") |
| 77 | +elseif (CMAKE_BUILD_TYPE EQUAL "Release") |
| 78 | + MESSAGE("Compiler flags : ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE}") |
| 79 | +elseif (CMAKE_BUILD_TYPE EQUAL "RelWithDebInfo") |
| 80 | + MESSAGE("Compiler flags : ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}") |
| 81 | +elseif (CMAKE_BUILD_TYPE EQUAL "MinSizeRel") |
| 82 | + MESSAGE("Compiler flags : ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_MINSIZEREL}") |
| 83 | +else() |
| 84 | + MESSAGE("Compiler flags : ${CMAKE_CXX_FLAGS}") |
| 85 | +endif() |
0 commit comments