-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
81 lines (64 loc) · 2.82 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
cmake_minimum_required(VERSION 3.10)
PROJECT(XWatcher)
set(CMAKE_CXX_FLAGS "-fPIC")
set(CMAKE_INCLUDE_CURRENT_DIR ON)
SET(AppVersion 0.5.1)
SET(XWatcher_Version ${PROJECT_NAME}_${AppVersion})
# 默认输出debug版
#SET(CMAKE_BUILD_TYPE "Release")
#SET(CMAKE_BUILD_TYPE "debug")
SET(CMAKE_BUILD_TYPE "RelWithDebInfo")
set(CMAKE_CXX_STANDARD 17)
macro(Get_CommitID APP_COMMITID)
find_package(Git QUIET) # 查找Git,QUIET静默方式不报错
if(GIT_FOUND)
execute_process( # 执行一个子进程
COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD # 命令
OUTPUT_VARIABLE ${APP_COMMITID} # 输出字符串存入变量
OUTPUT_STRIP_TRAILING_WHITESPACE # 删除字符串尾的换行符
ERROR_QUIET # 对执行错误静默
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} # 执行路径
)
endif()
endmacro()
macro(Get_UtilsCommitID GIT_UTILSCOMMITID)
find_package(Git QUIET) # 查找Git,QUIET静默方式不报错
if(GIT_FOUND)
execute_process( # 执行一个子进程
COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD # 命令
OUTPUT_VARIABLE ${GIT_UTILSCOMMITID} # 输出字符串存入变量
OUTPUT_STRIP_TRAILING_WHITESPACE # 删除字符串尾的换行符
ERROR_QUIET # 对执行错误静默
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../Utils/ # 执行路径
)
endif()
endmacro()
set(APP_COMMITID "")
Get_CommitID(APP_COMMITID)
message(STATUS "AppCommitID is ${APP_COMMITID}")
set(UTILS_COMMITID "")
Get_UtilsCommitID(UTILS_COMMITID)
message(STATUS "UtilsCommitID is ${UTILS_COMMITID}")
SET(APIVersion "")
add_definitions(-DAPP_COMMITID=\"${APP_COMMITID}\")
add_definitions(-DUTILS_COMMITID=\"${UTILS_COMMITID}\")
add_definitions(-DAPI_VERSION=\"${APIVersion}\")
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../Utils/)
# HP-Scoket
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../XAPI/HP-Socket/5.8.2/include/)
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/../XAPI/HP-Socket/5.8.2/lib)
# SPDLog
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../XAPI/SPDLog/1.8.5/include/)
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/../XAPI/SPDLog/1.8.5/lib)
# YAML-CPP
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../XAPI/YAML-CPP/0.8.0/include/)
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/../XAPI/YAML-CPP/0.8.0/lib)
# Parallel HashMap
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../XAPI/parallel_hashmap/)
set(SOURCES main.cpp
HPPackServer.cpp
HPPackClient.cpp
WatcherEngine.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../Utils/Logger.cpp)
add_executable(${XWatcher_Version} ${SOURCES})
target_link_libraries(${XWatcher_Version} spdlog pthread hpsocket4c yaml-cpp)