-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
88 lines (63 loc) · 2.46 KB
/
CMakeLists.txt
File metadata and controls
88 lines (63 loc) · 2.46 KB
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
cmake_minimum_required(VERSION 3.20)
project(cpp-template VERSION 2024.1
LANGUAGES CXX
HOMEPAGE_URL "https://github.com/maseiler/cpp-template")
#####################################################################
# Dependencies
#####################################################################
include(FetchContent)
# Boost
###################################
find_package(Boost REQUIRED)
# Google Test
###################################
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest
GIT_TAG v1.14.0)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_GetProperties(googletest)
if (NOT catch_POPULATED)
FetchContent_Populate(googletest)
add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR}
EXCLUDE_FROM_ALL)
endif ()
add_executable(${PROJECT_NAME}-tests
tests/MyClassTest.cpp)
target_link_libraries(${PROJECT_NAME}-tests
PRIVATE gtest_main ${PROJECT_NAME}::${PROJECT_NAME})
# Google Benchmark
###################################
set(BENCHMARK_ENABLE_TESTING off)
FetchContent_Declare(
googlebenchmark
GIT_REPOSITORY https://github.com/google/benchmark.git
GIT_TAG v1.8.3)
FetchContent_MakeAvailable(googlebenchmark)
add_executable(${PROJECT_NAME}-benchmarks
benchmarks/MyClassBenchmark.cpp)
target_link_libraries(${PROJECT_NAME}-benchmarks
PRIVATE benchmark::benchmark ${PROJECT_NAME}::${PROJECT_NAME})
#####################################################################
# Libraries
#####################################################################
add_library(${PROJECT_NAME}
src/MyLib/MyClass.cpp)
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
set_target_properties(${PROJECT_NAME} PROPERTIES
VERSION ${PROJECT_VERSION})
target_include_directories(${PROJECT_NAME}
PUBLIC include
PRIVATE src)
target_link_libraries(${PROJECT_NAME}
PRIVATE Boost::boost)
#####################################################################
# Compiler options
#####################################################################
target_compile_options(${PROJECT_NAME}
PRIVATE -Wall -Wextra -pedantic -Werror)
target_compile_options(${PROJECT_NAME}-tests
PRIVATE -Wall -Wextra -pedantic -Werror)
target_compile_features(${PROJECT_NAME}
PRIVATE cxx_std_17)