-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
73 lines (61 loc) · 1.52 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
cmake_minimum_required(VERSION 3.17)
# Name of the CMake project
project(Template)
# C++ standard you want to use for the project
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_LIST_DIR})
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_BINARY_DIR})
option(UNIT_TESTS "When sets to ON, build the unit tests" OFF)
if(UNIT_TESTS)
# Bin name of the unit tests
set(BIN unit_tests)
else()
# Bin name of the project
set(BIN binary)
endif()
# Fetch GoogleTest
if(UNIT_TESTS)
find_package(googletest QUIET)
include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/refs/tags/release-1.11.0.zip
)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
endif()
# Build flags
if(UNIX)
add_compile_options(-Wall -Wextra -Weffc++)
elseif(WIN32)
add_compile_options(/W4)
endif()
# Location of the main source file
set(MAIN src/main.cpp)
# List of source files
set(SOURCES
# fill here
)
# List of tests source files
set(TEST_SOURCES
tests/test.cpp
)
# Executable settings
if(UNIT_TESTS)
add_executable(${BIN}
${SOURCES}
${TEST_SOURCES}
)
enable_testing()
include(GoogleTest)
gtest_discover_tests(${BIN})
target_link_libraries(${BIN} PRIVATE gtest_main)
else()
add_executable(${BIN}
${MAIN}
${SOURCES}
)
endif()
# Include path of the project
target_include_directories(${BIN} PRIVATE include)