2 ############ Setup project and cmake
7 # Minimum cmake requirement. We should require a quite recent
8 # cmake for the dependency find macros etc. to be up to date.
9 cmake_minimum_required (VERSION 2.6)
11 set (WEBSOCKETPP_MAJOR_VERSION 0)
12 set (WEBSOCKETPP_MINOR_VERSION 7)
13 set (WEBSOCKETPP_PATCH_VERSION 0)
14 set (WEBSOCKETPP_VERSION ${WEBSOCKETPP_MAJOR_VERSION}.${WEBSOCKETPP_MINOR_VERSION}.${WEBSOCKETPP_PATCH_VERSION})
16 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
18 set(INSTALL_INCLUDE_DIR include CACHE PATH "Installation directory for header files")
19 if (WIN32 AND NOT CYGWIN)
20 set (DEF_INSTALL_CMAKE_DIR cmake)
22 set (DEF_INSTALL_CMAKE_DIR lib/cmake/websocketpp)
24 set (INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH "Installation directory for CMake files")
26 # Make relative paths absolute (needed later on)
27 foreach (p INCLUDE CMAKE)
28 set (var INSTALL_${p}_DIR)
29 if (NOT IS_ABSOLUTE "${${var}}")
30 set (${var} "${CMAKE_INSTALL_PREFIX}/${${var}}")
34 # Set CMake library search policy
35 if (COMMAND cmake_policy)
36 cmake_policy (SET CMP0003 NEW)
37 cmake_policy (SET CMP0005 NEW)
40 # Disable unnecessary build types
41 set (CMAKE_CONFIGURATION_TYPES "Release;RelWithDebInfo;Debug" CACHE STRING "Configurations" FORCE)
43 # Include our cmake macros
44 set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
45 include (CMakeHelpers)
49 set (WEBSOCKETPP_ROOT ${CMAKE_CURRENT_SOURCE_DIR})
50 set (WEBSOCKETPP_INCLUDE ${WEBSOCKETPP_ROOT}/websocketpp)
51 set (WEBSOCKETPP_BUILD_ROOT ${CMAKE_CURRENT_BINARY_DIR})
52 set (WEBSOCKETPP_BIN ${WEBSOCKETPP_BUILD_ROOT}/bin)
53 set (WEBSOCKETPP_LIB ${WEBSOCKETPP_BUILD_ROOT}/lib)
55 # CMake install step prefix. I assume linux users want the prefix to
56 # be the default /usr or /usr/local so this is only adjusted on Windows.
57 # - Windows: Build the INSTALL project in your solution file.
58 # - Linux/OSX: make install.
60 set (CMAKE_INSTALL_PREFIX "${WEBSOCKETPP_ROOT}/install")
63 ############ Build customization
65 # Override from command line "CMake -D<OPTION>=TRUE/FALSE/0/1/ON/OFF"
66 option (ENABLE_CPP11 "Build websocketpp with CPP11 features enabled." TRUE)
67 option (BUILD_EXAMPLES "Build websocketpp examples." FALSE)
68 option (BUILD_TESTS "Build websocketpp tests." FALSE)
70 if (BUILD_TESTS OR BUILD_EXAMPLES)
74 ############ Compiler specific setup
76 set (WEBSOCKETPP_PLATFORM_LIBS "")
77 set (WEBSOCKETPP_PLATFORM_TLS_LIBS "")
78 set (WEBSOCKETPP_BOOST_LIBS "")
80 # VC9 and C++11 reasoning
81 if (ENABLE_CPP11 AND MSVC AND MSVC90)
82 message("* Detected Visual Studio 9 2008, disabling C++11 support.")
83 set (ENABLE_CPP11 FALSE)
86 # Detect clang. Not officially reported by cmake.
87 execute_process(COMMAND "${CMAKE_CXX_COMPILER}" "-v" ERROR_VARIABLE CXX_VER_STDERR)
88 if ("${CXX_VER_STDERR}" MATCHES ".*clang.*")
89 set (CMAKE_COMPILER_IS_CLANGXX 1)
95 add_definitions (-D_WEBSOCKETPP_CPP11_FUNCTIONAL_)
96 add_definitions (-D_WEBSOCKETPP_CPP11_SYSTEM_ERROR_)
97 add_definitions (-D_WEBSOCKETPP_CPP11_RANDOM_DEVICE_)
98 add_definitions (-D_WEBSOCKETPP_CPP11_MEMORY_)
100 add_definitions (-D_WEBSOCKETPP_CPP11_STL_)
106 set (WEBSOCKETPP_BOOST_LIBS system thread)
107 set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /GL /Gy /GF /Ox /Ob2 /Ot /Oi /MP /arch:SSE2 /fp:fast")
108 set (CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /LTCG /INCREMENTAL:NO /OPT:REF /OPT:ICF")
109 add_definitions (/W3 /wd4996 /wd4995 /wd4355)
110 add_definitions (-DUNICODE -D_UNICODE)
111 add_definitions (-D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS)
112 add_definitions (-DNOMINMAX)
116 if (CMAKE_COMPILER_IS_GNUCXX)
117 set (WEBSOCKETPP_PLATFORM_LIBS pthread rt)
118 set (WEBSOCKETPP_PLATFORM_TLS_LIBS ssl crypto)
119 set (WEBSOCKETPP_BOOST_LIBS system thread)
120 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
122 add_definitions (-DNDEBUG -Wall -Wcast-align) # todo: should we use CMAKE_C_FLAGS for these?
125 # Try to detect version. Note: Not tested!
126 execute_process (COMMAND ${CMAKE_CXX_COMPILER} "-dumpversion" OUTPUT_VARIABLE GCC_VERSION)
127 if ("${GCC_VERSION}" STRGREATER "4.4.0")
128 message("* C++11 support partially enabled due to GCC version ${GCC_VERSION}")
129 set (WEBSOCKETPP_BOOST_LIBS system thread)
134 if (CMAKE_COMPILER_IS_CLANGXX)
136 set (WEBSOCKETPP_PLATFORM_LIBS pthread rt)
138 set (WEBSOCKETPP_PLATFORM_LIBS pthread)
140 set (WEBSOCKETPP_PLATFORM_TLS_LIBS ssl crypto)
141 set (WEBSOCKETPP_BOOST_LIBS system thread)
142 set (CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-std=c++0x -stdlib=libc++") # todo: is libc++ really needed here?
144 add_definitions (-DNDEBUG -Wall -Wno-padded) # todo: should we use CMAKE_C_FLAGS for these?
148 # OSX, can override above.
150 add_definitions (-DNDEBUG -Wall)
154 list (APPEND WEBSOCKETPP_BOOST_LIBS random)
158 list (APPEND WEBSOCKETPP_BOOST_LIBS unit_test_framework)
161 ############ Dependencies
163 # Set BOOST_ROOT env variable or pass with cmake -DBOOST_ROOT=path.
164 # BOOST_ROOT can also be defined by a previous run from cmake cache.
165 if (NOT "$ENV{BOOST_ROOT_CPP11}" STREQUAL "")
166 # Scons documentation for BOOST_ROOT_CPP11:
167 # "look for optional second boostroot compiled with clang's libc++ STL library
168 # this prevents warnings/errors when linking code built with two different
169 # incompatible STL libraries."
170 file (TO_CMAKE_PATH "$ENV{BOOST_ROOT_CPP11}" BOOST_ROOT)
171 set (BOOST_ROOT ${BOOST_ROOT} CACHE PATH "BOOST_ROOT dependency path" FORCE)
173 if ("${BOOST_ROOT}" STREQUAL "")
174 file (TO_CMAKE_PATH "$ENV{BOOST_ROOT}" BOOST_ROOT)
175 # Cache BOOST_ROOT for runs that do not define $ENV{BOOST_ROOT}.
176 set (BOOST_ROOT ${BOOST_ROOT} CACHE PATH "BOOST_ROOT dependency path" FORCE)
179 message ("* Configuring Boost")
180 message (STATUS "-- Using BOOST_ROOT")
181 message (STATUS " " ${BOOST_ROOT})
184 set (Boost_USE_MULTITHREADED TRUE)
185 set (Boost_USE_STATIC_LIBS TRUE)
187 set (Boost_USE_MULTITHREADED FALSE)
188 set (Boost_USE_STATIC_LIBS FALSE)
192 set (Boost_USE_STATIC_LIBS TRUE)
195 if (NOT Boost_USE_STATIC_LIBS)
196 add_definitions (/DBOOST_TEST_DYN_LINK)
199 set (Boost_FIND_REQUIRED TRUE)
200 set (Boost_FIND_QUIETLY TRUE)
201 set (Boost_DEBUG FALSE)
202 set (Boost_USE_MULTITHREADED TRUE)
203 set (Boost_ADDITIONAL_VERSIONS "1.39.0" "1.40.0" "1.41.0" "1.42.0" "1.43.0" "1.44.0" "1.46.1") # todo: someone who knows better spesify these!
205 find_package (Boost 1.39.0 COMPONENTS "${WEBSOCKETPP_BOOST_LIBS}")
208 # Boost is a project wide global dependency.
209 include_directories (${Boost_INCLUDE_DIRS})
210 link_directories (${Boost_LIBRARY_DIRS})
212 # Pretty print status
213 message (STATUS "-- Include Directories")
214 foreach (include_dir ${Boost_INCLUDE_DIRS})
215 message (STATUS " " ${include_dir})
217 message (STATUS "-- Library Directories")
218 foreach (library_dir ${Boost_LIBRARY_DIRS})
219 message (STATUS " " ${library_dir})
221 message (STATUS "-- Libraries")
222 foreach (boost_lib ${Boost_LIBRARIES})
223 message (STATUS " " ${boost_lib})
227 message (FATAL_ERROR "Failed to find required dependency: boost")
230 find_package(OpenSSL)
234 ############ Add projects
237 add_subdirectory (websocketpp)
241 include_subdirs ("examples")
246 include_subdirs ("test")
249 print_used_build_config()
251 export (PACKAGE websocketpp)
253 configure_file (websocketpp-config.cmake.in "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/websocketpp-config.cmake" @ONLY)
254 configure_file (websocketpp-configVersion.cmake.in "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/websocketpp-configVersion.cmake" @ONLY)
256 # Install the websocketpp-config.cmake and websocketpp-configVersion.cmake
258 "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/websocketpp-config.cmake"
259 "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/websocketpp-configVersion.cmake"
260 DESTINATION "${INSTALL_CMAKE_DIR}" COMPONENT dev)