Fetch tools/cmake instead of having a duplicate

This commit is contained in:
Peter Dimov
2019-12-22 03:08:58 +02:00
parent 2deeac36b4
commit 3afdb0e876
6 changed files with 33 additions and 188 deletions

View File

@@ -16,16 +16,24 @@ target_compile_features(boost_mp11 INTERFACE cxx_alias_templates cxx_variadic_te
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
# Fetch support files
# Testing
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/BoostFetch.cmake")
boost_fetch(boostorg/cmake TAG "feature/boost-install" NO_ADD_SUBDIR)
FetchContent_GetProperties(boostorg_cmake)
list(APPEND CMAKE_MODULE_PATH ${boostorg_cmake_SOURCE_DIR}/include)
# Enable testing
include(CTest)
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C $<CONFIG>)
include(BoostFetch)
if(BUILD_TESTING)
set(BUILD_TESTING OFF)
set(BUILD_TESTING OFF) # hide cache variable
boost_fetch(boostorg/assert TAG develop EXCLUDE_FROM_ALL)
boost_fetch(boostorg/config TAG develop EXCLUDE_FROM_ALL)
@@ -33,28 +41,15 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
unset(BUILD_TESTING)
# Installation
endif()
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
endif()
set(LIB boost_mp11)
set(CONFIG_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/${LIB}-${PROJECT_VERSION})
include(BoostInstall OPTIONAL RESULT_VARIABLE HAVE_BOOST_INSTALL)
install(TARGETS ${LIB} EXPORT ${LIB}-targets)
install(EXPORT ${LIB}-targets DESTINATION ${CONFIG_INSTALL_DIR} NAMESPACE Boost:: FILE ${LIB}-config.cmake)
if(HAVE_BOOST_INSTALL)
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
# Mp11 is independent of 32/64, so this hack makes BoostMp11ConfigVersion.cmake skip the check
set(OLD_CMAKE_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P})
unset(CMAKE_SIZEOF_VOID_P)
write_basic_package_version_file("${PROJECT_BINARY_DIR}/${LIB}-config-version.cmake" COMPATIBILITY AnyNewerVersion)
set(CMAKE_SIZEOF_VOID_P ${OLD_CMAKE_SIZEOF_VOID_P})
install(FILES "${PROJECT_BINARY_DIR}/${LIB}-config-version.cmake" DESTINATION ${CONFIG_INSTALL_DIR})
#export(EXPORT ${PROJECT_NAME}Targets NAMESPACE Boost:: FILE ${PROJECT_NAME}Config.cmake)
boost_install(boost_mp11)
endif()

View File

@@ -1,4 +1,4 @@
# Copyright 2018 Peter Dimov
# Copyright 2018, 2019 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
@@ -34,7 +34,7 @@ endif()
function(boost_fetch)
cmake_parse_arguments(_ "EXCLUDE_FROM_ALL" "TAG" "" ${ARGN})
cmake_parse_arguments(_ "EXCLUDE_FROM_ALL;NO_ADD_SUBDIR" "TAG" "" ${ARGN})
if(NOT __UNPARSED_ARGUMENTS)
@@ -78,7 +78,11 @@ function(boost_fetch)
FetchContent_Populate(${NAME})
if(__EXCLUDE_FROM_ALL)
if(__NO_ADD_SUBDIR)
# Skip add_subdirectory
elseif(__EXCLUDE_FROM_ALL)
add_subdirectory(${${NAME}_SOURCE_DIR} ${${NAME}_BINARY_DIR} EXCLUDE_FROM_ALL)

View File

@@ -1,36 +0,0 @@
# Copyright 2019 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
if(NOT CMAKE_VERSION VERSION_LESS 3.10)
include_guard()
endif()
function(boost_message type)
if(type STREQUAL "VERBOSE")
if(Boost_VERBOSE OR Boost_DEBUG)
set(type STATUS)
elseif(CMAKE_VERSION VERSION_LESS 3.15)
return()
endif()
endif()
if(type STREQUAL "DEBUG")
if(Boost_DEBUG)
set(type STATUS)
elseif(CMAKE_VERSION VERSION_LESS 3.15)
return()
endif()
endif()
set(m "")
math(EXPR last "${ARGC}-1")
foreach(i RANGE 1 ${last})
set(m "${m}${ARGV${i}}")
endforeach()
message(${type} "${m}")
endfunction()

View File

