-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
98 lines (79 loc) · 3.22 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.10)
set(CMAKE_CXX_STANDARD 17)
project(sylar_wxb CXX)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
MESSAGE(STATUS "This is Project source dir " ${PROJECT_SOURCE_DIR})
MESSAGE(STATUS "This is PROJECT_BINARY_DIR dir " ${PROJECT_BINARY_DIR})
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/bin)
# set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/lib)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)
MESSAGE(STATUS "This isCMAKE_MODULE_PATH " ${CMAKE_MODULE_PATH})
option(STATIC_STDLIB "Link std library static or dynamic, such as libgcc, libstdc++, libasan" ON)
MESSAGE(STATUS "HOME dir: $ENV{HOME}")
IF(WIN32)
MESSAGE(STATUS "This is windows.")
# ADD_DEFINITIONS(-DWIN32)
ELSEIF(WIN64)
MESSAGE(STATUS "This is windows.")
# ADD_DEFINITIONS(-DWIN64)
ELSEIF(APPLE)
MESSAGE(STATUS "This is apple")
# normally __MACH__ has already been defined
# ADD_DEFINITIONS(-D__MACH__ )
ELSEIF(UNIX)
MESSAGE(STATUS "This is UNIX")
# ADD_DEFINITIONS(-DUNIX -DLINUX)
ELSE()
MESSAGE(STATUS "This is UNKNOW OS")
ENDIF(WIN32)
# This is for clangd plugin for vscode
IF(RELEASE)
MESSAGE(STATUS "Enable release")
SET(CMAKE_COMMON_FLAGS "${CMAKE_COMMON_FLAGS} -O3 -g -fipa-pta -flto=auto")
ADD_DEFINITIONS(-DRELEASE_MODE)
ELSE()
MESSAGE(STATUS "Enable debug")
SET(CMAKE_COMMON_FLAGS "${CMAKE_COMMON_FLAGS} -O0 -g")
ADD_DEFINITIONS(-DDEBUG_MODE)
ENDIF()
MESSAGE(STATUS "CMAKE_CXX_COMPILER_ID is " ${CMAKE_CXX_COMPILER_ID})
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND ${STATIC_STDLIB})
ADD_LINK_OPTIONS(-static-libgcc -static-libstdc++)
ENDIF()
# ----------------------------- sys include and lib -------------------------------
IF (EXISTS /usr/local/lib)
LINK_DIRECTORIES (/usr/local/lib)
ENDIF ()
IF (EXISTS /usr/local/lib64)
LINK_DIRECTORIES (/usr/local/lib64)
ENDIF ()
INCLUDE_DIRECTORIES(/usr/local/include ${CMAKE_SOURCE_DIR}/include)
# ---------------------------- include and src ------------------------------------------------
include_directories(${CMAKE_SOURCE_DIR}/sylar)
file(GLOB SRC
"${CMAKE_SOURCE_DIR}/sylar/*.cpp"
"${CMAKE_SOURCE_DIR}/sylar/util/*.cpp")
# ------------------------------------ deps --------------------------------------------
set(3RD ${CMAKE_SOURCE_DIR}/deps/3rd/)
include_directories(${3RD}/yaml-cpp/include
${3RD}/boost_1_84_0/include
${3RD}/jsoncpp/include
${3RD}/protobuf-3.18.3/include
${3RD}/openssl-3.2.1/include
)
link_directories(${3RD}/yaml-cpp/lib
${3RD}/boost_1_84_0/lib
${3RD}/jsoncpp/lib
${3RD}/protobuf-3.18.3/lib
${3RD}/openssl-3.2.1/lib64
)
# ----------------------------------- other --------------------------------------------
set(CMAKE_CXX_FLAGS ${CMAKE_COMMON_FLAGS})
set(CMAKE_C_FLAGS ${CMAKE_COMMON_FLAGS})
message(STATUS "CMAKE_CXX_FLAGS is" ${CMAKE_CXX_FLAGS})
# 源代码相关宏
add_definitions(-DPROJECT_DIR="${CMAKE_SOURCE_DIR}/")
#------------------------------------ exec ----------------------------------------------
add_library(sylar ${SRC})
target_link_libraries(sylar pthread dl yaml-cpp jsoncpp protobuf ssl crypto)
add_subdirectory(tests)