From ed9d6324d13c915f411f83d6571dbc0bb1892595 Mon Sep 17 00:00:00 2001 From: Hans Dembinski Date: Sat, 28 Dec 2019 20:16:46 +0100 Subject: [PATCH] adapt and fix cmake build to match mp11, assert, ... --- CMakeLists.txt | 136 ++++++++++++++--------------------- benchmark/CMakeLists.txt | 42 +---------- test/CMakeLists.txt | 7 +- test/check_cmake_version.cpp | 25 ------- 4 files changed, 57 insertions(+), 153 deletions(-) delete mode 100644 test/check_cmake_version.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 8cb7831e..2374a879 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,117 +4,85 @@ # Warning: Boost-CMake support is incomplete; testing works, install target doesn't -cmake_minimum_required(VERSION 3.6) +cmake_minimum_required(VERSION 3.5...3.16) -project(BoostHistogram VERSION 1.73.0 LANGUAGES CXX) +project(boost_histogram VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX) add_library(boost_histogram INTERFACE) -set_property(TARGET boost_histogram PROPERTY EXPORT_NAME histogram) - add_library(Boost::histogram ALIAS boost_histogram) +target_include_directories(boost_histogram INTERFACE include) + target_compile_features(boost_histogram INTERFACE cxx_alias_templates cxx_variadic_templates cxx_decltype_auto cxx_defaulted_functions cxx_generic_lambdas cxx_range_for cxx_relaxed_constexpr cxx_return_type_deduction) -target_include_directories(boost_histogram - INTERFACE - $ $) + target_link_libraries(boost_histogram - INTERFACE - Boost::assert - Boost::config - Boost::core - Boost::mp11 - Boost::throw_exception - Boost::variant2 -) + INTERFACE + Boost::assert + Boost::config + Boost::core + Boost::mp11 + Boost::throw_exception + Boost::variant2) if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) - ########################################################### - # Setup `check_histogram` target to build and run all tests. - ########################################################### + # Fetch support files - # `function` confuses FetchContent, sees empty CMAKE_CURRENT_LIST_DIR - macro(fetch_and_include name) - message(STATUS "Fetching ${name}") + message(STATUS "Fetching BoostFetch.cmake") - set(fetch_and_include_local_path "${CMAKE_BINARY_DIR}/fetch_and_include/${name}") - if(NOT EXISTS ${fetch_and_include_local_path}) - file(DOWNLOAD - "https://raw.githubusercontent.com/boostorg/mincmake/develop/${name}" - "${CMAKE_BINARY_DIR}/fetch_and_include/${name}" - ) - endif() - include("${CMAKE_BINARY_DIR}/fetch_and_include/${name}") + file(DOWNLOAD + "https://raw.githubusercontent.com/boostorg/cmake/develop/include/BoostFetch.cmake" + "${CMAKE_BINARY_DIR}/fetch_and_include/BoostFetch.cmake" + ) - endmacro() + include("${CMAKE_BINARY_DIR}/fetch_and_include/BoostFetch.cmake") - fetch_and_include(cmake/boost_test.cmake) - fetch_and_include(cmake/boost_fetch.cmake) + boost_fetch(boostorg/cmake TAG develop NO_ADD_SUBDIR) - boost_fetch(boostorg/assert TAG develop) - boost_fetch(boostorg/config TAG develop) - boost_fetch(boostorg/core TAG develop) - boost_fetch(boostorg/mp11 TAG develop) - boost_fetch(boostorg/throw_exception TAG develop) - boost_fetch(boostorg/variant2 TAG develop) + FetchContent_GetProperties(boostorg_cmake) - ## No cmake support yet - # boost_fetch(boostorg/accumulators TAG develop) - # boost_fetch(boostorg/range TAG develop) - # boost_fetch(boostorg/serialization TAG develop) - # boost_fetch(boostorg/units TAG develop) + list(APPEND CMAKE_MODULE_PATH ${boostorg_cmake_SOURCE_DIR}/include) - find_package(Threads) # for optional multi-threaded tests + # Enable testing - enable_testing() - add_custom_target(histogram_check - COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C $ - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMENT "Build and then run all the tests and examples.") + include(CTest) + add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C $) - ########################################################### - # Setup 'install' target and package config file. - ########################################################### + if(BUILD_TESTING) - ## installings targets doesn't work currently, fails with errors like - # Target "boost_variant" INTERFACE_INCLUDE_DIRECTORIES property contains - # path: - # - # "/path/to/histogram/build/_deps/boostorg_variant-src/include" - # - # which is prefixed in the build directory.Target "boost_variant" - # INTERFACE_INCLUDE_DIRECTORIES property contains path: - # - # "/path/to/histogram/build/_deps/boostorg_variant-src/include" - # - # which is prefixed in the source directory. + set(BUILD_TESTING OFF) # hide cache variable - # set(CONFIG_INSTALL_DIR lib/cmake/${PROJECT_NAME}-${PROJECT_VERSION}) - # - # install(TARGETS boost_histogram - # boost_assert - # boost_config - # boost_core - # boost_mp11 - # boost_throw_exception - # boost_variant2 - # EXPORT ${PROJECT_NAME}Targets) - # install(EXPORT ${PROJECT_NAME}Targets - # DESTINATION ${CONFIG_INSTALL_DIR} - # NAMESPACE Boost:: - # FILE ${PROJECT_NAME}Config.cmake) - # - # install(DIRECTORY include/ DESTINATION include) + boost_fetch(boostorg/assert TAG develop EXCLUDE_FROM_ALL) + boost_fetch(boostorg/config TAG develop EXCLUDE_FROM_ALL) + boost_fetch(boostorg/core TAG develop EXCLUDE_FROM_ALL) + boost_fetch(boostorg/mp11 TAG develop EXCLUDE_FROM_ALL) + boost_fetch(boostorg/throw_exception TAG develop EXCLUDE_FROM_ALL) + boost_fetch(boostorg/variant2 TAG develop EXCLUDE_FROM_ALL) + ## No cmake support yet + # boost_fetch(boostorg/accumulators TAG develop) + # boost_fetch(boostorg/range TAG develop) + # boost_fetch(boostorg/serialization TAG develop) + # boost_fetch(boostorg/units TAG develop) + + unset(BUILD_TESTING) + + endif() endif() -if (COMMAND boost_test) +if(BOOST_SUPERPROJECT_VERSION) + + include(BoostInstall) + boost_install(TARGETS boost_histogram HEADER_DIRECTORY include/) + +endif() + +if (BUILD_TESTING) + add_subdirectory(test) -endif() - -if (COMMAND boost_fetch) add_subdirectory(benchmark) + endif() diff --git a/benchmark/CMakeLists.txt b/benchmark/CMakeLists.txt index e9f0ce84..1a125edb 100644 --- a/benchmark/CMakeLists.txt +++ b/benchmark/CMakeLists.txt @@ -2,48 +2,10 @@ # Distributed under the Boost Software License, Version 1.0. # See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt -cmake_minimum_required(VERSION 3.6) - +# setup for google benchmark set(CMAKE_BUILD_TYPE Release) # ok, only set in local scope - -if (NOT COMMAND boost_fetch) - # `function` confuses FetchContent, sees empty CMAKE_CURRENT_LIST_DIR - macro(fetch_and_include name) - message(STATUS "Fetching ${name}") - - set(fetch_and_include_local_path "${CMAKE_BINARY_DIR}/fetch_and_include/${name}") - if(NOT EXISTS ${fetch_and_include_local_path}) - file(DOWNLOAD - "https://raw.githubusercontent.com/boostorg/mincmake/develop/${name}" - "${CMAKE_BINARY_DIR}/fetch_and_include/${name}" - ) - endif() - include("${CMAKE_BINARY_DIR}/fetch_and_include/${name}") - endmacro() - - fetch_and_include(cmake/boost_fetch.cmake) -endif() - -# allow benchmarks to build old versions of the code if we sit inside the boost metaproject -if (NOT TARGET boost_histogram) - add_library(boost_histogram INTERFACE) - add_library(Boost::histogram ALIAS boost_histogram) - target_compile_features(boost_histogram INTERFACE - cxx_alias_templates cxx_variadic_templates cxx_decltype_auto - cxx_defaulted_functions cxx_generic_lambdas cxx_range_for - cxx_relaxed_constexpr cxx_return_type_deduction) - target_include_directories(boost_histogram - INTERFACE - ${CMAKE_CURRENT_SOURCE_DIR}/../include - ${CMAKE_CURRENT_SOURCE_DIR}/../../../ - ) - set(BENCHMARK_FLAGS) # old versions don't work with -fno-exceptions -else() - set(BENCHMARK_FLAGS -fno-exceptions -fno-rtti) -endif() - option(BENCHMARK_ENABLE_TESTING "" OFF) -boost_fetch(hdembinski/benchmark) +boost_fetch(google/benchmark) macro(add_benchmark name) add_executable(${name} "${name}.cpp") diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 45b2cb87..321929e6 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -2,9 +2,6 @@ # Distributed under the Boost Software License, Version 1.0. # See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt -boost_test(SOURCES check_cmake_version.cpp ARGUMENTS ${PROJECT_VERSION} - LIBRARIES Boost::core Boost::config) - find_package(PythonInterp) if (PYTHONINTERP_FOUND) # checks that b2 and cmake are in sync @@ -14,6 +11,8 @@ if (PYTHONINTERP_FOUND) add_test(NAME runpy-${PROJECT_NAME}_check_odr_test COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/check_odr_test.py) endif() +include(BoostTest) + # keep in sync with Jamfile, this should be automatized... boost_test(TYPE compile-fail SOURCES axis_category_fail0.cpp LIBRARIES Boost::histogram @@ -160,7 +159,7 @@ boost_test(TYPE run SOURCES utility_test.cpp if (cxx_std_17 IN_LIST CMAKE_CXX_COMPILE_FEATURES) boost_test(TYPE run SOURCES deduction_guides_test.cpp LIBRARIES Boost::histogram Boost::core) - target_compile_features(BoostHistogram-deduction_guides_test_cpp PRIVATE cxx_std_17) + target_compile_features(boost_histogram-deduction_guides_test_cpp PRIVATE cxx_std_17) endif() if (Threads_FOUND) diff --git a/test/check_cmake_version.cpp b/test/check_cmake_version.cpp deleted file mode 100644 index 160db585..00000000 --- a/test/check_cmake_version.cpp +++ /dev/null @@ -1,25 +0,0 @@ -// Check whether the version in CMakeLists.txt is up to date -// -// Copyright 2018 Peter Dimov -// -// Distributed under the Boost Software License, Version 1.0. -// See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt - -#include -#include -#include - -int main(int ac, char const* av[]) { - BOOST_TEST_EQ(ac, 2); - - if (ac >= 2) { - char version[64]; - std::sprintf(version, "%d.%d.%d", BOOST_VERSION / 100000, BOOST_VERSION / 100 % 1000, - BOOST_VERSION % 100); - - BOOST_TEST_CSTR_EQ(av[1], version); - } - - return boost::report_errors(); -}