From 3a50c15a9734439598b46442568b375a52c9d63d Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sun, 5 Jan 2020 03:29:05 +0200 Subject: [PATCH] Add CMake install support, tests --- .travis.yml | 28 +++++++++++- CMakeLists.txt | 30 ++++++++----- test/CMakeLists.txt | 11 +++++ test/Jamfile.v2 | 59 ++++++++++++++++---------- test/buffer_test.cpp | 14 +++++- test/cmake_install_test/CMakeLists.txt | 18 ++++++++ test/cmake_subdir_test/CMakeLists.txt | 3 +- test/conversion_test.cpp | 14 +++++- test/deprecated_test.cpp | 14 +++++- test/endian_operations_test.cpp | 14 +++++- test/endian_test.cpp | 14 +++++- 11 files changed, 178 insertions(+), 41 deletions(-) create mode 100644 test/CMakeLists.txt create mode 100644 test/cmake_install_test/CMakeLists.txt diff --git a/.travis.yml b/.travis.yml index 177f224..f4dfdfc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -330,15 +330,41 @@ matrix: compiler: clang++ env: UBSAN=1 TOOLSET=clang COMPILER=clang++ CXXSTD=03,11,14,1z UBSAN_OPTIONS=print_stacktrace=1 + - os: linux + env: CMAKE_TEST=1 + script: + - mkdir __build__ && cd __build__ + - cmake -DBOOST_ENABLE_CMAKE=1 -DBoost_VERBOSE=1 -DBOOST_INCLUDE_LIBRARIES=endian .. + - ctest --output-on-failure -R boost_endian + - os: linux compiler: g++ env: CMAKE_SUBDIR_TEST=1 + install: + - BOOST_BRANCH=develop + - if [ "$TRAVIS_BRANCH" = "master" ]; then BOOST_BRANCH=master; fi + - git clone -b $BOOST_BRANCH https://github.com/boostorg/assert.git ../assert + - git clone -b $BOOST_BRANCH https://github.com/boostorg/config.git ../config + - git clone -b $BOOST_BRANCH https://github.com/boostorg/core.git ../core + - git clone -b $BOOST_BRANCH https://github.com/boostorg/static_assert.git ../static_assert + - git clone -b $BOOST_BRANCH https://github.com/boostorg/type_traits.git ../type_traits script: - - cd libs/endian/test/cmake_subdir_test && mkdir __build__ && cd __build__ + - cd test/cmake_subdir_test && mkdir __build__ && cd __build__ - cmake .. - cmake --build . - cmake --build . --target check + - os: linux + env: CMAKE_INSTALL_TEST=1 + script: + - mkdir __build__ && cd __build__ + - cmake -DBOOST_ENABLE_CMAKE=1 -DBoost_VERBOSE=1 -DBOOST_INCLUDE_LIBRARIES="assert;config;core;endian;static_assert;type_traits" -DCMAKE_INSTALL_PREFIX=~/.local .. + - cmake --build . --target install + - cd ../libs/endian/test/cmake_install_test && mkdir __build__ && cd __build__ + - cmake -DCMAKE_INSTALL_PREFIX=~/.local .. + - cmake --build . + - cmake --build . --target check + install: - BOOST_BRANCH=develop && [ "$TRAVIS_BRANCH" == "master" ] && BOOST_BRANCH=master || true - cd .. diff --git a/CMakeLists.txt b/CMakeLists.txt index 765a986..6ec1017 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,11 +2,9 @@ # 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 -# Partial (add_subdirectory only) and experimental CMake support -# Subject to change; please do not rely on the contents of this file yet +cmake_minimum_required(VERSION 3.5...3.16) -cmake_minimum_required(VERSION 3.5) -project(BoostEndian LANGUAGES CXX) +project(boost_endian VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX) add_library(boost_endian INTERFACE) add_library(Boost::endian ALIAS boost_endian) @@ -14,10 +12,22 @@ add_library(Boost::endian ALIAS boost_endian) target_include_directories(boost_endian INTERFACE include) target_link_libraries(boost_endian - INTERFACE - Boost::config - Boost::core - Boost::predef - Boost::static_assert - Boost::type_traits + INTERFACE + Boost::config + Boost::core + Boost::static_assert + Boost::type_traits ) + +if(BOOST_SUPERPROJECT_VERSION) + + include(BoostInstall) + boost_install(TARGETS boost_endian HEADER_DIRECTORY include/) + +endif() + +if(BUILD_TESTING) + + add_subdirectory(test) + +endif() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..5de3000 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,11 @@ +# 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 + +include(BoostTestJamfile OPTIONAL RESULT_VARIABLE HAVE_BOOST_TEST) + +if(HAVE_BOOST_TEST) + +boost_test_jamfile(FILE Jamfile.v2 LINK_LIBRARIES Boost::endian Boost::core) + +endif() diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index dc3e1c0..5f98443 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -28,23 +28,24 @@ project clang:on ; -local rule endian-run ( sources + ) +local rule run-ni ( sources + ) { - local result ; - - result += [ run $(sources) ] ; - result += [ run $(sources) : : : BOOST_ENDIAN_NO_INTRINSICS : $(sources[1]:B)_ni ] ; - - return $(result) ; + return [ run $(sources) : : : BOOST_ENDIAN_NO_INTRINSICS : $(sources[1]:B)_ni ] ; } -endian-run buffer_test.cpp ; -endian-run endian_test.cpp ; -endian-run endian_operations_test.cpp ; +run buffer_test.cpp ; +run-ni buffer_test.cpp ; + +run endian_test.cpp ; +run-ni endian_test.cpp ; + +run endian_operations_test.cpp ; +run-ni endian_operations_test.cpp ; run endian_in_union_test.cpp ; -endian-run conversion_test.cpp ; +run conversion_test.cpp ; +run-ni conversion_test.cpp ; run intrinsic_test.cpp ; @@ -55,29 +56,41 @@ local allow-warnings = "-gcc:on" "-clang:on" ; -compile spirit_conflict_test.cpp - : $(allow-warnings) ; +compile spirit_conflict_test.cpp : $(allow-warnings) ; -endian-run endian_reverse_test.cpp ; +run endian_reverse_test.cpp ; +run-ni endian_reverse_test.cpp ; -endian-run endian_load_test.cpp ; -endian-run endian_store_test.cpp ; -endian-run endian_ld_st_roundtrip_test.cpp ; +run endian_load_test.cpp ; +run-ni endian_load_test.cpp ; -endian-run endian_arithmetic_test.cpp ; +run endian_store_test.cpp ; +run-ni endian_store_test.cpp ; + +run endian_ld_st_roundtrip_test.cpp ; +run-ni endian_ld_st_roundtrip_test.cpp ; + +run endian_arithmetic_test.cpp ; +run-ni endian_arithmetic_test.cpp ; run deprecated_test.cpp ; compile endian_reverse_cx_test.cpp ; compile endian_reverse_cx_test.cpp : BOOST_ENDIAN_NO_INTRINSICS : endian_reverse_cx_test_ni ; -endian-run load_convenience_test.cpp ; -endian-run store_convenience_test.cpp ; +run load_convenience_test.cpp ; +run-ni load_convenience_test.cpp ; -endian-run float_typedef_test.cpp ; +run store_convenience_test.cpp ; +run-ni store_convenience_test.cpp ; -endian-run data_test.cpp ; +run float_typedef_test.cpp ; +run-ni float_typedef_test.cpp ; -endian-run endian_hpp_test.cpp ; +run data_test.cpp ; +run-ni data_test.cpp ; + +run endian_hpp_test.cpp ; +run-ni endian_hpp_test.cpp ; run order_test.cpp ; diff --git a/test/buffer_test.cpp b/test/buffer_test.cpp index 0fcbe5b..2d97355 100644 --- a/test/buffer_test.cpp +++ b/test/buffer_test.cpp @@ -12,7 +12,6 @@ #include #include -#include #include #include #include @@ -322,4 +321,17 @@ int cpp_main(int, char *[]) return ::boost::report_errors(); } +int main( int argc, char* argv[] ) +{ + try + { + return cpp_main( argc, argv ); + } + catch( std::exception const & x ) + { + BOOST_ERROR( x.what() ); + return boost::report_errors(); + } +} + #include diff --git a/test/cmake_install_test/CMakeLists.txt b/test/cmake_install_test/CMakeLists.txt new file mode 100644 index 0000000..74116d2 --- /dev/null +++ b/test/cmake_install_test/CMakeLists.txt @@ -0,0 +1,18 @@ +# 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 + +cmake_minimum_required(VERSION 3.5...3.16) + +project(cmake_install_test LANGUAGES CXX) + +find_package(boost_endian REQUIRED) +find_package(boost_core REQUIRED) + +add_executable(quick ../quick.cpp) +target_link_libraries(quick Boost::endian Boost::core) + +enable_testing() +add_test(quick quick) + +add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C $) diff --git a/test/cmake_subdir_test/CMakeLists.txt b/test/cmake_subdir_test/CMakeLists.txt index 2826ba5..6310b1f 100644 --- a/test/cmake_subdir_test/CMakeLists.txt +++ b/test/cmake_subdir_test/CMakeLists.txt @@ -2,7 +2,7 @@ # 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.5) +cmake_minimum_required(VERSION 3.5...3.16) project(cmake_subdir_test LANGUAGES CXX) @@ -20,7 +20,6 @@ endfunction() boost_add_subdir(config) boost_add_subdir(core) -boost_add_subdir(predef) boost_add_subdir(static_assert) boost_add_subdir(type_traits) diff --git a/test/conversion_test.cpp b/test/conversion_test.cpp index 1399df3..b184343 100644 --- a/test/conversion_test.cpp +++ b/test/conversion_test.cpp @@ -10,7 +10,6 @@ #include #include -#include #include #include #include @@ -376,4 +375,17 @@ int cpp_main(int, char * []) return ::boost::report_errors(); } +int main( int argc, char* argv[] ) +{ + try + { + return cpp_main( argc, argv ); + } + catch( std::exception const & x ) + { + BOOST_ERROR( x.what() ); + return boost::report_errors(); + } +} + #include diff --git a/test/deprecated_test.cpp b/test/deprecated_test.cpp index 3fc0a62..5e6e2a8 100644 --- a/test/deprecated_test.cpp +++ b/test/deprecated_test.cpp @@ -13,7 +13,6 @@ #define BOOST_ENDIAN_DEPRECATED_NAMES #include -#include #include #include #include @@ -181,4 +180,17 @@ int cpp_main(int, char *[]) return ::boost::report_errors(); } +int main( int argc, char* argv[] ) +{ + try + { + return cpp_main( argc, argv ); + } + catch( std::exception const & x ) + { + BOOST_ERROR( x.what() ); + return boost::report_errors(); + } +} + #include diff --git a/test/endian_operations_test.cpp b/test/endian_operations_test.cpp index a8084fe..8e16390 100644 --- a/test/endian_operations_test.cpp +++ b/test/endian_operations_test.cpp @@ -29,7 +29,6 @@ #include #include #include -#include #include #include #include @@ -489,3 +488,16 @@ int cpp_main(int, char * []) return boost::report_errors(); } + +int main( int argc, char* argv[] ) +{ + try + { + return cpp_main( argc, argv ); + } + catch( std::exception const & x ) + { + BOOST_ERROR( x.what() ); + return boost::report_errors(); + } +} diff --git a/test/endian_test.cpp b/test/endian_test.cpp index c267cfc..6aa8652 100644 --- a/test/endian_test.cpp +++ b/test/endian_test.cpp @@ -20,7 +20,6 @@ #include #include -#include #include #include @@ -838,3 +837,16 @@ int cpp_main( int argc, char * argv[] ) return err_count ? 1 : 0; } // main + +int main( int argc, char* argv[] ) +{ + try + { + return cpp_main( argc, argv ); + } + catch( std::exception const & x ) + { + std::cout << "Exception: " << x.what() << std::endl; + return 1; + } +}