1# 2# Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail dot com) 3# 4# Distributed under the Boost Software License, Version 1.0. (See accompanying 5# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6# 7# Official repository: https://github.com/boostorg/beast 8# 9 10cmake_minimum_required (VERSION 3.5.1) 11 12if (POLICY CMP0074) 13 cmake_policy (SET CMP0074 NEW) 14endif() 15 16#------------------------------------------------------------------------------- 17 18function (DoGroupSources curdir rootdir folder) 19 file (GLOB children RELATIVE ${PROJECT_SOURCE_DIR}/${curdir} ${PROJECT_SOURCE_DIR}/${curdir}/*) 20 foreach (child ${children}) 21 if (IS_DIRECTORY ${PROJECT_SOURCE_DIR}/${curdir}/${child}) 22 DoGroupSources (${curdir}/${child} ${rootdir} ${folder}) 23 elseif (${child} STREQUAL "CMakeLists.txt") 24 source_group("" FILES ${PROJECT_SOURCE_DIR}/${curdir}/${child}) 25 else() 26 string (REGEX REPLACE ^${rootdir} ${folder} groupname ${curdir}) 27 string (REPLACE "/" "\\" groupname ${groupname}) 28 source_group (${groupname} FILES ${PROJECT_SOURCE_DIR}/${curdir}/${child}) 29 endif() 30 endforeach() 31endfunction() 32 33function (GroupSources curdir folder) 34 DoGroupSources (${curdir} ${curdir} ${folder}) 35endfunction() 36 37#------------------------------------------------------------------------------- 38# 39# Beast 40# 41#------------------------------------------------------------------------------- 42 43project (Beast VERSION 313) 44 45set_property (GLOBAL PROPERTY USE_FOLDERS ON) 46option (Beast_BUILD_EXAMPLES "Build examples" ON) 47option (Beast_BUILD_TESTS "Build tests" ON) 48option (Beast_ENABLE_HANDLER_TRACKING "Define BOOST_ASIO_ENABLE_HANDLER_TRACKING when building libraries" OFF) 49option (Boost_USE_STATIC_LIBS "Use Static Boost libraries" ON) 50 51if (MSVC) 52 set (CMAKE_VERBOSE_MAKEFILE FALSE) 53 54 add_definitions ( 55 -D_WIN32_WINNT=0x0601 56 -D_SCL_SECURE_NO_WARNINGS=1 57 -D_CRT_SECURE_NO_WARNINGS=1 58 -D_SILENCE_CXX17_ALLOCATOR_VOID_DEPRECATION_WARNING 59 -D_SILENCE_CXX17_ADAPTOR_TYPEDEFS_DEPRECATION_WARNING 60 ) 61 62 add_compile_options( 63 /bigobj # large object file format 64 /permissive- # strict C++ 65 #/wd4503 # decorated name length exceeded, name was truncated 66 /W4 # enable all warnings 67 /MP # Multi-processor compilation 68 ) 69 70 set (Boost_USE_STATIC_RUNTIME ON) 71 72 set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd") 73 set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Ob2 /Oi /Ot /GL /MT") 74 set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /Oi /Ot /MT") 75 76 set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO") 77 set (CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /LTCG") 78 79 # for RelWithDebInfo builds, disable incremental linking 80 # since CMake sets it ON by default for that build type and it 81 # causes warnings 82 # 83 string (REPLACE "/INCREMENTAL" "/INCREMENTAL:NO" replacement_flags 84 ${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO}) 85 set (CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO ${replacement_flags}) 86 87else() 88 set (THREADS_PREFER_PTHREAD_FLAG ON) 89 find_package (Threads) 90 link_libraries(Threads::Threads) 91 92 93 set( CMAKE_CXX_FLAGS 94 "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra -Wpedantic -Wno-unused-parameter") 95 96 if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") 97 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wrange-loop-analysis") 98 endif () 99endif() 100 101# Must come before Boost includes, otherwise the 102# IDE sees the wrong file due to boost/ symlinks. 103include_directories (include) 104 105#------------------------------------------------------------------------------- 106# 107# OpenSSL 108# 109#------------------------------------------------------------------------------- 110 111if (APPLE AND NOT DEFINED ENV{OPENSSL_ROOT_DIR}) 112 find_program(HOMEBREW brew) 113 if (NOT HOMEBREW STREQUAL "HOMEBREW-NOTFOUND") 114 execute_process(COMMAND brew --prefix openssl 115 OUTPUT_VARIABLE OPENSSL_ROOT_DIR 116 OUTPUT_STRIP_TRAILING_WHITESPACE) 117 endif() 118endif() 119 120find_package(OpenSSL) 121if (NOT MSVC) 122 link_libraries(${OPENSSL_LIBRARIES}) 123endif() 124 125#------------------------------------------------------------------------------- 126# 127# Boost 128# 129#------------------------------------------------------------------------------- 130 131get_filename_component (BOOST_ROOT ../../ ABSOLUTE) 132 133# VFALCO I want static but "b2 stage" builds a minimal set which excludes static 134add_definitions (-DBOOST_ALL_STATIC_LINK=1) 135 136add_definitions (-DBOOST_ASIO_NO_DEPRECATED=1) 137add_definitions (-DBOOST_ASIO_DISABLE_BOOST_ARRAY=1) 138add_definitions (-DBOOST_ASIO_DISABLE_BOOST_BIND=1) 139add_definitions (-DBOOST_ASIO_DISABLE_BOOST_DATE_TIME=1) 140add_definitions (-DBOOST_ASIO_DISABLE_BOOST_REGEX=1) 141add_definitions (-DBOOST_COROUTINES_NO_DEPRECATION_WARNING=1) 142 143if (MSVC) 144 include_directories (${BOOST_ROOT}) 145 link_libraries( bcrypt.lib ) 146else() 147 set(BOOST_INCLUDEDIR ${BOOST_ROOT}) 148 set(BOOST_LIBRARYDIR ${BOOST_ROOT}/stage/lib) 149 find_package(Boost COMPONENTS coroutine filesystem system thread REQUIRED) 150 link_libraries(Boost::coroutine Boost::filesystem Boost::system Boost::thread) 151endif() 152 153link_directories(${BOOST_ROOT}/stage/lib) 154 155if (MINGW) 156 link_libraries(ws2_32 mswsock) 157endif() 158 159#------------------------------------------------------------------------------- 160 161if ("${VARIANT}" STREQUAL "coverage") 162 if (MSVC) 163 else() 164 set (CMAKE_BUILD_TYPE DEBUG) 165 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.2 --coverage") 166 set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage") 167 endif() 168 169elseif ("${VARIANT}" STREQUAL "ubasan") 170 if (MSVC) 171 else() 172 set (CMAKE_BUILD_TYPE RELWITHDEBINFO) 173 set (CMAKE_CXX_FLAGS 174 "${CMAKE_CXX_FLAGS} -DBOOST_BEAST_NO_SLOW_TESTS=1 -msse4.2 -funsigned-char -fno-omit-frame-pointer -fsanitize=address,undefined -fno-sanitize-recover=address,undefined -fsanitize-blacklist=${PROJECT_SOURCE_DIR}/tools/blacklist.supp") 175 set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address,undefined -fno-sanitize-recover=address,undefined") 176 endif() 177 178elseif ("${VARIANT}" STREQUAL "debug") 179 set (CMAKE_BUILD_TYPE DEBUG) 180 181elseif ("${VARIANT}" STREQUAL "release") 182 set (CMAKE_BUILD_TYPE RELEASE) 183 184endif() 185 186#------------------------------------------------------------------------------- 187# 188# Static Libraries 189# 190#------------------------------------------------------------------------------- 191 192add_definitions (-DBOOST_ASIO_SEPARATE_COMPILATION=1) 193add_definitions (-DBOOST_BEAST_SEPARATE_COMPILATION=1) 194 195GroupSources (test "/") 196 197add_library ( 198 lib-asio STATIC 199 test/lib_asio.cpp 200) 201if(Beast_ENABLE_HANDLER_TRACKING) 202 target_compile_definitions(lib-asio 203 PUBLIC BOOST_ASIO_ENABLE_HANDLER_TRACKING=1) 204endif() 205 206set_property(TARGET lib-asio PROPERTY FOLDER "static-libs") 207 208add_library ( 209 lib-asio-ssl STATIC 210 test/lib_asio_ssl.cpp 211) 212 213set_property(TARGET lib-asio-ssl PROPERTY FOLDER "static-libs") 214 215add_library ( 216 lib-beast STATIC 217 test/lib_beast.cpp 218) 219 220set_property(TARGET lib-beast PROPERTY FOLDER "static-libs") 221 222target_link_libraries(lib-beast lib-asio) 223 224#------------------------------------------------------------------------------- 225# 226# Tests and examples 227# 228 229include_directories (.) 230 231if (OPENSSL_FOUND) 232 include_directories (${OPENSSL_INCLUDE_DIR}) 233endif() 234 235file (GLOB_RECURSE BOOST_BEAST_FILES 236 ${PROJECT_SOURCE_DIR}/include/boost/beast/*.hpp 237 ${PROJECT_SOURCE_DIR}/include/boost/beast/*.ipp 238) 239 240file (GLOB_RECURSE BOOST_BEAST_EXPERIMENTAL_FILES 241 ${PROJECT_SOURCE_DIR}/include/boost/beast/_experimental/*.hpp 242 ${PROJECT_SOURCE_DIR}/include/boost/beast/_experimental/*.ipp 243) 244 245file (GLOB_RECURSE COMMON_FILES 246 ${PROJECT_SOURCE_DIR}/example/common/*.hpp 247 ) 248 249if (Beast_BUILD_EXAMPLES AND 250 (NOT "${VARIANT}" STREQUAL "coverage") AND 251 (NOT "${VARIANT}" STREQUAL "ubasan")) 252 add_subdirectory (example) 253endif() 254 255if (Beast_BUILD_TESTS) 256 add_subdirectory (test) 257endif() 258