|
| 1 | + |
| 2 | +############ Setup project and cmake |
| 3 | + |
| 4 | +# Project name |
| 5 | +project (websocketpp) |
| 6 | + |
| 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) |
| 10 | + |
| 11 | +set (WEBSOCKETPP_MAJOR_VERSION 0) |
| 12 | +set (WEBSOCKETPP_MINOR_VERSION 3) |
| 13 | +set (WEBSOCKETPP_PATCH_VERSION 0) |
| 14 | +set (WEBSOCKETPP_VERSION ${WEBSOCKETPP_MAJOR_VERSION}.${WEBSOCKETPP_MINOR_VERSION}.${WEBSOCKETPP_PATCH_VERSION}) |
| 15 | + |
| 16 | +set(INSTALL_INCLUDE_DIR include CACHE PATH "Installation directory for header files") |
| 17 | +if (WIN32 AND NOT CYGWIN) |
| 18 | + set (DEF_INSTALL_CMAKE_DIR cmake) |
| 19 | +else () |
| 20 | + set (DEF_INSTALL_CMAKE_DIR lib/cmake/websocketpp) |
| 21 | +endif () |
| 22 | +set (INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH "Installation directory for CMake files") |
| 23 | + |
| 24 | +# Make relative paths absolute (needed later on) |
| 25 | +foreach (p INCLUDE CMAKE) |
| 26 | + set (var INSTALL_${p}_DIR) |
| 27 | + if (NOT IS_ABSOLUTE "${${var}}") |
| 28 | + set (${var} "${CMAKE_INSTALL_PREFIX}/${${var}}") |
| 29 | + endif () |
| 30 | +endforeach () |
| 31 | + |
| 32 | +# Set CMake library search policy |
| 33 | +if (COMMAND cmake_policy) |
| 34 | + cmake_policy (SET CMP0003 NEW) |
| 35 | + cmake_policy (SET CMP0005 NEW) |
| 36 | +endif () |
| 37 | + |
| 38 | +# Disable unnecessary build types |
| 39 | +set (CMAKE_CONFIGURATION_TYPES "Release;RelWithDebInfo;Debug" CACHE STRING "Configurations" FORCE) |
| 40 | + |
| 41 | +# Include our cmake macros |
| 42 | +set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) |
| 43 | +include (CMakeHelpers) |
| 44 | + |
| 45 | +############ Paths |
| 46 | + |
| 47 | +set (WEBSOCKETPP_ROOT ${CMAKE_CURRENT_SOURCE_DIR}) |
| 48 | +set (WEBSOCKETPP_INCLUDE ${WEBSOCKETPP_ROOT}/websocketpp) |
| 49 | +set (WEBSOCKETPP_BUILD_ROOT ${CMAKE_CURRENT_BINARY_DIR}) |
| 50 | +set (WEBSOCKETPP_BIN ${WEBSOCKETPP_BUILD_ROOT}/bin) |
| 51 | +set (WEBSOCKETPP_LIB ${WEBSOCKETPP_BUILD_ROOT}/lib) |
| 52 | + |
| 53 | +# CMake install step prefix. I assume linux users want the prefix to |
| 54 | +# be the default /usr or /usr/local so this is only adjusted on Windows. |
| 55 | +# - Windows: Build the INSTALL project in your solution file. |
| 56 | +# - Linux/OSX: make install. |
| 57 | +if (MSVC) |
| 58 | + set (CMAKE_INSTALL_PREFIX "${WEBSOCKETPP_ROOT}/install") |
| 59 | +endif () |
| 60 | + |
| 61 | +############ Build customization |
| 62 | + |
| 63 | +# Override from command line "CMake -D<OPTION>=TRUE/FALSE/0/1/ON/OFF" |
| 64 | +option (ENABLE_CPP11 "Build websocketpp with CPP11 features enabled." TRUE) |
| 65 | +option (BUILD_EXAMPLES "Build websocketpp examples." FALSE) |
| 66 | +option (BUILD_TESTS "Build websocketpp tests." FALSE) |
| 67 | + |
| 68 | +if (BUILD_TESTS OR BUILD_EXAMPLES) |
| 69 | + |
| 70 | + ############ Compiler specific setup |
| 71 | + |
| 72 | + set (WEBSOCKETPP_PLATFORM_LIBS "") |
| 73 | + set (WEBSOCKETPP_PLATFORM_TSL_LIBS "") |
| 74 | + set (WEBSOCKETPP_BOOST_LIBS "") |
| 75 | + |
| 76 | + # VC9 and C++11 reasoning |
| 77 | + if (ENABLE_CPP11 AND MSVC AND MSVC90) |
| 78 | + message("* Detected Visual Studio 9 2008, disabling C++11 support.") |
| 79 | + set (ENABLE_CPP11 FALSE) |
| 80 | + endif () |
| 81 | + |
| 82 | + # Detect clang. Not officially reported by cmake. |
| 83 | + execute_process(COMMAND "${CMAKE_CXX_COMPILER}" "-v" ERROR_VARIABLE CXX_VER_STDERR) |
| 84 | + if ("${CXX_VER_STDERR}" MATCHES ".*clang.*") |
| 85 | + set (CMAKE_COMPILER_IS_CLANGXX 1) |
| 86 | + endif () |
| 87 | + |
| 88 | + # C++11 defines |
| 89 | + if (ENABLE_CPP11) |
| 90 | + add_definitions (-D_WEBSOCKETPP_CPP11_STL_) |
| 91 | + endif () |
| 92 | + |
| 93 | + # Visual studio |
| 94 | + if (MSVC) |
| 95 | + set (WEBSOCKETPP_BOOST_LIBS system thread) |
| 96 | + set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /GL /Gy /GF /Ox /Ob2 /Ot /Oi /MP /arch:SSE2 /fp:fast") |
| 97 | + set (CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /LTCG /INCREMENTAL:NO /OPT:REF /OPT:ICF") |
| 98 | + add_definitions (/W3 /wd4996 /wd4995 /wd4355) |
| 99 | + add_definitions (-DUNICODE -D_UNICODE) |
| 100 | + add_definitions (-D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS) |
| 101 | + add_definitions (-DNOMINMAX) |
| 102 | + endif () |
| 103 | + |
| 104 | + # g++ |
| 105 | + if (CMAKE_COMPILER_IS_GNUCXX) |
| 106 | + set (WEBSOCKETPP_PLATFORM_LIBS pthread rt) |
| 107 | + set (WEBSOCKETPP_PLATFORM_TSL_LIBS ssl crypto) |
| 108 | + set (WEBSOCKETPP_BOOST_LIBS system thread) |
| 109 | + set (CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-std=c++0x") |
| 110 | + if (NOT APPLE) |
| 111 | + add_definitions (-DNDEBUG -Wall -Wcast-align) # todo: should we use CMAKE_C_FLAGS for these? |
| 112 | + endif () |
| 113 | + |
| 114 | + # Try to detect version. Note: Not tested! |
| 115 | + execute_process (COMMAND ${CMAKE_CXX_COMPILER} "-dumpversion" OUTPUT_VARIABLE GCC_VERSION) |
| 116 | + if ("${GCC_VERSION}" STRGREATER "4.4.0") |
| 117 | + message("* C++11 support partially enabled due to GCC version ${GCC_VERSION}") |
| 118 | + set (WEBSOCKETPP_BOOST_LIBS system thread) |
| 119 | + endif () |
| 120 | + endif () |
| 121 | + |
| 122 | + # clang |
| 123 | + if (CMAKE_COMPILER_IS_CLANGXX) |
| 124 | + if (NOT APPLE) |
| 125 | + set (WEBSOCKETPP_PLATFORM_LIBS pthread rt) |
| 126 | + else() |
| 127 | + set (WEBSOCKETPP_PLATFORM_LIBS pthread) |
| 128 | + endif() |
| 129 | + set (WEBSOCKETPP_PLATFORM_TSL_LIBS ssl crypto) |
| 130 | + set (WEBSOCKETPP_BOOST_LIBS system thread) |
| 131 | + set (CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-std=c++0x -stdlib=libc++") # todo: is libc++ really needed here? |
| 132 | + if (NOT APPLE) |
| 133 | + add_definitions (-DNDEBUG -Wall -Wno-padded) # todo: should we use CMAKE_C_FLAGS for these? |
| 134 | + endif () |
| 135 | + endif () |
| 136 | + |
| 137 | + # OSX, can override above. |
| 138 | + if (APPLE) |
| 139 | + add_definitions (-DNDEBUG -Wall) |
| 140 | + endif () |
| 141 | + |
| 142 | + if (BUILD_EXAMPLES) |
| 143 | + list (APPEND WEBSOCKETPP_BOOST_LIBS random) |
| 144 | + endif() |
| 145 | + |
| 146 | + ############ Dependencies |
| 147 | + |
| 148 | + # Set BOOST_ROOT env variable or pass with cmake -DBOOST_ROOT=path. |
| 149 | + # BOOST_ROOT can also be defined by a previous run from cmake cache. |
| 150 | + if (NOT "$ENV{BOOST_ROOT_CPP11}" STREQUAL "") |
| 151 | + # Scons documentation for BOOST_ROOT_CPP11: |
| 152 | + # "look for optional second boostroot compiled with clang's libc++ STL library |
| 153 | + # this prevents warnings/errors when linking code built with two different |
| 154 | + # incompatible STL libraries." |
| 155 | + file (TO_CMAKE_PATH "$ENV{BOOST_ROOT_CPP11}" BOOST_ROOT) |
| 156 | + set (BOOST_ROOT ${BOOST_ROOT} CACHE PATH "BOOST_ROOT dependency path" FORCE) |
| 157 | + endif () |
| 158 | + if ("${BOOST_ROOT}" STREQUAL "") |
| 159 | + file (TO_CMAKE_PATH "$ENV{BOOST_ROOT}" BOOST_ROOT) |
| 160 | + # Cache BOOST_ROOT for runs that do not define $ENV{BOOST_ROOT}. |
| 161 | + set (BOOST_ROOT ${BOOST_ROOT} CACHE PATH "BOOST_ROOT dependency path" FORCE) |
| 162 | + endif () |
| 163 | + |
| 164 | + message ("* Configuring Boost") |
| 165 | + message (STATUS "-- Using BOOST_ROOT") |
| 166 | + message (STATUS " " ${BOOST_ROOT}) |
| 167 | + |
| 168 | + if (MSVC) |
| 169 | + set (Boost_USE_MULTITHREADED TRUE) |
| 170 | + set (Boost_USE_STATIC_LIBS TRUE) |
| 171 | + else () |
| 172 | + set (Boost_USE_MULTITHREADED FALSE) |
| 173 | + set (Boost_USE_STATIC_LIBS FALSE) |
| 174 | + endif () |
| 175 | + |
| 176 | + set (Boost_FIND_REQUIRED TRUE) |
| 177 | + set (Boost_FIND_QUIETLY TRUE) |
| 178 | + set (Boost_DEBUG FALSE) |
| 179 | + set (Boost_USE_MULTITHREADED TRUE) |
| 180 | + 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! |
| 181 | + |
| 182 | + find_package (Boost 1.39.0 COMPONENTS "${WEBSOCKETPP_BOOST_LIBS}") |
| 183 | + |
| 184 | + if (Boost_FOUND) |
| 185 | + # Boost is a project wide global dependency. |
| 186 | + include_directories (${Boost_INCLUDE_DIRS}) |
| 187 | + link_directories (${Boost_LIBRARY_DIRS}) |
| 188 | + |
| 189 | + # Pretty print status |
| 190 | + message (STATUS "-- Include Directories") |
| 191 | + foreach (include_dir ${Boost_INCLUDE_DIRS}) |
| 192 | + message (STATUS " " ${include_dir}) |
| 193 | + endforeach () |
| 194 | + message (STATUS "-- Library Directories") |
| 195 | + foreach (library_dir ${Boost_LIBRARY_DIRS}) |
| 196 | + message (STATUS " " ${library_dir}) |
| 197 | + endforeach () |
| 198 | + message (STATUS "-- Libraries") |
| 199 | + foreach (boost_lib ${Boost_LIBRARIES}) |
| 200 | + message (STATUS " " ${boost_lib}) |
| 201 | + endforeach () |
| 202 | + message ("") |
| 203 | + else () |
| 204 | + message (FATAL_ERROR "Failed to find required dependency: boost") |
| 205 | + endif () |
| 206 | + |
| 207 | + find_package(OpenSSL) |
| 208 | +endif() |
| 209 | + |
| 210 | +############ Add projects |
| 211 | + |
| 212 | +# Add main library |
| 213 | +add_subdirectory (websocketpp) |
| 214 | + |
| 215 | +# Add examples |
| 216 | +if (BUILD_EXAMPLES) |
| 217 | + add_subdirectory (examples) |
| 218 | +endif () |
| 219 | + |
| 220 | +# Add tests |
| 221 | +if (BUILD_TESTS) |
| 222 | + add_subdirectory (test) |
| 223 | +endif () |
| 224 | + |
| 225 | +print_used_build_config() |
| 226 | + |
| 227 | +export (PACKAGE websocketpp) |
| 228 | + |
| 229 | +configure_file (websocketpp-config.cmake.in "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/websocketpp-config.cmake" @ONLY) |
| 230 | +configure_file (websocketpp-configVersion.cmake.in "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/websocketpp-configVersion.cmake" @ONLY) |
| 231 | + |
| 232 | +# Install the websocketpp-config.cmake and websocketpp-configVersion.cmake |
| 233 | +install (FILES |
| 234 | + "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/websocketpp-config.cmake" |
| 235 | + "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/websocketpp-configVersion.cmake" |
| 236 | + DESTINATION "${INSTALL_CMAKE_DIR}" COMPONENT dev) |
| 237 | + |
0 commit comments