From 3641521af7ed989fd4ceb55f302fede5c0c0c4b6 Mon Sep 17 00:00:00 2001 From: Sergey Lyubimov Date: Fri, 31 Mar 2017 08:54:12 +0300 Subject: [PATCH] Update CMake scripts for finding packages: These changes require CMake version 3.7.2 or later. --- CHANGELOG.md | 1 + CMakeLists.txt | 16 +++++++++------- README.md | 10 ++++++++-- examples/CMakeLists.txt | 13 +++++++++++++ test/CMakeLists.txt | 2 ++ test/core/CMakeLists.txt | 2 ++ test/http/CMakeLists.txt | 4 ++++ test/websocket/CMakeLists.txt | 2 ++ test/zlib/CMakeLists.txt | 2 ++ 9 files changed, 43 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 558e89d3..13fb489f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ 1.0.0-b32 * Add io_service completion invariants test +* Update CMake scripts for finding packages API Changes: diff --git a/CMakeLists.txt b/CMakeLists.txt index 066540b2..7ece8f30 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,12 +4,13 @@ cmake_minimum_required (VERSION 3.2) project (Beast) +option(Boost_USE_STATIC_LIBS "Use static libraries for boost" ON) + set_property (GLOBAL PROPERTY USE_FOLDERS ON) if (MSVC) # /wd4244 /wd4127 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4100 /wd4244 /wd4251 /MP /W4 /bigobj /D BOOST_COROUTINES_NO_DEPRECATION_WARNING=1 /D _WIN32_WINNT=0x0601 /D _SCL_SECURE_NO_WARNINGS=1 /D _CRT_SECURE_NO_WARNINGS=1") - set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd") set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Ob2 /Oi /Ot /GL /MT") set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /Oi /Ot /MT") @@ -19,17 +20,12 @@ if (MSVC) # for RelWithDebInfo builds, disable incremental linking # since CMake sets it ON by default for that build type and it # causes warnings + # string (REPLACE "/INCREMENTAL" "/INCREMENTAL:NO" replacement_flags ${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO}) set (CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO ${replacement_flags}) else() - set(Boost_USE_STATIC_LIBS ON) - set(Boost_USE_MULTITHREADED ON) - find_package(Boost REQUIRED COMPONENTS coroutine context thread filesystem program_options system) - include_directories(SYSTEM ${Boost_INCLUDE_DIRS}) - link_directories(${Boost_LIBRARY_DIR}) - set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads) @@ -37,6 +33,12 @@ else() "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra -Wpedantic -Wno-unused-parameter -DBOOST_COROUTINES_NO_DEPRECATION_WARNING=1") endif() +set(Boost_USE_MULTITHREADED ON) + +find_package(Boost REQUIRED COMPONENTS coroutine context thread filesystem program_options system) +include_directories(SYSTEM ${Boost_INCLUDE_DIRS}) +link_directories(${Boost_LIBRARY_DIR}) + add_definitions ("-DBOOST_COROUTINES_NO_DEPRECATION_WARNING") if (APPLE AND NOT DEFINED ENV{OPENSSL_ROOT_DIR}) diff --git a/README.md b/README.md index 6552fe18..8706010a 100644 --- a/README.md +++ b/README.md @@ -73,9 +73,15 @@ The library has been submitted to the ## Requirements -* Boost 1.58 or higher -* C++11 or greater +* Boost 1.58 or later +* C++11 or later + +These components are optionally required in order to build the +tests and examples: + * OpenSSL (optional) +* CMake 3.7.2 or later (optional) +* Properly configured bjam/b2 (optional) ## Building diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 6d9e8edb..edb8e333 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -15,6 +15,8 @@ add_executable (http-crawl if (NOT WIN32) target_link_libraries(http-crawl ${Boost_LIBRARIES} Threads::Threads) +else() + target_link_libraries(http-crawl ${Boost_LIBRARIES}) endif() add_executable (http-server @@ -29,8 +31,11 @@ add_executable (http-server if (NOT WIN32) target_link_libraries(http-server ${Boost_LIBRARIES} Threads::Threads) +else() + target_link_libraries(http-server ${Boost_LIBRARIES}) endif() + add_executable (http-example ${BEAST_INCLUDES} ${EXTRAS_INCLUDES} @@ -39,8 +44,11 @@ add_executable (http-example if (NOT WIN32) target_link_libraries(http-example ${Boost_LIBRARIES} Threads::Threads) +else() + target_link_libraries(http-example ${Boost_LIBRARIES}) endif() + add_executable (websocket-echo ${BEAST_INCLUDES} websocket_async_echo_server.hpp @@ -50,8 +58,11 @@ add_executable (websocket-echo if (NOT WIN32) target_link_libraries(websocket-echo ${Boost_LIBRARIES} Threads::Threads) +else() + target_link_libraries(websocket-echo ${Boost_LIBRARIES}) endif() + add_executable (websocket-example ${BEAST_INCLUDES} ${EXTRAS_INCLUDES} @@ -60,4 +71,6 @@ add_executable (websocket-example if (NOT WIN32) target_link_libraries(websocket-example ${Boost_LIBRARIES} Threads::Threads) +else() + target_link_libraries(websocket-example ${Boost_LIBRARIES}) endif() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 4a80f6ae..740e4c7a 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -16,6 +16,8 @@ add_executable (lib-tests ) if (NOT WIN32) + target_link_libraries(lib-tests ${Boost_LIBRARIES} Threads::Threads) +else() target_link_libraries(lib-tests ${Boost_LIBRARIES}) endif() diff --git a/test/core/CMakeLists.txt b/test/core/CMakeLists.txt index 2d575cd8..766627e3 100644 --- a/test/core/CMakeLists.txt +++ b/test/core/CMakeLists.txt @@ -39,4 +39,6 @@ add_executable (core-tests if (NOT WIN32) target_link_libraries(core-tests ${Boost_LIBRARIES} Threads::Threads) +else() + target_link_libraries(core-tests ${Boost_LIBRARIES}) endif() diff --git a/test/http/CMakeLists.txt b/test/http/CMakeLists.txt index 02e5db8b..5505e37d 100644 --- a/test/http/CMakeLists.txt +++ b/test/http/CMakeLists.txt @@ -32,6 +32,8 @@ add_executable (http-tests if (NOT WIN32) target_link_libraries(http-tests ${Boost_LIBRARIES} Threads::Threads) +else() + target_link_libraries(http-tests ${Boost_LIBRARIES}) endif() add_executable (bench-tests @@ -44,5 +46,7 @@ add_executable (bench-tests ) if (NOT WIN32) + target_link_libraries(bench-tests ${Boost_LIBRARIES} Threads::Threads) +else() target_link_libraries(bench-tests ${Boost_LIBRARIES}) endif() diff --git a/test/websocket/CMakeLists.txt b/test/websocket/CMakeLists.txt index 9a3260c7..5d2856ed 100644 --- a/test/websocket/CMakeLists.txt +++ b/test/websocket/CMakeLists.txt @@ -22,6 +22,8 @@ add_executable (websocket-tests if (NOT WIN32) target_link_libraries(websocket-tests ${Boost_LIBRARIES} Threads::Threads) +else() + target_link_libraries(websocket-tests ${Boost_LIBRARIES}) endif() if (MINGW) diff --git a/test/zlib/CMakeLists.txt b/test/zlib/CMakeLists.txt index b4fcfd93..4d955e26 100644 --- a/test/zlib/CMakeLists.txt +++ b/test/zlib/CMakeLists.txt @@ -21,4 +21,6 @@ add_executable (zlib-tests if (NOT WIN32) target_link_libraries(zlib-tests ${Boost_LIBRARIES} Threads::Threads) +else() + target_link_libraries(zlib-tests ${Boost_LIBRARIES}) endif()