adapt and fix cmake build to match mp11, assert, ...

This commit is contained in:
Hans Dembinski 2019-12-28 20:16:46 +01:00 committed by GitHub
parent ca07c7fa4a
commit ed9d6324d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 57 additions and 153 deletions

View File

@ -4,117 +4,85 @@
# Warning: Boost-CMake support is incomplete; testing works, install target doesn't # 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) add_library(boost_histogram INTERFACE)
set_property(TARGET boost_histogram PROPERTY EXPORT_NAME histogram)
add_library(Boost::histogram ALIAS boost_histogram) add_library(Boost::histogram ALIAS boost_histogram)
target_include_directories(boost_histogram INTERFACE include)
target_compile_features(boost_histogram INTERFACE target_compile_features(boost_histogram INTERFACE
cxx_alias_templates cxx_variadic_templates cxx_decltype_auto cxx_alias_templates cxx_variadic_templates cxx_decltype_auto
cxx_defaulted_functions cxx_generic_lambdas cxx_range_for cxx_defaulted_functions cxx_generic_lambdas cxx_range_for
cxx_relaxed_constexpr cxx_return_type_deduction) cxx_relaxed_constexpr cxx_return_type_deduction)
target_include_directories(boost_histogram
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include>)
target_link_libraries(boost_histogram target_link_libraries(boost_histogram
INTERFACE INTERFACE
Boost::assert Boost::assert
Boost::config Boost::config
Boost::core Boost::core
Boost::mp11 Boost::mp11
Boost::throw_exception Boost::throw_exception
Boost::variant2 Boost::variant2)
)
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
########################################################### # Fetch support files
# Setup `check_histogram` target to build and run all tests.
###########################################################
# `function` confuses FetchContent, sees empty CMAKE_CURRENT_LIST_DIR message(STATUS "Fetching BoostFetch.cmake")
macro(fetch_and_include name)
message(STATUS "Fetching ${name}")
set(fetch_and_include_local_path "${CMAKE_BINARY_DIR}/fetch_and_include/${name}") file(DOWNLOAD
if(NOT EXISTS ${fetch_and_include_local_path}) "https://raw.githubusercontent.com/boostorg/cmake/develop/include/BoostFetch.cmake"
file(DOWNLOAD "${CMAKE_BINARY_DIR}/fetch_and_include/BoostFetch.cmake"
"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() include("${CMAKE_BINARY_DIR}/fetch_and_include/BoostFetch.cmake")
fetch_and_include(cmake/boost_test.cmake) boost_fetch(boostorg/cmake TAG develop NO_ADD_SUBDIR)
fetch_and_include(cmake/boost_fetch.cmake)
boost_fetch(boostorg/assert TAG develop) FetchContent_GetProperties(boostorg_cmake)
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)
## No cmake support yet list(APPEND CMAKE_MODULE_PATH ${boostorg_cmake_SOURCE_DIR}/include)
# boost_fetch(boostorg/accumulators TAG develop)
# boost_fetch(boostorg/range TAG develop)
# boost_fetch(boostorg/serialization TAG develop)
# boost_fetch(boostorg/units TAG develop)
find_package(Threads) # for optional multi-threaded tests # Enable testing
enable_testing() include(CTest)
add_custom_target(histogram_check add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C $<CONFIG>)
COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C $<CONFIG>
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Build and then run all the tests and examples.")
########################################################### if(BUILD_TESTING)
# Setup 'install' target and package config file.
###########################################################
## installings targets doesn't work currently, fails with errors like set(BUILD_TESTING OFF) # hide cache variable
# 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(CONFIG_INSTALL_DIR lib/cmake/${PROJECT_NAME}-${PROJECT_VERSION}) boost_fetch(boostorg/assert TAG develop EXCLUDE_FROM_ALL)
# boost_fetch(boostorg/config TAG develop EXCLUDE_FROM_ALL)
# install(TARGETS boost_histogram boost_fetch(boostorg/core TAG develop EXCLUDE_FROM_ALL)
# boost_assert boost_fetch(boostorg/mp11 TAG develop EXCLUDE_FROM_ALL)
# boost_config boost_fetch(boostorg/throw_exception TAG develop EXCLUDE_FROM_ALL)
# boost_core boost_fetch(boostorg/variant2 TAG develop EXCLUDE_FROM_ALL)
# boost_mp11 ## No cmake support yet
# boost_throw_exception # boost_fetch(boostorg/accumulators TAG develop)
# boost_variant2 # boost_fetch(boostorg/range TAG develop)
# EXPORT ${PROJECT_NAME}Targets) # boost_fetch(boostorg/serialization TAG develop)
# install(EXPORT ${PROJECT_NAME}Targets # boost_fetch(boostorg/units TAG develop)
# DESTINATION ${CONFIG_INSTALL_DIR}
# NAMESPACE Boost:: unset(BUILD_TESTING)
# FILE ${PROJECT_NAME}Config.cmake)
# endif()
# install(DIRECTORY include/ DESTINATION include)
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) add_subdirectory(test)
endif()
if (COMMAND boost_fetch)
add_subdirectory(benchmark) add_subdirectory(benchmark)
endif() endif()

View File

@ -2,48 +2,10 @@
# Distributed under the Boost Software License, Version 1.0. # 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 # 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 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) option(BENCHMARK_ENABLE_TESTING "" OFF)
boost_fetch(hdembinski/benchmark) boost_fetch(google/benchmark)
macro(add_benchmark name) macro(add_benchmark name)
add_executable(${name} "${name}.cpp") add_executable(${name} "${name}.cpp")

View File

@ -2,9 +2,6 @@
# Distributed under the Boost Software License, Version 1.0. # 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 # 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) find_package(PythonInterp)
if (PYTHONINTERP_FOUND) if (PYTHONINTERP_FOUND)
# checks that b2 and cmake are in sync # 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) add_test(NAME runpy-${PROJECT_NAME}_check_odr_test COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/check_odr_test.py)
endif() endif()
include(BoostTest)
# keep in sync with Jamfile, this should be automatized... # keep in sync with Jamfile, this should be automatized...
boost_test(TYPE compile-fail SOURCES axis_category_fail0.cpp boost_test(TYPE compile-fail SOURCES axis_category_fail0.cpp
LIBRARIES Boost::histogram 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) if (cxx_std_17 IN_LIST CMAKE_CXX_COMPILE_FEATURES)
boost_test(TYPE run SOURCES deduction_guides_test.cpp boost_test(TYPE run SOURCES deduction_guides_test.cpp
LIBRARIES Boost::histogram Boost::core) 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() endif()
if (Threads_FOUND) if (Threads_FOUND)

View File

@ -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 <boost/core/lightweight_test.hpp>
#include <boost/version.hpp>
#include <cstdio>
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();
}