diff --git a/.github/workflows/ci_tests.yml b/.github/workflows/ci_tests.yml index 8fe6056..631de18 100644 --- a/.github/workflows/ci_tests.yml +++ b/.github/workflows/ci_tests.yml @@ -104,7 +104,7 @@ jobs: - name: Build Release run: | cmake --build build --config Release --verbose - # TODO: cmake --build build --config Release --target all_verify_interface_header_sets + cmake --build build --config Release --target all_verify_interface_header_sets cmake --install build --config Release --prefix /tmp/beman.inplace_vector find /tmp/beman.inplace_vector -type f - name: Test Release @@ -112,7 +112,7 @@ jobs: - name: Build Debug run: | cmake --build build --config Debug --verbose - # TODO: cmake --build build --config Debug --target all_verify_interface_header_sets + cmake --build build --config Debug --target all_verify_interface_header_sets cmake --install build --config Debug --prefix /tmp/beman.inplace_vector find /tmp/beman.inplace_vector -type f - name: Test Debug diff --git a/.gitignore b/.gitignore index 172d4ef..65d887b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ /build /out CMakeUserPresets.json +CMakeCache.txt +CMakeFiles/ diff --git a/CMakeLists.txt b/CMakeLists.txt index e7d6744..331621f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,9 @@ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception # cmake-format: on -cmake_minimum_required(VERSION 3.23) +set(CMAKE_SKIP_TEST_ALL_DEPENDENCY FALSE) + +cmake_minimum_required(VERSION 3.25...3.31) project( beman.inplace_vector @@ -13,6 +15,10 @@ project( LANGUAGES CXX ) +if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR}) + message(FATAL_ERROR "In-source builds are not allowed!") +endif() + # [CMAKE.SKIP_EXAMPLES] option( BEMAN_EXEMPLAR_BUILD_EXAMPLES @@ -27,41 +33,90 @@ option( ${PROJECT_IS_TOP_LEVEL} ) +set(CPACK_GENERATOR TGZ) + include(GNUInstallDirs) +include(CMakePackageConfigHelpers) +include(CPack) -add_library(beman.inplace_vector INTERFACE) +add_library(beman_inplace_vector INTERFACE) # [CMAKE.LIBRARY_ALIAS] -add_library(beman::inplace_vector ALIAS beman.inplace_vector) +add_library(beman::beman_inplace_vector ALIAS beman_inplace_vector) -target_include_directories( - beman.inplace_vector - INTERFACE - $ - $ +target_sources( + beman_inplace_vector + PUBLIC + FILE_SET inplace_vector_public_headers + TYPE HEADERS + BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include + FILES + "${CMAKE_CURRENT_SOURCE_DIR}/include/beman/inplace_vector/inplace_vector.hpp" ) +set_target_properties( + beman_inplace_vector + PROPERTIES VERIFY_INTERFACE_HEADER_SETS ON +) +target_compile_features(beman_inplace_vector INTERFACE cxx_std_23) + +# export cmake config package +set(TARGET_NAME inplace_vector) +set(TARGET_NAMESPACE beman) +set(TARGET_ALIAS ${TARGET_NAMESPACE}::${TARGET_NAME}) +set(TARGET_PREFIX ${TARGET_NAMESPACE}.${TARGET_NAME}) # -> PROJECT_NAME? +set(TARGET_PACKAGE_NAME ${TARGET_NAME}-config) +set(TARGETS_EXPORT_NAME ${TARGET_NAME}-targets) +set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/${TARGET_NAME}) # Install the InplaceVector library to the appropriate destination install( - TARGETS beman.inplace_vector + TARGETS beman_inplace_vector EXPORT ${TARGETS_EXPORT_NAME} - DESTINATION - ${CMAKE_INSTALL_LIBDIR} + FILE_SET inplace_vector_public_headers +) + +write_basic_package_version_file( + ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_PACKAGE_NAME}-version.cmake + VERSION ${PROJECT_VERSION} + COMPATIBILITY AnyNewerVersion +) + +configure_package_config_file( + cmake/config.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_PACKAGE_NAME}.cmake + INSTALL_DESTINATION ${INSTALL_CONFIGDIR} ) -# Install the header files to the appropriate destination install( - DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${CMAKE_PROJECT_NAME} - FILES_MATCHING - PATTERN - "${CMAKE_CURRENT_SOURCE_DIR}/include/beman/inplace_vector/inplace_vector.hpp" + FILES + ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_PACKAGE_NAME}.cmake + ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_PACKAGE_NAME}-version.cmake + DESTINATION ${INSTALL_CONFIGDIR} +) + +install( + EXPORT ${TARGETS_EXPORT_NAME} + FILE ${TARGETS_EXPORT_NAME}.cmake + DESTINATION "${INSTALL_CONFIGDIR}" + NAMESPACE ${TARGET_NAMESPACE}:: ) if(BEMAN_INPLACE_VECTOR_BUILD_TESTS) - include(CTest) + enable_testing() add_subdirectory(tests/beman/inplace_vector) endif() if(BEMAN_EXEMPLAR_BUILD_EXAMPLES) add_subdirectory(examples) endif() + +# Coverage +configure_file(cmake/gcovr.cfg.in gcovr.cfg @ONLY) + +add_custom_target( + process_coverage + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + DEPENDS test + COMMENT "Running gcovr to process coverage results" + COMMAND mkdir -p coverage + COMMAND gcovr --config gcovr.cfg . +) diff --git a/README.md b/README.md index f1936fd..1ed79b6 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ TODO: tested platforms. ```text # Configure build -$ cmake -S . -B build -DCMAKE_CXX_STANDARD=20 +$ cmake -S . -B build -DCMAKE_CXX_STANDARD=23 -- The CXX compiler identification is GNU 11.4.0 -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done diff --git a/cmake/config.cmake.in b/cmake/config.cmake.in new file mode 100644 index 0000000..e6ed3e2 --- /dev/null +++ b/cmake/config.cmake.in @@ -0,0 +1,7 @@ +# cmake/Config.cmake.in -*-makefile-*- +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/@TARGETS_EXPORT_NAME@.cmake") +check_required_components("@TARGET_NAME@") diff --git a/cmake/gcovr.cfg.in b/cmake/gcovr.cfg.in new file mode 100644 index 0000000..3097f1e --- /dev/null +++ b/cmake/gcovr.cfg.in @@ -0,0 +1,13 @@ +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception. + +root = @CMAKE_SOURCE_DIR@ +cobertura = @CMAKE_BINARY_DIR@/coverage/cobertura.xml +sonarqube = @CMAKE_BINARY_DIR@/coverage/sonarqube.xml +html-details = @CMAKE_BINARY_DIR@/coverage/coverage.html +# XXX gcov-executable = @GCOV_EXECUTABLE@ +gcov-parallel = yes +html-theme = blue +html-self-contained = yes +print-summary = yes +filter = .*/beman/inplace_vector/.* +exclude = .*\.t\.cpp diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 496bc08..bbabb25 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,8 +1,17 @@ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +cmake_minimum_required(VERSION 3.25...3.31) + +project(beman_inplace_vector_example LANGUAGES CXX) + +if(PROJECT_IS_TOP_LEVEL) + find_package(inplace_vector 1.0.0 EXACT REQUIRED) + enable_testing() +endif() + set(ALL_EXAMPLES fibonacci) -message("Examples to be built: ${ALL_EXAMPLES}") +message(STATUS "Examples to be built: ${ALL_EXAMPLES}") foreach(example ${ALL_EXAMPLES}) add_executable(beman.inplace_vector.examples.${example}) @@ -12,6 +21,7 @@ foreach(example ${ALL_EXAMPLES}) ) target_link_libraries( beman.inplace_vector.examples.${example} - beman.inplace_vector + beman::beman_inplace_vector ) + add_test(NAME ${example} COMMAND beman.inplace_vector.examples.${example}) endforeach() diff --git a/tests/beman/inplace_vector/CMakeLists.txt b/tests/beman/inplace_vector/CMakeLists.txt index 9b10181..f3d9a90 100644 --- a/tests/beman/inplace_vector/CMakeLists.txt +++ b/tests/beman/inplace_vector/CMakeLists.txt @@ -5,18 +5,43 @@ # Tests add_executable(beman.inplace_vector.test inplace_vector.test.cpp) - -target_link_libraries(beman.inplace_vector.test PRIVATE beman.inplace_vector) - +target_link_libraries( + beman.inplace_vector.test + PRIVATE beman::beman_inplace_vector +) add_test(NAME beman.inplace_vector.test COMMAND beman.inplace_vector.test) # Migrated test from original implementation add_executable(beman.inplace_vector.ref-test ref_impl.test.cpp) target_link_libraries( beman.inplace_vector.ref-test - PRIVATE beman.inplace_vector + PRIVATE beman::beman_inplace_vector ) add_test( NAME beman.inplace_vector.ref-test COMMAND beman.inplace_vector.ref-test ) + +# test if the targets are findable from the build directory +# NOTE: For an INTERFACE library and multi config generators, we may always use +# the -C Debug config type instead of $ to prevent problems! CK +if(CMAKE_BUILD_TYPE STREQUAL Debug) + if(NOT DEFINED CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 23) + endif() + if(NOT DEFINED CMAKE_PREFIX_PATH) + set(CMAKE_PREFIX_PATH ${CMAKE_INSTALL_PREFIX}) + endif() + add_test( + NAME find-package-test + COMMAND + ${CMAKE_CTEST_COMMAND} --verbose --output-on-failure -C Debug + --build-and-test "${PROJECT_SOURCE_DIR}/examples" + "${CMAKE_CURRENT_BINARY_DIR}/find-package-test" --build-generator + ${CMAKE_GENERATOR} --build-makeprogram ${CMAKE_MAKE_PROGRAM} + --build-options "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" + "-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}" + "-DCMAKE_BUILD_TYPE=Debug" + "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" + ) +endif()