-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
111 lines (93 loc) · 1.87 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
cmake_minimum_required(VERSION 3.22 FATAL_ERROR)
project(
cmake-cpp-starter-kit
LANGUAGES CXX
VERSION 1.0
)
# Project Options
option(
build_testing
"build testing"
ON
)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# setup cpm
set(CPM_DOWNLOAD_LOCATION ${CMAKE_BINARY_DIR}/CPM.cmake)
file(DOWNLOAD
https://github.com/cpm-cmake/CPM.cmake/releases/latest/download/cpm.cmake
${CPM_DOWNLOAD_LOCATION})
include(${CPM_DOWNLOAD_LOCATION})
# abseil
set(ABSL_PROPAGATE_CXX_STD ON)
CPMAddPackage(
NAME absl
GITHUB_REPOSITORY "abseil/abseil-cpp"
GIT_TAG "20230125.3"
)
# proto
# add_subdirectory(proto)
# include_directories(${CMAKE_BINARY_DIR}/proto)
set(BIN_NAME main)
set(LIB_NAME lib${PROJECT_NAME})
include_directories(${CMAKE_SOURCE_DIR}/include)
# Project lib
# Some code which is irrelevant to environment. This is benefit to testing.
file(
GLOB_RECURSE
LIB_FILES
${CMAKE_SOURCE_DIR}/source/*
)
add_library(
${LIB_NAME}
${LIB_FILES}
)
target_link_libraries(
${LIB_NAME}
#abseil
absl::base
absl::strings
absl::log
absl::log_initialize
#proto
# serviceproto
)
# project executable binary
file(
GLOB_RECURSE
BIN_FILES
${CMAKE_SOURCE_DIR}/standalone/*
)
add_executable(
${BIN_NAME}
${BIN_FILES}
)
target_link_libraries(
${BIN_NAME}
${LIB_NAME}
)
# For generate compile_commands.json
add_custom_target(
copy-if-compile ALL
${CMAKE_COMMAND} -E copy_if_different
${CMAKE_BINARY_DIR}/compile_commands.json
${CMAKE_CURRENT_LIST_DIR}/compile_commands.json
)
# For format target
file(
GLOB_RECURSE
filetofmt${PROJECT_NAME}
${CMAKE_SOURCE_DIR}/source/*
${CMAKE_SOURCE_DIR}/include/*
${CMAKE_SOURCE_DIR}/standalone/*
)
add_custom_target(
format
command clang-format -i
filetofmt${PROJECT_NAME}
)
if (build_testing)
# test
add_subdirectory(test)
endif()