-
Notifications
You must be signed in to change notification settings - Fork 24
/
CMakeLists.txt
205 lines (166 loc) · 6.48 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
cmake_minimum_required(VERSION 3.15.0 FATAL_ERROR)
set (WAMPCC_VERSION_MAJOR 1)
set (WAMPCC_VERSION_MINOR 6)
set (WAMPCC_VERSION "${WAMPCC_VERSION_MAJOR}.${WAMPCC_VERSION_MINOR}")
project(wampcc VERSION ${WAMPCC_VERSION})
# Allows for setting MSVC static runtime
cmake_policy(SET CMP0091 NEW)
# Version number
# Include extra cmake modules
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/cmake")
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
##
## Platform based options defaults
##
if(CMAKE_HOST_UNIX)
set(DEFAULT_BUILD_SHARED_LIBS "ON")
set(DEFAULT_BUILD_UTILS "ON")
else()
set(DEFAULT_BUILD_SHARED_LIBS "OFF")
set(DEFAULT_BUILD_UTILS "OFF")
endif()
##
## Build options
##
option (BUILD_SHARED_LIBS "Use shared libraries" ${DEFAULT_BUILD_SHARED_LIBS})
option (BUILD_STATIC_LIBS "Use static libraries" ON)
option (BUILD_EXAMPLES "Build example apps" ON)
option (BUILD_UTILS "Build utility apps" ${DEFAULT_BUILD_UTILS})
option (BUILD_TESTS "Build test apps" OFF)
if (MSVC)
option (USE_STATIC_RUNTIME "Build using statuc runtime" OFF)
endif()
set(LibUV_DIR "" CACHE STRING "libuv installation directory")
set(JANSSON_DIR "" CACHE STRING "Jansson installation directory")
include(GNUInstallDirs)
set(INSTALL_BIN_DIR "${CMAKE_INSTALL_BINDIR}" CACHE PATH "Installation directory for executables")
set(INSTALL_LIB_DIR "${CMAKE_INSTALL_LIBDIR}" CACHE PATH "Installation directory for libraries")
set(INSTALL_INC_DIR "${CMAKE_INSTALL_INCLUDEDIR}" CACHE PATH "Installation directory for headers")
set(INSTALL_PKGCONFIG_DIR "${CMAKE_INSTALL_LIBDIR}/pkgconfig" CACHE PATH "Installation directory for pkgconfig (.pc) files")
set(INSTALL_CMAKE_DIR "${INSTALL_LIB_DIR}/cmake/wampcc" CACHE PATH "Installation directory for CMake config files")
# Allow settin of RPATH for install
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
##
## Platform checks, and generate config.h
##
include(PlatformCheck)
include(CheckLibraryExists)
##
## Compiler settings
##
# Only enable warning flags for Linux, since there are too many warning
# generated by Visual Studio
if(CMAKE_HOST_UNIX)
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag(-Wall temp)
if(temp)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
endif()
endif()
##
## Try to find libssl
##
find_package(OpenSSL REQUIRED)
##
## Try to find libuv
##
find_package(LibUV REQUIRED)
set(HAVE_LIBUV ON)
##
## Try to find jansson
##
find_package(Jansson REQUIRED)
set(HAVE_JANSSON ON)
##
## Find Threads on Linux systems, for compiling EXAMPLES or UTILS
##
if(CMAKE_HOST_UNIX)
find_package(Threads REQUIRED)
endif()
message(STATUS "OpenSSL_INCLUDE_DIR: " ${OPENSSL_INCLUDE_DIR})
message(STATUS "OpenSSL_LIBRARIES: " ${OPENSSL_LIBRARIES})
message(STATUS "LibUV_INCLUDE_DIRS: " ${LibUV_INCLUDE_DIRS})
message(STATUS "LibUV_LIBRARIES: " ${LibUV_LIBRARIES})
message(STATUS "JANSSON_INCLUDE_DIR: " ${JANSSON_INCLUDE_DIR})
message(STATUS "JANSSON_LIBRARY: " ${JANSSON_LIBRARY})
message(STATUS "JANSSON_VERSION: " ${JANSSON_VERSION})
# configure a header file to pass some of the CMake settings
# to the source code
configure_file (
"${PROJECT_SOURCE_DIR}/cmake/config.h.incmake"
"${PROJECT_BINARY_DIR}/config.h"
)
# pkg-config
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/wampcc.pc.incmake"
"${CMAKE_CURRENT_BINARY_DIR}/wampcc.pc" @ONLY)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/wampcc_json.pc.incmake"
"${CMAKE_CURRENT_BINARY_DIR}/wampcc_json.pc" @ONLY)
# check websocketpp is available in the source tree
set(websocketpp "${PROJECT_SOURCE_DIR}/3rdparty/websocketpp/websocketpp/message_buffer/message.hpp")
message(STATUS "checking for ${websocketpp}")
if(NOT EXISTS "${websocketpp}")
message(FATAL_ERROR "websocketpp header not found! Check that websocketpp is unzipped under 3rdparty/")
endif()
# check msgpack is available in the source tree
set(msgpackfile "${PROJECT_SOURCE_DIR}/3rdparty/msgpack-c/include/msgpack.h")
message(STATUS "checking for ${msgpackfile}")
if(NOT EXISTS "${msgpackfile}")
message(FATAL_ERROR "msgpack header not found! Check that msgpack is unzipped under 3rdparty/")
endif()
# add the binary tree to the search path for include files
# so that we will find config.h
include_directories("${PROJECT_BINARY_DIR}")
include_directories("${PROJECT_SOURCE_DIR}/include")
include_directories("${PROJECT_SOURCE_DIR}/3rdparty/websocketpp")
include_directories("${PROJECT_SOURCE_DIR}/3rdparty")
# add external dependencies after the wampcc includes
include_directories(${OPENSSL_INCLUDE_DIR})
# include sub directories
add_subdirectory(libs/json)
add_subdirectory(libs/wampcc)
add_subdirectory(utils)
add_subdirectory(tests)
add_subdirectory(examples)
install(FILES ${PROJECT_BINARY_DIR}/wampcc.pc DESTINATION "${INSTALL_PKGCONFIG_DIR}" COMPONENT dev)
install(FILES ${PROJECT_BINARY_DIR}/wampcc_json.pc DESTINATION "${INSTALL_PKGCONFIG_DIR}" COMPONENT dev)
#
# Compile statically against MSVC runtime if option is enabled
#
if (USE_STATIC_RUNTIME AND MSVC)
foreach(t ${TO_INSTALL})
set_property(TARGET ${t} PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endforeach()
endif()
#
# Export CMake config
#
# Here we create a CMake config and export targets, and them to the
# install target. This allows users that are using CMake to easily use
# wampcc by doing `find_package(wampcc)` in their CMake project. They
# can the refer to the wampcc targets by depdending on the
# 'wampcc::wampcc_shared' or 'wampcc::wampcc_static'.
include(CMakePackageConfigHelpers)
write_basic_package_version_file(wampccConfigVersion.cmake
VERSION ${PACKAGE_VERSION}
COMPATIBILITY AnyNewerVersion)
configure_package_config_file(cmake/wampccConfig.cmake.in wampccConfig.cmake INSTALL_DESTINATION ${INSTALL_CMAKE_DIR})
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/wampccConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/wampccConfigVersion.cmake"
DESTINATION ${INSTALL_CMAKE_DIR}
COMPONENT dev)
# Export any custom "Find<PackageName>.cmake" files
FILE(GLOB CUSTOM_MODULE_FIND_FILES "${CMAKE_CURRENT_LIST_DIR}/cmake/Find*.cmake")
install(FILES ${CUSTOM_MODULE_FIND_FILES}
DESTINATION ${INSTALL_CMAKE_DIR}/find_modules
COMPONENT dev)
get_property(EXPORT_TARGETS GLOBAL PROPERTY WAMPCC_INSTALL_TARGETS)
install(EXPORT wampccExportTargets
FILE wampccTargets.cmake
NAMESPACE wampcc::
DESTINATION ${INSTALL_CMAKE_DIR}
COMPONENT dev)
include(cmake/MakeDebPackages.cmake)