forked from nats-io/nats.c
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
167 lines (136 loc) · 5.57 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
163
164
165
166
cmake_minimum_required(VERSION 2.8)
project(cnats)
include(CTest)
# Uncomment to have the build process verbose
#set(CMAKE_VERBOSE_MAKEFILE TRUE)
# Uncomment to have the executable moved to 'build' instead of their respective 'build/xxx' directories
#set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
option(NATS_UPDATE_VERSION "Update the version file" OFF)
option(NATS_UPDATE_DOC "Update the doc template file" OFF)
option(NATS_COVERAGE "Code coverage" OFF)
option(NATS_BUILD_WITH_TLS "Build with TLS support" ON)
option(NATS_BUILD_WITH_TLS_CLIENT_METHOD "Use TLS_client_method()" OFF)
option(NATS_BUILD_EXAMPLES "Build examples" ON)
option(NATS_BUILD_LIBUV_EXAMPLE "Build libuv examples" OFF)
option(NATS_BUILD_LIBEVENT_EXAMPLE "Build libevent examples" OFF)
option(NATS_BUILD_STATIC_EXAMPLES "Statically link examples" OFF)
option(NATS_BUILD_STREAMING "Build NATS Streaming" ON)
option(NATS_BUILD_NO_PREFIX_CONNSTS "No prefix for connection status enum" OFF)
if(NATS_BUILD_WITH_TLS)
find_package(OpenSSL REQUIRED)
endif(NATS_BUILD_WITH_TLS)
set(LIBUV_DIR "/usr/local/" CACHE PATH "Libuv install directory")
set(LIBEVENT_DIR "/usr/local/" CACHE PATH "Libevent install directory")
set(NATS_DOC_PROJECT_NAME "NATS C Client")
if(NATS_BUILD_STREAMING)
set(PROTOBUF_DIR "${PROJECT_SOURCE_DIR}/pbuf")
add_definitions(-DNATS_HAS_STREAMING)
set(NATS_DOC_INCLUDE_STREAMING "NATS_HAS_STREAMING")
set(NATS_DOC_PROJECT_NAME "NATS C Client with Streaming support")
endif(NATS_BUILD_STREAMING)
if(NATS_BUILD_NO_PREFIX_CONNSTS)
add_definitions(-DNATS_CONN_STATUS_NO_PREFIX)
endif(NATS_BUILD_NO_PREFIX_CONNSTS)
# Platform specific settings
if(UNIX)
#---------------------------------------------------------------------------
# Define NATS cache variables that override the CMAKE and MEMCHECK variables
#---------------------------------------------------------------------------
include(GNUInstallDirs)
set(NATS_LIBDIR ${CMAKE_INSTALL_LIBDIR})
set(NATS_INCLUDE_DIR ${CMAKE_INSTALL_INCLUDEDIR})
set(NATS_BUILD_TYPE Release CACHE STRING "Build type: Release, Debug, RelWithDebInfo, MinRelSize")
set(CMAKE_BUILD_TYPE ${NATS_BUILD_TYPE} CACHE INTERNAL "")
set(NATS_BUILD_ARCH "64" CACHE STRING "32 for 32bits builds")
set(NATS_MEMCHECK_CMD "/usr/bin/valgrind" CACHE FILE "Memcheck tool")
set(MEMORYCHECK_COMMAND ${NATS_MEMCHECK_CMD} CACHE INTERNAL "")
set(NATS_MEMCHECK_CMD_OPTS "--leak-check=full --track-fds=yes --show-reachable=yes --num-callers=50" CACHE STRING "Memcheck options")
set(MEMORYCHECK_COMMAND_OPTIONS ${NATS_MEMCHECK_CMD_OPTS} CACHE INTERNAL "")
set(NATS_COMMON_C_FLAGS "-std=c99 -pedantic")
if(NATS_BUILD_TYPE MATCHES "Debug")
set(NATS_COMMON_C_FLAGS "${NATS_COMMON_C_FLAGS} -ggdb")
endif(NATS_BUILD_TYPE MATCHES "Debug")
set(NATS_WARNINGS "-Wall -W -Wno-unused-variable -Wno-unused-parameter -Wno-unused-function -Wstrict-prototypes -Wwrite-strings")
set(NATS_PLATFORM_INCLUDE "unix")
if(APPLE)
set(CMAKE_MACOSX_RPATH OFF)
set(NATS_OS "DARWIN")
if(NATS_BUILD_STREAMING)
set(NATS_PROTOBUF_LIB "${PROTOBUF_DIR}/lib/darwin/libprotobuf-c.a")
endif(NATS_BUILD_STREAMING)
else(APPLE)
set(NATS_OS "LINUX")
set(NATS_USE_PTHREAD "-pthread")
set(NATS_EXTRA_LIB "rt")
if(NATS_COVERAGE)
set(NATS_CODE_COVERAGE "--coverage")
endif()
if(NATS_BUILD_STREAMING)
set(NATS_PROTOBUF_LIB "${PROTOBUF_DIR}/lib/linux/libprotobuf-c.so")
endif(NATS_BUILD_STREAMING)
endif(APPLE)
if (${NATS_BUILD_ARCH} MATCHES "32")
if(NOT APPLE)
message("-----------------------------------------------------------")
message("If build fails, you probably need to install libc6-dev-i386")
message("apt-get install libc6-dev-i386")
message("-----------------------------------------------------------")
endif(NOT APPLE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32")
set(CMAKE_C_LINKER_FLAGS "${CMAKE_C_LINKER_FLAGS} -m32")
endif(${NATS_BUILD_ARCH} MATCHES "32")
elseif(WIN32)
set(NATS_LIBDIR "lib")
set(NATS_INCLUDE_DIR "include")
set(NATS_EXTRA_LIB "Ws2_32")
set(NATS_OS "_WIN32")
set(NATS_PLATFORM_INCLUDE "win")
if(NATS_BUILD_STREAMING)
set(NATS_PROTOBUF_LIB "${PROTOBUF_DIR}/lib/win/protobuf-c.lib")
endif(NATS_BUILD_STREAMING)
endif(UNIX)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${NATS_CODE_COVERAGE} ${NATS_COMMON_C_FLAGS} ${NATS_USE_PTHREAD} ${NATS_WARNINGS}")
if(UNIX)
if(APPLE)
add_definitions(-DNATS_USE_X_LOCALE)
else(APPLE)
add_definitions(-D_GNU_SOURCE)
endif(APPLE)
endif(UNIX)
add_definitions(-D${NATS_OS})
add_definitions(-D_REENTRANT)
if(NATS_BUILD_WITH_TLS)
add_definitions(-DNATS_HAS_TLS)
if(NATS_BUILD_WITH_TLS_CLIENT_METHOD)
add_definitions(-DNATS_USE_TLS_CLIENT_METHOD)
endif(NATS_BUILD_WITH_TLS_CLIENT_METHOD)
endif(NATS_BUILD_WITH_TLS)
#------------
# Versionning and Doc
set(NATS_VERSION_MAJOR 1)
set(NATS_VERSION_MINOR 8)
set(NATS_VERSION_PATCH 0)
set(NATS_VERSION_SUFFIX "-beta")
set(NATS_VERSION_REQUIRED_NUMBER 0x010100)
if(NATS_UPDATE_VERSION OR NATS_UPDATE_DOC)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/src/version.h.in
${CMAKE_CURRENT_SOURCE_DIR}/src/version.h
@ONLY)
configure_file(
${CMAKE_SOURCE_DIR}/doc/DoxyFile.NATS.Client.in
${CMAKE_SOURCE_DIR}/doc/DoxyFile.NATS.Client
@ONLY)
endif(NATS_UPDATE_VERSION OR NATS_UPDATE_DOC)
#------------
#----------------------------
# Add the project directories
add_subdirectory(src)
add_subdirectory(examples)
add_subdirectory(examples/getstarted)
if(NATS_BUILD_STREAMING)
add_subdirectory(examples/stan)
endif()
add_subdirectory(test)
add_subdirectory(test/dylib)
#----------------------------