-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
89 lines (73 loc) · 2.83 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# CMakeList.txt : Top-level CMake project file, do global configuration
# and include sub-projects here.
#
cmake_minimum_required (VERSION 3.8)
project ("sudoku-solver")
# GoogleTest requires at least C++14
set(CMAKE_CXX_STANDARD 14)
# To organize projects in VisualStudio:
if(MSVC)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
endif(MSVC)
option(BUILD_SUDOKU_TESTS OFF)
option(CODE_COVERAGE OFF)
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
find_package(CPPCHECK)
if(CPPCHECK_FOUND)
#set(CMAKE_CXX_CPPCHECK "${CPPCHECK_BIN};--std=c++${CMAKE_CXX_STANDARD};--verbose;--quiet")
endif()
### Tests setup
if(BUILD_SUDOKU_TESTS)
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG v1.13.0
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
if(MSVC)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
endif(MSVC)
FetchContent_MakeAvailable(googletest)
if(MSVC)
set_target_properties(gtest PROPERTIES FOLDER "external/Google")
set_target_properties(gmock PROPERTIES FOLDER "external/Google")
set_target_properties(gtest_main PROPERTIES FOLDER "external/Google")
set_target_properties(gmock_main PROPERTIES FOLDER "external/Google")
endif(MSVC)
enable_testing()
include(CTest)
endif(BUILD_SUDOKU_TESTS)
### Code Coverage
if(CMAKE_BUILD_TYPE STREQUAL "coverage" OR CODE_COVERAGE)
if("${CMAKE_C_COMPILER_ID}" MATCHES "(Apple)?[Cc]lang" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "(Apple)?[Cc]lang")
message("Building with llvm Code Coverage Tools")
# Warning/Error messages
if(NOT LLVM_COV_PATH)
message(FATAL_ERROR "llvm-cov not found! Aborting.")
endif()
# set Flags
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-instr-generate -fcoverage-mapping")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-instr-generate -fcoverage-mapping")
elseif(CMAKE_COMPILER_IS_GNUCXX)
message("Building with lcov Code Coverage Tools")
# Warning/Error messages
if(NOT (CMAKE_BUILD_TYPE STREQUAL "Debug"))
message(WARNING "Code coverage results with an optimized (non-Debug) build may be misleading")
endif()
find_program(LCOV_PATH lcov)
if(NOT LCOV_PATH)
message(FATAL_ERROR "lcov not found! Aborting...")
endif()
find_program(GENHTML_PATH lcov)
if(NOT GENHTML_PATH)
message(FATAL_ERROR "genhtml not found! Aborting...")
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage -fprofile-arcs -ftest-coverage")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage -fprofile-arcs -ftest-coverage")
else()
message(FATAL_ERROR "Code coverage requires Clang or GCC. Aborting.")
endif()
endif()
# Include sub-projects.
add_subdirectory ("sudoku-solver")