Skip to content

Commit

Permalink
Added support for running tests in CMake.
Browse files Browse the repository at this point in the history
Related to #71.
  • Loading branch information
Lastique committed Oct 19, 2024
1 parent d5914e3 commit 5a04505
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 60 deletions.
37 changes: 21 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ jobs:

- name: CMake tests
cmake_tests: 1
os: ubuntu-20.04
os: ubuntu-22.04

timeout-minutes: 30
runs-on: ${{matrix.os}}
Expand Down Expand Up @@ -710,7 +710,7 @@ jobs:
./b2 "${B2_ARGS[@]}" "address-model=32" "cxxstd=${{matrix.cxxstd32}}" "libs/$LIBRARY/test"
fi
- name: Run CMake tests
- name: Build CMake tests
if: matrix.cmake_tests
run: |
if [ -n "${{matrix.macosx_version_min}}" ]
Expand All @@ -719,12 +719,15 @@ jobs:
fi
cd boost-root
mkdir __build_static__ && cd __build_static__
cmake ../libs/$LIBRARY/test/test_cmake
cmake --build . --target boost_${LIBRARY}_cmake_self_test -j $BUILD_JOBS
cd ..
mkdir __build_shared__ && cd __build_shared__
cmake -DBUILD_SHARED_LIBS=On ../libs/$LIBRARY/test/test_cmake
cmake --build . --target boost_${LIBRARY}_cmake_self_test -j $BUILD_JOBS
cmake -DBOOST_INCLUDE_LIBRARIES=$LIBRARY -DBUILD_TESTING=ON ..
cmake --build . --target tests -j $BUILD_JOBS
- name: Run CMake tests
if: matrix.cmake_tests
run: |
cd boost-root
cd __build_static__
ctest --output-on-failure --no-tests=error -j $BUILD_JOBS
windows:
defaults:
Expand Down Expand Up @@ -828,16 +831,18 @@ jobs:
b2 %B2_ARGS% cxxstd=${{matrix.cxxstd32}} address-model=32 libs/%LIBRARY%/test
)
- name: Run CMake tests
- name: Build CMake tests
if: matrix.cmake_tests
run: |
cd boost-root
mkdir __build_static__
cd __build_static__
cmake ../libs/%LIBRARY%/test/test_cmake
cmake --build . --target boost_%LIBRARY%_cmake_self_test -j %NUMBER_OF_PROCESSORS%
cd ..
mkdir __build_shared__
cd __build_shared__
cmake -DBUILD_SHARED_LIBS=On ../libs/%LIBRARY%/test/test_cmake
cmake --build . --target boost_%LIBRARY%_cmake_self_test -j %NUMBER_OF_PROCESSORS%
cmake -DBOOST_INCLUDE_LIBRARIES=%LIBRARY% -DBUILD_TESTING=ON ..
cmake --build . --config Release --target tests -j %NUMBER_OF_PROCESSORS%
- name: Run CMake tests
if: matrix.cmake_tests
run: |
cd boost-root
cd __build_static__
ctest -C Release --output-on-failure --no-tests=error -j %NUMBER_OF_PROCESSORS%
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright 2018 Mike Dev
# Copyright 2019 Peter Dimov
# Copyright 2020-2023 Andrey Semashev
# Copyright 2020-2024 Andrey Semashev
#
# Distributed under the Boost Software License, Version 1.0.
# See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt

Expand Down Expand Up @@ -138,3 +139,7 @@ endif()
if (BOOST_ATOMIC_COMPILER_HAS_SSE41)
target_compile_definitions(boost_atomic PRIVATE BOOST_ATOMIC_USE_SSE41)
endif()

if (BUILD_TESTING AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt")
add_subdirectory(test)
endif()
76 changes: 76 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Copyright 2024 Andrey Semashev
#
# 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(BoostTest OPTIONAL RESULT_VARIABLE HAVE_BOOST_TEST)

if (NOT HAVE_BOOST_TEST)
return()
endif()

include_directories(${CMAKE_CURRENT_SOURCE_DIR})

set(BOOST_TEST_COMPILE_FEATURES
cxx_lambdas
cxx_static_assert
cxx_deleted_functions
cxx_defaulted_functions
)

set(BOOST_TEST_LINK_LIBRARIES
Boost::atomic
Boost::config
Boost::core
Boost::type_traits
)

if (WIN32)
set(BOOST_TEST_COMPILE_DEFINITIONS
"_CRT_SECURE_NO_WARNINGS"
"_CRT_SECURE_NO_DEPRECATE"
"BOOST_USE_WINDOWS_H"
)
list(APPEND BOOST_TEST_LINK_LIBRARIES
Boost::winapi
)
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
list(APPEND BOOST_TEST_LINK_LIBRARIES
kernel32
)
endif()
endif()

if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(BOOST_TEST_COMPILE_OPTIONS "-Wall" "-Wextra" "-Werror")
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(BOOST_TEST_COMPILE_OPTIONS "/W4" "/WX")
endif()

boost_test(TYPE run SOURCES atomic_api.cpp)
boost_test(TYPE run SOURCES atomic_ref_api.cpp)
boost_test(TYPE run SOURCES atomic_api.cpp COMPILE_DEFINITIONS BOOST_ATOMIC_FORCE_FALLBACK NAME fallback_atomic_api)
boost_test(TYPE run SOURCES atomic_ref_api.cpp COMPILE_DEFINITIONS BOOST_ATOMIC_FORCE_FALLBACK NAME fallback_atomic_ref_api)
boost_test(TYPE run SOURCES wait_api.cpp)
boost_test(TYPE run SOURCES wait_ref_api.cpp)
boost_test(TYPE run SOURCES wait_api.cpp COMPILE_DEFINITIONS BOOST_ATOMIC_FORCE_FALLBACK NAME fallback_wait_api)
boost_test(TYPE run SOURCES wait_ref_api.cpp COMPILE_DEFINITIONS BOOST_ATOMIC_FORCE_FALLBACK NAME fallback_wait_ref_api)
boost_test(TYPE run SOURCES wait_fuzz.cpp)
boost_test(TYPE run SOURCES wait_fuzz.cpp COMPILE_DEFINITIONS BOOST_ATOMIC_FORCE_FALLBACK NAME fallback_wait_fuzz)
boost_test(TYPE run SOURCES ipc_atomic_api.cpp)
boost_test(TYPE run SOURCES ipc_atomic_ref_api.cpp)
boost_test(TYPE run SOURCES ipc_wait_api.cpp)
boost_test(TYPE run SOURCES ipc_wait_ref_api.cpp)
boost_test(TYPE run SOURCES atomicity.cpp)
boost_test(TYPE run SOURCES atomicity_ref.cpp)
boost_test(TYPE run SOURCES ordering.cpp)
boost_test(TYPE run SOURCES ordering_ref.cpp)
boost_test(TYPE run SOURCES lockfree.cpp)

unset(BOOST_TEST_COMPILE_OPTIONS)

boost_test(TYPE compile-fail SOURCES cf_arith_void_ptr.cpp)
boost_test(TYPE compile-fail SOURCES cf_arith_func_ptr.cpp)
boost_test(TYPE compile-fail SOURCES cf_arith_mem_ptr.cpp)

boost_test(TYPE compile SOURCES c_implicit_ctor.cpp)
21 changes: 0 additions & 21 deletions test/test_cmake/CMakeLists.txt

This file was deleted.

22 changes: 0 additions & 22 deletions test/test_cmake/main.cpp

This file was deleted.

0 comments on commit 5a04505

Please sign in to comment.