From 1dec0591045899e3fcf256ccb4c5ac50e1a71291 Mon Sep 17 00:00:00 2001 From: Dennis Klein Date: Wed, 31 Jul 2019 18:38:05 +0200 Subject: [PATCH] SDK: Require C++14, CMake 3.11 and bundle asio 1.13.0 Decouple from Boost distro to be able to use newest releases and rely on std::error_code only. --- .clang-tidy | 2 +- .gitmodules | 3 +++ CMakeLists.txt | 52 ++++++++++++++++++++++++++---------- COPYRIGHT | 29 ++++++++++++++++++++ README.md | 6 +++-- cmake/FairMQConfig.cmake.in | 2 ++ cmake/FairMQLib.cmake | 53 ++++++++++++++++++++++++++++++------- cmake/Findasio.cmake | 8 ++++++ extern/asio | 1 + extern/bundled_asio.cmake | 17 ++++++++++++ fairmq/sdk/CMakeLists.txt | 8 +++--- 11 files changed, 152 insertions(+), 29 deletions(-) create mode 160000 extern/asio create mode 100644 extern/bundled_asio.cmake diff --git a/.clang-tidy b/.clang-tidy index a4aa8fc2..be9bc944 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,3 +1,3 @@ --- Checks: '*,-google-*,-fuchsia-*,-cert-*,-llvm-header-guard,-readability-named-parameter,-misc-non-private-member-variables-in-classes,-*-magic-numbers,-llvm-include-order,-hicpp-no-array-decay,-performance-unnecessary-value-param,-cppcoreguidelines-pro-bounds-array-to-pointer-decay' -HeaderFilterRegex: '/(fairmq/|FairMQ)' +HeaderFilterRegex: '/(fairmq/)' diff --git a/.gitmodules b/.gitmodules index b03d1ba0..4ee89fc4 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "extern/googletest"] path = extern/googletest url = https://github.com/google/googletest +[submodule "extern/asio"] + path = extern/asio + url = https://github.com/chriskohlhoff/asio diff --git a/CMakeLists.txt b/CMakeLists.txt index 1064e1c8..329c5584 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,8 +6,8 @@ # copied verbatim in the file "LICENSE" # ################################################################################ -cmake_minimum_required(VERSION 3.10 FATAL_ERROR) -cmake_policy(VERSION 3.10...3.14) +cmake_minimum_required(VERSION 3.11 FATAL_ERROR) +cmake_policy(VERSION 3.11...3.15) # Project ###################################################################### set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) @@ -18,7 +18,7 @@ get_git_version() project(FairMQ VERSION ${PROJECT_VERSION} LANGUAGES CXX) message(STATUS "${BWhite}${PROJECT_NAME}${CR} ${PROJECT_GIT_VERSION} from ${PROJECT_DATE}") -if(BUILD_OFI_TRANSPORT) +if(BUILD_OFI_TRANSPORT OR BUILD_SDK) set(PROJECT_MIN_CXX_STANDARD 14) else() set(PROJECT_MIN_CXX_STANDARD 11) @@ -79,6 +79,7 @@ if(BUILD_SDK) else() set(required_dds_version 2.4) endif() + if(BUILD_DDS_PLUGIN OR BUILD_SDK) find_package2(PRIVATE DDS REQUIRED VERSION ${required_dds_version} @@ -126,6 +127,21 @@ if(BUILD_FAIRMQ OR BUILD_SDK) DDS FairLogger ) + + # Normalize Boost version + if(CMAKE_VERSION VERSION_LESS 3.15) + set(Boost_VERSION "${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION}") + endif() +endif() + +if(BUILD_SDK) + find_package2(BUNDLED asio + VERSION 1.13.0 + ) + if(NOT asio_FOUND) + build_bundled(asio extern/asio) + find_package2(PRIVATE asio REQUIRED) + endif() endif() if(BUILD_FAIRMQ) @@ -219,6 +235,22 @@ if(BUILD_DOCS) DESTINATION ${PROJECT_INSTALL_DATADIR}/docs ) endif() +if(BUILD_SDK) + install(FILES cmake/Findasio.cmake + DESTINATION ${PROJECT_INSTALL_CMAKEMODDIR} + ) + if(asio_BUNDLED) + install(TARGETS bundled_asio_headers EXPORT ${PROJECT_EXPORT_SET}) + install(DIRECTORY "${asio_BUILD_INCLUDE_DIR}/asio" + DESTINATION ${asio_INSTALL_INCLUDE_DIR} + PATTERN "Makefile.am" EXCLUDE + PATTERN ".gitignore" EXCLUDE + ) + install(FILES "${asio_BUILD_INCLUDE_DIR}/asio.hpp" + DESTINATION ${asio_INSTALL_INCLUDE_DIR} + ) + endif() +endif() install_cmake_package() ################################################################################ @@ -255,15 +287,7 @@ if(PROJECT_PACKAGE_DEPENDENCIES) message(STATUS " ${Cyan}DEPENDENCY FOUND VERSION PREFIX${CR}") foreach(dep IN LISTS PROJECT_PACKAGE_DEPENDENCIES) if(${dep}_VERSION) - if(${dep} STREQUAL Boost) - if(Boost_VERSION_MAJOR) - set(version_str "${BGreen}${${dep}_VERSION_MAJOR}.${${dep}_VERSION_MINOR}${CR}") - else() - set(version_str "${BGreen}${${dep}_MAJOR_VERSION}.${${dep}_MINOR_VERSION}${CR}") - endif() - else() - set(version_str "${BGreen}${${dep}_VERSION}${CR}") - endif() + set(version_str "${BGreen}${${dep}_VERSION}${CR}") else() set(version_str "${BYellow}unknown${CR}") endif() @@ -372,9 +396,9 @@ else() endif() message(STATUS " ${BWhite}docs${CR} ${docs_summary}") if(BUILD_SDK) - set(sdk_summary "${BGreen}YES${CR} EXPERIMENTAL (disable with ${BMagenta}-DBUILD_SDK=OFF${CR})") + set(sdk_summary "${BGreen}YES${CR} EXPERIMENTAL (required C++14) (disable with ${BMagenta}-DBUILD_SDK=OFF${CR})") else() - set(sdk_summary "${BRed} NO${CR} EXPERIMENTAL (default, enable with ${BMagenta}-DBUILD_SDK=ON${CR})") + set(sdk_summary "${BRed} NO${CR} EXPERIMENTAL (required C++14) (default, enable with ${BMagenta}-DBUILD_SDK=ON${CR})") endif() message(STATUS " ${BWhite}sdk${CR} ${sdk_summary}") message(STATUS " ") diff --git a/COPYRIGHT b/COPYRIGHT index ad561455..68437134 100644 --- a/COPYRIGHT +++ b/COPYRIGHT @@ -19,6 +19,10 @@ Files: extern/googletest Copyright: 2008, Google Inc. License: GOOGLE +Files: extern/asio +Copyright: 2003-2019, Christopher M. Kohlhoff (chris at kohlhoff dot com) +License: BSL-1.0 + License: LGPL-3.0-only [see LICENSE file] @@ -73,3 +77,28 @@ License: GOOGLE THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +License: BSL-1.0 + Boost Software License - Version 1.0 - August 17th, 2003 + + Permission is hereby granted, free of charge, to any person or organization + obtaining a copy of the software and accompanying documentation covered by + this license (the "Software") to use, reproduce, display, distribute, + execute, and transmit the Software, and to prepare derivative works of the + Software, and to permit third-parties to whom the Software is furnished to + do so, all subject to the following: + + The copyright notices in the Software and this entire statement, including + the above license grant, this restriction and the following disclaimer, + must be included in all copies of the Software, in whole or in part, and + all derivative works of the Software, unless such copies or derivative + works are solely in the form of machine-executable object code generated by + a source language processor. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT + SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE + FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, + ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md index 985a1e33..0b50307f 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,9 @@ cd fairmq_build; ctest -j4; cd .. cmake --build fairmq_build --target install ``` -If dependencies are not installed in standard system directories, you can hint the installation location via `-DCMAKE_PREFIX_PATH=...` or per dependency via `-D{DEPENDENCY}_ROOT=...`. `{DEPENDENCY}` can be `GTEST`, `BOOST`, `FAIRLOGGER`, `ZEROMQ`, `MSGPACK`, `NANOMSG`, `OFI`, `PMIX`, `ASIOFI` or `DDS` (`*_ROOT` variables can also be environment variables). +Please consult the [manpages of your CMake version](https://cmake.org/cmake/help/latest/manual/cmake.1.html) for more options. + +If dependencies are not installed in standard system directories, you can hint the installation location via `-DCMAKE_PREFIX_PATH=...` or per dependency via `-D{DEPENDENCY}_ROOT=...`. `{DEPENDENCY}` can be `GTEST`, `BOOST`, `FAIRLOGGER`, `ZEROMQ`, `MSGPACK`, `NANOMSG`, `OFI`, `PMIX`, `ASIO`, `ASIOFI` or `DDS` (`*_ROOT` variables can also be environment variables). ## Usage @@ -91,7 +93,7 @@ When building FairMQ, CMake will print a summary table of all available package ## Dependencies - * [asio](https://github.com/chriskohlhoff/asio) + * [asio](https://github.com/chriskohlhoff/asio) (optionally bundled) * [asiofi](https://github.com/FairRootGroup/asiofi) * [Boost](https://www.boost.org/) * [CMake](https://cmake.org/) diff --git a/cmake/FairMQConfig.cmake.in b/cmake/FairMQConfig.cmake.in index f4c16e2d..474f4661 100644 --- a/cmake/FairMQConfig.cmake.in +++ b/cmake/FairMQConfig.cmake.in @@ -36,4 +36,6 @@ set(CMAKE_MODULE_PATH ${@PROJECT_NAME@_CMAKEMODDIR} ${CMAKE_MODULE_PATH}) ### Import targets include(@PACKAGE_CMAKE_INSTALL_PREFIX@/@PACKAGE_INSTALL_DESTINATION@/@PROJECT_EXPORT_SET@.cmake) +@BUNDLED_PACKAGES@ + @PACKAGE_COMPONENTS@ diff --git a/cmake/FairMQLib.cmake b/cmake/FairMQLib.cmake index 0acb764a..e413b7da 100644 --- a/cmake/FairMQLib.cmake +++ b/cmake/FairMQLib.cmake @@ -266,6 +266,23 @@ check_required_components(${PROJECT_NAME}) set(PACKAGE_COMPONENTS ${PACKAGE_COMPONENTS} PARENT_SCOPE) endfunction() +function(generate_bundled_packages) + if(asio_BUNDLED) + set(BUNDLED_PACKAGES "\ +####### Expanded from @BUNDLED_PACKAGES@ by configure_package_config_file() ######### + +if(\"\${CMAKE_MAJOR_VERSION}.\${CMAKE_MINOR_VERSION}\" VERSION_LESS 3.11) + message(FATAL_ERROR \"CMake >= 3.11 required\") +endif() +set_target_properties(${PROJECT_NAME}::bundled_asio_headers PROPERTIES IMPORTED_GLOBAL TRUE) +add_library(asio::headers ALIAS ${PROJECT_NAME}::bundled_asio_headers) +set(asio_VERSION ${asio_VERSION}) + +") + endif() +set(BUNDLED_PACKAGES ${BUNDLED_PACKAGES} PARENT_SCOPE) +endfunction() + # Configure/Install CMake package macro(install_cmake_package) list(SORT PROJECT_PACKAGE_DEPENDENCIES) @@ -288,6 +305,7 @@ macro(install_cmake_package) ) generate_package_dependencies() # fills ${PACKAGE_DEPENDENCIES} generate_package_components() # fills ${PACKAGE_COMPONENTS} + generate_bundled_packages() # fills ${BUNDLED_PACKAGES} string(TOUPPER ${CMAKE_BUILD_TYPE} PROJECT_BUILD_TYPE_UPPER) set(PROJECT_CXX_FLAGS ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${PROJECT_BUILD_TYPE_UPPER}}) configure_package_config_file( @@ -312,10 +330,11 @@ endmacro() # # Wrapper around CMake's native find_package command to add some features and bookkeeping. # -# The qualifier (PRIVATE|PUBLIC|INTERFACE) to the package to populate +# The qualifier (PRIVATE|PUBLIC|INTERFACE|BUNDLED) to the package to populate # the variables PROJECT_[INTERFACE]__([VERSION]|[COMPONENTS]|PACKAGE_DEPENDENCIES) # accordingly. This bookkeeping information is used to print our dependency found summary -# table and to generate a part of our CMake package. +# table and to generate a part of our CMake package. BUNDLED decays to PUBLIC if the variable +# _BUNDLED is false and to PRIVATE otherwise. # # When a dependending package is listed with ADD_REQUIREMENTS_OF the variables # __VERSION|COMPONENTS are looked up to and added to the native @@ -372,25 +391,36 @@ macro(find_package2 qualifier pkgname) find_package(${pkgname} ${__version__} QUIET ${ARGS_UNPARSED_ARGUMENTS}) endif() + if(${qualifier} STREQUAL BUNDLED) + if(${pkgname}_BUNDLED) + set(__qualifier__ PRIVATE) + else() + set(__qualifier__ PUBLIC) + endif() + else() + set(__qualifier__ ${qualifier}) + endif() + if(${pkgname}_FOUND) - if(${qualifier} STREQUAL PRIVATE) + if(${__qualifier__} STREQUAL PRIVATE) set(PROJECT_${pkgname}_VERSION ${__version__}) set(PROJECT_${pkgname}_COMPONENTS ${__components__}) set(PROJECT_PACKAGE_DEPENDENCIES ${PROJECT_PACKAGE_DEPENDENCIES} ${pkgname}) - elseif(${qualifier} STREQUAL PUBLIC) + elseif(${__qualifier__} STREQUAL PUBLIC) set(PROJECT_${pkgname}_VERSION ${__version__}) set(PROJECT_${pkgname}_COMPONENTS ${__components__}) set(PROJECT_PACKAGE_DEPENDENCIES ${PROJECT_PACKAGE_DEPENDENCIES} ${pkgname}) set(PROJECT_INTERFACE_${pkgname}_VERSION ${__version__}) set(PROJECT_INTERFACE_${pkgname}_COMPONENTS ${__components__}) set(PROJECT_INTERFACE_PACKAGE_DEPENDENCIES ${PROJECT_INTERFACE_PACKAGE_DEPENDENCIES} ${pkgname}) - elseif(${qualifier} STREQUAL INTERFACE) + elseif(${__qualifier__} STREQUAL INTERFACE) set(PROJECT_INTERFACE_${pkgname}_VERSION ${__version__}) set(PROJECT_INTERFACE_${pkgname}_COMPONENTS ${__components__}) set(PROJECT_INTERFACE_PACKAGE_DEPENDENCIES ${PROJECT_INTERFACE_PACKAGE_DEPENDENCIES} ${pkgname}) endif() endif() + unset(__qualifier__) unset(__version__) unset(__components__) unset(__required_versions__) @@ -421,26 +451,31 @@ function(build_bundled package bundle) set(${package}_SOURCE_DIR ${CMAKE_SOURCE_DIR}/${bundle}) set(${package}_BINARY_DIR ${CMAKE_BINARY_DIR}/${bundle}) file(MAKE_DIRECTORY ${${package}_BINARY_DIR}) - set(${package}_INSTALL_DIR ${CMAKE_BINARY_DIR}/${bundle}_install) - file(MAKE_DIRECTORY ${${package}_INSTALL_DIR}) set(${package}_BUILD_LOGFILE ${${package}_BINARY_DIR}/build.log) file(REMOVE ${${package}_BUILD_LOGFILE}) - set(${package}_ROOT ${${package}_INSTALL_DIR}) if(Git_FOUND) exec(${GIT_EXECUTABLE} submodule update --init --recursive --depth 1 -- ${${package}_SOURCE_DIR}) endif() if(${package} STREQUAL GTest) + set(${package}_INSTALL_DIR ${CMAKE_BINARY_DIR}/${bundle}_install) + file(MAKE_DIRECTORY ${${package}_INSTALL_DIR}) + set(${package}_ROOT ${${package}_INSTALL_DIR}) + exec(${CMAKE_COMMAND} -S ${${package}_SOURCE_DIR} -B ${${package}_BINARY_DIR} -G ${CMAKE_GENERATOR} -DCMAKE_INSTALL_PREFIX=${${package}_INSTALL_DIR} -DBUILD_GMOCK=OFF ) exec(${CMAKE_COMMAND} --build ${${package}_BINARY_DIR}) exec(${CMAKE_COMMAND} --build ${${package}_BINARY_DIR} --target install) + elseif(${package} STREQUAL asio) + set(${package}_BUILD_INCLUDE_DIR ${${package}_SOURCE_DIR}/asio/include CACHE PATH "Bundled ${package} build-interface include dir") + set(${package}_INSTALL_INCLUDE_DIR ${PROJECT_INSTALL_INCDIR}/bundled CACHE PATH "Bundled ${package} install-interface include dir") + set(${package}_ROOT ${${package}_SOURCE_DIR}/asio) endif() string(TOUPPER ${package} package_upper) - set(${package_upper}_ROOT "${${package}_INSTALL_DIR}" CACHE PATH "Bundled ${package} install dir") + set(${package_upper}_ROOT "${${package}_ROOT}" CACHE PATH "Bundled ${package} install prefix search hint") set(${package}_BUNDLED ON CACHE BOOL "Whether bundled ${package} was used") message(STATUS "Building bundled ${package} - done") diff --git a/cmake/Findasio.cmake b/cmake/Findasio.cmake index dd5537b0..b68c3252 100644 --- a/cmake/Findasio.cmake +++ b/cmake/Findasio.cmake @@ -36,6 +36,14 @@ find_package_handle_standard_args(asio HANDLE_COMPONENTS ) +if(asio_FOUND AND asio_BUNDLED) + add_library(bundled_asio_headers INTERFACE) + target_include_directories(bundled_asio_headers INTERFACE + $ + $ + ) + add_library(asio::headers ALIAS bundled_asio_headers) +endif() if(asio_FOUND AND NOT TARGET asio::headers) add_library(asio::headers INTERFACE IMPORTED) set_target_properties(asio::headers PROPERTIES diff --git a/extern/asio b/extern/asio new file mode 160000 index 00000000..90f32660 --- /dev/null +++ b/extern/asio @@ -0,0 +1 @@ +Subproject commit 90f32660cd503494b3707840cfbd5434d8e9dabe diff --git a/extern/bundled_asio.cmake b/extern/bundled_asio.cmake new file mode 100644 index 00000000..91919802 --- /dev/null +++ b/extern/bundled_asio.cmake @@ -0,0 +1,17 @@ +################################################################################ +# Copyright (C) 2019 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH # +# # +# This software is distributed under the terms of the # +# GNU Lesser General Public Licence (LGPL) version 3, # +# copied verbatim in the file "LICENSE" # +################################################################################ + +if(NOT TARGET asio::headers) + if(Git_FOUND) + execute_process( + COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive --depth 1 -- extern/asio + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + ) + endif() + +endif() diff --git a/fairmq/sdk/CMakeLists.txt b/fairmq/sdk/CMakeLists.txt index cbb06b65..989f1991 100644 --- a/fairmq/sdk/CMakeLists.txt +++ b/fairmq/sdk/CMakeLists.txt @@ -44,20 +44,22 @@ target_include_directories(${target} PUBLIC $ $ - $ + $ ) target_link_libraries(${target} PUBLIC + asio::headers + Boost::boost Boost::filesystem FairLogger::FairLogger + Threads::Threads + Tools StateMachine PRIVATE - Boost::boost DDS::dds_intercom_lib DDS::dds_tools_lib DDS::dds_topology_lib - Tools ) set_target_properties(${target} PROPERTIES VERSION ${PROJECT_GIT_VERSION}