1 if(NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
3 # Generated by `boostdep --cmake beast`
4 # Copyright 2020, 2021 Peter Dimov
5 # Distributed under the Boost Software License, Version 1.0.
6 # https://www.boost.org/LICENSE_1_0.txt
8 cmake_minimum_required(VERSION 3.8...3.20)
10 project(boost_beast VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX)
12 add_library(boost_beast INTERFACE)
13 add_library(Boost::beast ALIAS boost_beast)
15 target_include_directories(boost_beast INTERFACE include)
17 target_link_libraries(boost_beast
33 Boost::throw_exception
39 target_compile_features(boost_beast INTERFACE cxx_std_11)
44 # Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
46 # Distributed under the Boost Software License, Version 1.0. (See accompanying
47 # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
49 # Official repository: https://github.com/boostorg/beast
52 cmake_minimum_required (VERSION 3.5.1)
55 cmake_policy (SET CMP0074 NEW)
58 #-------------------------------------------------------------------------------
60 function (DoGroupSources curdir rootdir folder)
61 file (GLOB children RELATIVE ${PROJECT_SOURCE_DIR}/${curdir} ${PROJECT_SOURCE_DIR}/${curdir}/*)
62 foreach (child ${children})
63 if (IS_DIRECTORY ${PROJECT_SOURCE_DIR}/${curdir}/${child})
64 DoGroupSources (${curdir}/${child} ${rootdir} ${folder})
65 elseif (${child} STREQUAL "CMakeLists.txt")
66 source_group("" FILES ${PROJECT_SOURCE_DIR}/${curdir}/${child})
68 string (REGEX REPLACE ^${rootdir} ${folder} groupname ${curdir})
69 string (REPLACE "/" "\\" groupname ${groupname})
70 source_group (${groupname} FILES ${PROJECT_SOURCE_DIR}/${curdir}/${child})
75 function (GroupSources curdir folder)
76 DoGroupSources (${curdir} ${curdir} ${folder})
79 #-------------------------------------------------------------------------------
83 #-------------------------------------------------------------------------------
85 project (Beast VERSION 330)
87 set_property (GLOBAL PROPERTY USE_FOLDERS ON)
88 option (Beast_BUILD_EXAMPLES "Build examples" ON)
89 option (Beast_BUILD_TESTS "Build tests" ON)
90 option (Beast_ENABLE_HANDLER_TRACKING "Define BOOST_ASIO_ENABLE_HANDLER_TRACKING when building libraries" OFF)
91 option (Boost_USE_STATIC_LIBS "Use Static Boost libraries" ON)
94 set (CMAKE_VERBOSE_MAKEFILE FALSE)
98 -D_SCL_SECURE_NO_WARNINGS=1
99 -D_CRT_SECURE_NO_WARNINGS=1
100 -D_SILENCE_CXX17_ALLOCATOR_VOID_DEPRECATION_WARNING
101 -D_SILENCE_CXX17_ADAPTOR_TYPEDEFS_DEPRECATION_WARNING
105 /bigobj # large object file format
106 /permissive- # strict C++
107 #/wd4503 # decorated name length exceeded, name was truncated
108 /W4 # enable all warnings
109 /MP # Multi-processor compilation
112 set (Boost_USE_STATIC_RUNTIME ON)
114 set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
115 set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Ob2 /Oi /Ot /GL /MT")
116 set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /Oi /Ot /MT")
118 set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO")
119 set (CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /LTCG")
121 # for RelWithDebInfo builds, disable incremental linking
122 # since CMake sets it ON by default for that build type and it
125 string (REPLACE "/INCREMENTAL" "/INCREMENTAL:NO" replacement_flags
126 ${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO})
127 set (CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO ${replacement_flags})
130 set (THREADS_PREFER_PTHREAD_FLAG ON)
131 find_package (Threads)
132 link_libraries(Threads::Threads)
136 "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra -Wpedantic -Wno-unused-parameter")
138 if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
139 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wrange-loop-analysis")
143 # Must come before Boost includes, otherwise the
144 # IDE sees the wrong file due to boost/ symlinks.
145 include_directories (include)
147 #-------------------------------------------------------------------------------
151 #-------------------------------------------------------------------------------
153 if (APPLE AND NOT DEFINED ENV{OPENSSL_ROOT_DIR})
154 find_program(HOMEBREW brew)
155 if (NOT HOMEBREW STREQUAL "HOMEBREW-NOTFOUND")
156 execute_process(COMMAND brew --prefix openssl
157 OUTPUT_VARIABLE OPENSSL_ROOT_DIR
158 OUTPUT_STRIP_TRAILING_WHITESPACE)
162 find_package(OpenSSL)
164 link_libraries(${OPENSSL_LIBRARIES})
167 #-------------------------------------------------------------------------------
171 #-------------------------------------------------------------------------------
173 get_filename_component (BOOST_ROOT ../../ ABSOLUTE)
175 # VFALCO I want static but "b2 stage" builds a minimal set which excludes static
176 add_definitions (-DBOOST_ALL_STATIC_LINK=1)
178 add_definitions (-DBOOST_ASIO_NO_DEPRECATED=1)
179 add_definitions (-DBOOST_ASIO_DISABLE_BOOST_ARRAY=1)
180 add_definitions (-DBOOST_ASIO_DISABLE_BOOST_BIND=1)
181 add_definitions (-DBOOST_ASIO_DISABLE_BOOST_DATE_TIME=1)
182 add_definitions (-DBOOST_ASIO_DISABLE_BOOST_REGEX=1)
183 add_definitions (-DBOOST_COROUTINES_NO_DEPRECATION_WARNING=1)
186 include_directories (${BOOST_ROOT})
187 link_libraries( bcrypt.lib )
189 set(BOOST_INCLUDEDIR ${BOOST_ROOT})
190 set(BOOST_LIBRARYDIR ${BOOST_ROOT}/stage/lib)
191 find_package(Boost COMPONENTS coroutine filesystem system thread REQUIRED)
192 link_libraries(Boost::coroutine Boost::filesystem Boost::system Boost::thread)
195 link_directories(${BOOST_ROOT}/stage/lib)
198 link_libraries(ws2_32 mswsock)
201 #-------------------------------------------------------------------------------
203 if ("${VARIANT}" STREQUAL "coverage")
206 set (CMAKE_BUILD_TYPE DEBUG)
207 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.2 --coverage")
208 set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
211 elseif ("${VARIANT}" STREQUAL "ubasan")
214 set (CMAKE_BUILD_TYPE RELWITHDEBINFO)
216 "${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")
217 set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address,undefined -fno-sanitize-recover=address,undefined")
220 elseif ("${VARIANT}" STREQUAL "debug")
221 set (CMAKE_BUILD_TYPE DEBUG)
223 elseif ("${VARIANT}" STREQUAL "release")
224 set (CMAKE_BUILD_TYPE RELEASE)
228 #-------------------------------------------------------------------------------
232 #-------------------------------------------------------------------------------
234 add_definitions (-DBOOST_ASIO_SEPARATE_COMPILATION=1)
235 add_definitions (-DBOOST_BEAST_SEPARATE_COMPILATION=1)
237 GroupSources (test "/")
243 if(Beast_ENABLE_HANDLER_TRACKING)
244 target_compile_definitions(lib-asio
245 PUBLIC BOOST_ASIO_ENABLE_HANDLER_TRACKING=1)
248 set_property(TARGET lib-asio PROPERTY FOLDER "static-libs")
252 test/lib_asio_ssl.cpp
255 set_property(TARGET lib-asio-ssl PROPERTY FOLDER "static-libs")
262 set_property(TARGET lib-beast PROPERTY FOLDER "static-libs")
264 target_link_libraries(lib-beast lib-asio)
266 #-------------------------------------------------------------------------------
271 include_directories (.)
274 include_directories (${OPENSSL_INCLUDE_DIR})
277 file (GLOB_RECURSE BOOST_BEAST_FILES
278 ${PROJECT_SOURCE_DIR}/include/boost/beast/*.hpp
279 ${PROJECT_SOURCE_DIR}/include/boost/beast/*.ipp
282 file (GLOB_RECURSE BOOST_BEAST_EXPERIMENTAL_FILES
283 ${PROJECT_SOURCE_DIR}/include/boost/beast/_experimental/*.hpp
284 ${PROJECT_SOURCE_DIR}/include/boost/beast/_experimental/*.ipp
287 file (GLOB_RECURSE COMMON_FILES
288 ${PROJECT_SOURCE_DIR}/example/common/*.hpp
291 if (Beast_BUILD_EXAMPLES AND
292 (NOT "${VARIANT}" STREQUAL "coverage") AND
293 (NOT "${VARIANT}" STREQUAL "ubasan"))
294 add_subdirectory (example)
297 if (Beast_BUILD_TESTS)
298 add_subdirectory (test)