-
Notifications
You must be signed in to change notification settings - Fork 9
/
CMakeLists.txt
113 lines (84 loc) · 2.63 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
111
112
113
cmake_minimum_required(VERSION 3.0)
# Define project name
project(fish_protocol)
# add_compile_options(-Werror)
add_compile_options(-Wall)
add_compile_options(-std=c++14)
# 消除boost的note
add_compile_options(-D=BOOST_BIND_GLOBAL_PLACEHOLDERS)
# 开启Debug模式
SET(CMAKE_BUILD_TYPE "RELEASE")
# 添加头文件
include_directories(
include
${Boost_INCLUDE_DIRS}
)
# 查找依赖
find_package(Boost REQUIRED COMPONENTS thread)
if(NOT Boost_FOUND)
message("NOT found Boost")
endif()
#***************************************动态库生成************************************************#
# 库文件
file(GLOB_RECURSE FISH_PROTOCOL_LIB_SRC "src/*.cpp")
# 添加动态库
add_library(${PROJECT_NAME} SHARED ${FISH_PROTOCOL_LIB_SRC})
target_link_libraries(${PROJECT_NAME} pthread boost_thread )
#***************************************动态库生成************************************************#
#***************************************DEBUG模式配置************************************************#
if(${CMAKE_BUILD_TYPE} MATCHES "DEBUG")
# 添加测试文件
file(GLOB_RECURSE FISH_PROTOCOL_TESTS "tests/*_test.cpp")
find_package(GTest REQUIRED)
if(NOT GTest_FOUND)
message("NOT found GTest")
endif()
# 添加测试可执行文件
add_executable(${PROJECT_NAME}_test
${FISH_PROTOCOL_TESTS}
${FISH_PROTOCOL_LIB_SRC}
)
target_link_libraries(${PROJECT_NAME}_test
${Boost_LIBRARIES}
gtest
)
# 代码格式检查
set(CPPLINT_SRC ${FISH_PROTOCOL_SRC} ${FISH_PROTOCOL_TESTS})
list(REMOVE_DUPLICATES CPPLINT_SRC)
foreach(v ${CPPLINT_SRC})
execute_process(
COMMAND cpplint --quiet ${v}
ERROR_VARIABLE _result
)
if( _result)
message(FATAL "cpplint check failed! \n ${_result}")
endif()
endforeach(v)
endif()
#***************************************DEBUG模式配置************************************************#
#***************************************INSTALL相关************************************************#
# 生成配置文件,安装到系统
install(
DIRECTORY include/
DESTINATION include
)
install(
TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin
INCLUDES DESTINATION include
)
# add lib.config
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
${PROJECT_NAME}Config.cmake
VERSION 1.0
COMPATIBILITY AnyNewerVersion
)
install(EXPORT ${PROJECT_NAME}
FILE ${PROJECT_NAME}Config.cmake
DESTINATION lib/cmake/${PROJECT_NAME}
)
#***************************************INSTALL相关************************************************#