-
Notifications
You must be signed in to change notification settings - Fork 5
/
CMakeLists.txt
162 lines (128 loc) · 3.55 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
project(appster)
cmake_minimum_required(VERSION 3.0.2)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
##
# Options
##
option(BUILD_REDIS "enables or disables redis module" ON)
option(BUILD_SQL "enables or disables sql module" ON)
option(BUILD_SSL "enables or disables tls/ssl extenstion" ON)
##
# Dependencies
##
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
add_subdirectory(deps)
include_directories(SYSTEM deps)
find_package(Hiredis)
find_package(PostgreSQL)
find_package(OpenSSL)
find_package(libdill REQUIRED)
find_package(LibUV REQUIRED)
include_directories(
${HIREDIS_INCLUDE_DIR}
${PostgreSQL_INCLUDE_DIRS}
${LIBDILL_INCLUDE_DIRS}
${LIBUV_INCLUDE_DIRS}
${OPENSSL_INCLUDE_DIR}
)
if(HIREDIS_FOUND)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${HIREDIS_DEFINITIONS}")
endif()
if (OPENSSL_FOUND)
add_definitions(-DHAS_CRYPTO)
endif()
##
# Files
##
set(SRC_LIST
src/appster.c
src/format.c
src/log.c
src/schema.c
)
if (OPENSSL_FOUND)
set(SRC_LIST ${SRC_LIST} src/crypto.c)
endif()
if(HIREDIS_FOUND)
set(SRC_LIST ${SRC_LIST} src/module/redis.c)
endif()
if(PostgreSQL_FOUND)
set(SRC_LIST ${SRC_LIST} src/module/sql.c)
endif()
##
# Link
##
add_library(object_${PROJECT_NAME} OBJECT ${SRC_LIST})
set_property(TARGET object_${PROJECT_NAME} PROPERTY POSITION_INDEPENDENT_CODE 1)
add_library(shared_${PROJECT_NAME} SHARED $<TARGET_OBJECTS:object_${PROJECT_NAME}>)
add_library(static_${PROJECT_NAME} STATIC $<TARGET_OBJECTS:object_${PROJECT_NAME}>)
target_link_libraries(static_${PROJECT_NAME}
deps
)
target_link_libraries(shared_${PROJECT_NAME}
deps
)
target_link_libraries(static_${PROJECT_NAME}
${HIREDIS_LIBRARIES}
${PostgreSQL_LIBRARIES}
${LIBDILL_LIBRARIES}
${LIBUV_LIBRARIES}
${OPENSSL_LIBRARIES}
)
target_link_libraries(shared_${PROJECT_NAME}
${HIREDIS_LIBRARIES}
${PostgreSQL_LIBRARIES}
${LIBDILL_LIBRARIES}
${LIBUV_LIBRARIES}
${OPENSSL_LIBRARIES}
)
##
# Compiler & linker flags
##
set(CMAKE_C_FLAGS "-Wall -Wpedantic -Wno-sign-compare -Wno-variadic-macros")
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0 -fsanitize=address -fno-omit-frame-pointer -Wno-unused-function")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address -static-libasan")
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0")
else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2")
endif()
##
# Examples
##
add_executable(example_read src/examples/read.c)
add_executable(example_write src/examples/write.c)
target_link_libraries(example_read static_${PROJECT_NAME} deps)
target_link_libraries(example_write static_${PROJECT_NAME} deps)
if(HIREDIS_FOUND)
add_executable(example_redis
src/examples/redis.c
)
target_link_libraries(example_redis
static_${PROJECT_NAME}
deps
)
endif()
if(PostgreSQL_FOUND)
add_executable(example_sql
src/examples/sql.c
)
target_link_libraries(example_sql
static_${PROJECT_NAME}
deps
)
endif()
##
# Installation
##
set (LIB_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/lib")
set (INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/include/appster")
install(TARGETS shared_${PROJECT_NAME} DESTINATION "${LIB_INSTALL_DIR}")
install(TARGETS static_${PROJECT_NAME} DESTINATION "${LIB_INSTALL_DIR}")
install(FILES src/appster.h DESTINATION ${INCLUDE_INSTALL_DIR})
if(HIREDIS_FOUND)
install(FILES src/module/redis.h DESTINATION "${INCLUDE_INSTALL_DIR}/module")
endif()
if(PostgreSQL_FOUND)
install(FILES src/module/sql.h DESTINATION "${INCLUDE_INSTALL_DIR}/module")
endif()