@@ -1,75 +0,0 @@
# Copyright 2018, 2019 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
if(NOT CMAKE_VERSION VERSION_LESS 3.10)
include_guard()
endif()
function(boost_test)
cmake_parse_arguments(_ "" "TYPE;PREFIX;NAME" "SOURCES;LIBRARIES;ARGUMENTS" ${ARGN})
if(NOT __TYPE)
set(__TYPE run)
endif()
if(NOT __PREFIX)
set(__PREFIX ${PROJECT_NAME})
endif()
if(NOT __NAME)
list(GET __SOURCES 0 __NAME)
string(MAKE_C_IDENTIFIER ${__NAME} __NAME)
endif()
set(__NAME ${__PREFIX}-${__NAME})
if(__TYPE STREQUAL "compile" OR __TYPE STREQUAL "compile-fail")
add_library(${__NAME} STATIC EXCLUDE_FROM_ALL ${__SOURCES})
target_link_libraries(${__NAME} ${__LIBRARIES})
add_test(NAME compile-${__NAME} COMMAND "${CMAKE_COMMAND}" --build ${CMAKE_BINARY_DIR} --target ${__NAME} --config $<CONFIG>)
if(__TYPE STREQUAL "compile-fail")
set_tests_properties(compile-${__NAME} PROPERTIES WILL_FAIL TRUE)
endif()
elseif(__TYPE STREQUAL "link")
add_executable(${__NAME} EXCLUDE_FROM_ALL ${__SOURCES})
target_link_libraries(${__NAME} ${__LIBRARIES})
add_test(NAME link-${__NAME} COMMAND "${CMAKE_COMMAND}" --build ${CMAKE_BINARY_DIR} --target ${__NAME} --config $<CONFIG>)
elseif(__TYPE STREQUAL "link-fail")
add_library(compile-${__NAME} STATIC EXCLUDE_FROM_ALL ${__SOURCES})
target_link_libraries(compile-${__NAME} ${__LIBRARIES})
add_test(NAME compile-${__NAME} COMMAND "${CMAKE_COMMAND}" --build ${CMAKE_BINARY_DIR} --target compile-${__NAME} --config $<CONFIG>)
add_executable(${__NAME} EXCLUDE_FROM_ALL ${__SOURCES})
target_link_libraries(${__NAME} ${__LIBRARIES})
add_test(NAME link-${__NAME} COMMAND "${CMAKE_COMMAND}" --build ${CMAKE_BINARY_DIR} --target ${__NAME} --config $<CONFIG>)
set_tests_properties(link-${__NAME} PROPERTIES WILL_FAIL TRUE)
elseif(__TYPE STREQUAL "run" OR __TYPE STREQUAL "run-fail")
add_executable(${__NAME} EXCLUDE_FROM_ALL ${__SOURCES})
target_link_libraries(${__NAME} ${__LIBRARIES})
add_test(NAME compile-${__NAME} COMMAND "${CMAKE_COMMAND}" --build ${CMAKE_BINARY_DIR} --target ${__NAME} --config $<CONFIG>)
add_test(NAME run-${__NAME} COMMAND ${__NAME} ${__ARGUMENTS})
set_tests_properties(run-${__NAME} PROPERTIES DEPENDS compile-${__NAME})
if(__TYPE STREQUAL "run-fail")
set_tests_properties(run-${__NAME} PROPERTIES WILL_FAIL TRUE)
endif()
endif()
endfunction(boost_test)

View File

@@ -1,47 +0,0 @@
# Copyright 2018, 2019 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
if(NOT CMAKE_VERSION VERSION_LESS 3.10)
include_guard()
endif()
include(BoostTest)
include(BoostMessage)
function(boost_test_jamfile)
cmake_parse_arguments(_ "" "FILE;PREFIX" "LIBRARIES" ${ARGN})
file(STRINGS ${__FILE} data)
set(types compile compile-fail link link-fail run run-fail)
foreach(line IN LISTS data)
if(line)
string(REGEX MATCHALL "[^ ]+" ll ${line})
if(ll)
list(GET ll 0 e0)
if(e0 IN_LIST types)
list(LENGTH ll lln)
if(NOT lln EQUAL 2)
boost_message(DEBUG "Jamfile line ignored: ${line}")
else()
list(GET ll 1 e1)
boost_test(PREFIX ${__PREFIX} TYPE ${e0} SOURCES ${e1} LIBRARIES ${__LIBRARIES})
endif()
endif()
endif()
endif()
endforeach(line)
endfunction(boost_test_jamfile)

View File

@@ -2,7 +2,11 @@
# 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(BoostTestJamfile)
include(BoostTestJamfile OPTIONAL RESULT_VARIABLE HAVE_BOOST_TEST)
if(HAVE_BOOST_TEST)
boost_test_jamfile(FILE Jamfile LIBRARIES Boost::mp11 Boost::core)
boost_test(SOURCES check_cmake_version.cpp ARGUMENTS ${PROJECT_VERSION} LIBRARIES Boost::core Boost::config)
endif()