Add boost_fetch.cmake

This commit is contained in:
Peter Dimov
2018-10-09 05:29:33 +03:00
parent 0ec05b3f0c
commit 0829d82ed1
4 changed files with 87 additions and 10 deletions

View File

@@ -8,10 +8,14 @@ project(BoostMinCMake LANGUAGES CXX)
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
include(cmake/boost_fetch.cmake)
include(cmake/boost_test.cmake) include(cmake/boost_test.cmake)
enable_testing() boost_fetch(boostorg/config TAG develop)
boost_fetch(boostorg/assert TAG develop)
boost_fetch(boostorg/core TAG develop)
enable_testing()
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C $<CONFIG>) add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C $<CONFIG>)
add_subdirectory(test) add_subdirectory(test)

73
cmake/boost_fetch.cmake Normal file
View File

@@ -0,0 +1,73 @@
# 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
if(NOT COMMAND FetchContent_Populate)
if(CMAKE_VERSION VERSION_LESS 3.11)
message(STATUS "Fetching FetchContent.cmake")
file(DOWNLOAD
"https://gitlab.kitware.com/cmake/cmake/raw/v3.11.3/Modules/FetchContent.cmake"
"${CMAKE_BINARY_DIR}/Modules/FetchContent.cmake"
)
file(DOWNLOAD
"https://gitlab.kitware.com/cmake/cmake/raw/v3.11.3/Modules/FetchContent/CMakeLists.cmake.in"
"${CMAKE_BINARY_DIR}/Modules/FetchContent/CMakeLists.cmake.in"
)
include(${CMAKE_BINARY_DIR}/Modules/FetchContent.cmake)
else()
include(FetchContent)
endif()
endif()
function(boost_fetch)
cmake_parse_arguments(_ "" "TAG" "" ${ARGN})
if(NOT __UNPARSED_ARGUMENTS)
message(FATAL_ERROR "boost_fetch: missing required argument, repository name")
return()
endif()
list(GET __UNPARSED_ARGUMENTS 0 REPO)
list(REMOVE_AT __UNPARSED_ARGUMENTS 0)
if(__UNPARSED_ARGUMENTS)
message(WARNING "boost_fetch: extra arguments ignored: ${__UNPARSED_ARGUMENTS}")
endif()
if(NOT __TAG)
set(__TAG master)
endif()
string(MAKE_C_IDENTIFIER ${REPO} NAME)
message(STATUS "Fetching ${REPO}:${__TAG}")
if(CMAKE_VERSION VERSION_LESS 3.6)
FetchContent_Populate(${NAME} QUIET GIT_REPOSITORY "https://github.com/${REPO}" GIT_TAG ${__TAG})
else()
FetchContent_Populate(${NAME} QUIET GIT_REPOSITORY "https://github.com/${REPO}" GIT_TAG ${__TAG} GIT_SHALLOW 1)
endif()
add_subdirectory(${${NAME}_SOURCE_DIR} ${${NAME}_BINARY_DIR})
endfunction(boost_fetch)

View File

@@ -18,6 +18,6 @@ boost_test(TYPE run-fail SOURCES run_fail.cpp)
boost_test_jamfile(FILE Jamfile PREFIX BoostMinCMake2) boost_test_jamfile(FILE Jamfile PREFIX BoostMinCMake2)
# # arguments
boost_test(TYPE run SOURCES arguments.cpp ARGUMENTS pumpkin) boost_test(TYPE run SOURCES arguments.cpp ARGUMENTS pumpkin LIBRARIES Boost::core)

View File

@@ -2,17 +2,17 @@
// 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
#include <iostream> #include <boost/core/lightweight_test.hpp>
#include <string.h> #include <string.h>
#define TEST(expr) if(!(expr)) { std::cerr << __FILE__ << "(" << __LINE__ << "): test '" #expr "' failed." << std::endl; r = 1; }
int main( int ac, char const* av[] ) int main( int ac, char const* av[] )
{ {
int r = 0; BOOST_TEST_EQ( ac, 2 );
TEST( ac == 2 ) if( ac >= 2 )
TEST( ac >= 2 && strcmp( av[1], "pumpkin" ) == 0 ) {
BOOST_TEST_CSTR_EQ( av[1], "pumpkin" );
}
return r; return boost::report_errors();
} }