-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
98 lines (82 loc) · 3.72 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
cmake_minimum_required(VERSION 3.0.2)
project(cppim)
message(STATUS "CMake version: " ${CMAKE_VERSION})
#定义 __FILENAME__ 宏,相对路径,仅仅在 GCC 编译器 上有效
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__FILENAME__='\"$(subst ${CMAKE_CURRENT_SOURCE_DIR}/,,$(abspath $<))\"'")
set(CMAKE_C_COMPILER gcc)
set(CMAKE_CXX_COMPILER g++)
#set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fexceptions -Wno-unused -ffunction-sections -fdata-sections")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fexceptions -static-libstdc++")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fexceptions -fcheck-new -fnon-call-exceptions ")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,-rpath,../lib/so/")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused -Wreorder -ffunction-sections -fdata-sections")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer")
#ASAN
if(OPEN_MEMORY_CHECK)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libasan")
message(STATUS "Open memory check")
endif(OPEN_MEMORY_CHECK)
#gperftools
if(GPERFTOOLS)
add_definitions(-DGPERFTOOLS)
link_libraries(tcmalloc)
link_libraries(profiler)
message(STATUS "Open gperftools")
endif(GPERFTOOLS)
#debug
set(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -DDEBUG -O0 -Wall")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wextra -Wpointer-arith")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wunreachable-code -Woverloaded-virtual")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wdouble-promotion -g -ggdb -fpic -fPIC")
#release
set(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -DNDEBUG -Os -Wall")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wextra -Wpointer-arith")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wdouble-promotion -Woverloaded-virtual")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -g -fpic -fPIC")
message(STATUS "Compiler version: ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_VERSION}")
#ASIO 不使用 Boost 库
add_definitions(-DASIO_STANDALONE)
#Spdlog 使用外部 Fmt 库
#add_definitions(-DSPDLOG_FMT_EXTERNAL)
#ADD_COMPILE_OPTIONS(-g -std=c++14 -O2 -Wcomment -Wformat -Wmain -Wparentheses -Wswitch -Wunused -Wuninitialized -Wall)
set(EXECUTABLE_OUTPUT_PATH "${CMAKE_SOURCE_DIR}/bin")
set(LIBRARY_OUTPUT_PATH "${CMAKE_BINARY_DIR}/lib/${CMAKE_BUILD_TYPE}/")
#set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
#set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
#set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin)
#link_directories(/usr/lib64/mysql)
#set(CPP_DIRS common chatserver gateserver httpserver test riskserver)
#message(STATUS "${PROJECT_NAME}, dirs: ${CPP_DIRS}")
#foreach(EXTENSION ${CPP_EXTENSIONS})
# foreach(DIR ${CPP_DIRS})
# file(GLOB_RECURSE FIND_FILES ${CMAKE_CURRENT_SOURCE_DIR}/${DIR}/${EXTENSION})
# list(APPEND FORMAT_ALL_FILES ${FIND_FILES})
# endforeach()
#endforeach()
#
#
#add_custom_target(format-all
# COMMAND clang-format -style=\"{BasedOnStyle: google}\" -i ${FORMAT_ALL_FILES}
# COMMAND cpplint --verbose=0 --quiet ${FORMAT_ALL_FILES})
#
#add_custom_target(format)
link_directories(${LIBRARY_OUTPUT_PATH})
link_directories(/usr/local/lib/)
include_directories(${CMAKE_SOURCE_DIR}/opt/spdlog/include/)
include_directories(${CMAKE_SOURCE_DIR}/opt/cpptoml/include/)
include_directories(${CMAKE_SOURCE_DIR}/opt/)
include_directories(${CMAKE_SOURCE_DIR}/rate/)
include_directories(/usr/local/include/)
#add_subdirectory(opt)
add_subdirectory(client)
add_subdirectory(common)
add_subdirectory(http)
add_subdirectory(rpc)
add_subdirectory(net)
add_subdirectory(redis)
add_subdirectory(protocol)
add_subdirectory(logicserver)
add_subdirectory(gateserver)
add_subdirectory(jobserver)