From 982759c1c84d0abafde67dfad835bb84e6cc0dd1 Mon Sep 17 00:00:00 2001 From: alandefreitas Date: Sun, 17 Apr 2022 18:07:08 -0300 Subject: [PATCH] CMake subdir tests --- .github/workflows/build.yml | 32 +++++++++++---- CMakeLists.txt | 2 +- test/cmake/CMakeLists.txt | 80 +++++++++++++++++++++++++++++++++++++ test/cmake/main.cpp | 14 +++++++ 4 files changed, 119 insertions(+), 9 deletions(-) create mode 100644 test/cmake/CMakeLists.txt create mode 100644 test/cmake/main.cpp diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d00eb4f..2f5d419 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -27,6 +27,10 @@ on: - '**/CMakeLists.txt' - '.github/workflows/build.yml' +concurrency: + group: ${{format('{0}:{1}', github.repository, github.ref)}} + cancel-in-progress: true + jobs: Build: name: ${{ matrix.config.name }} @@ -44,6 +48,7 @@ jobs: sudocmd: "", artifact_name: "Windows x86", cores: 2, + install_dir: "C:/Program Files (x86)/small" } - { name: "Windows-MSVC/2019/Static/X64/Release", @@ -53,6 +58,7 @@ jobs: sudocmd: "", artifact_name: "Windows x64", cores: 2, + install_dir: "C:/Program Files/small" } - { name: "Ubuntu/20.04/Static/X64/Release", @@ -62,6 +68,7 @@ jobs: sudocmd: "sudo", artifact_name: "Linux", cores: 2, + install_dir: "/usr/local/" } - { name: "MacOSX/10.15/Static/X64/Release", @@ -71,6 +78,7 @@ jobs: sudocmd: "sudo", artifact_name: "MacOSX", cores: 4, + install_dir: "/usr/local/" } steps: - uses: actions/checkout@v2 @@ -79,7 +87,7 @@ jobs: - name: Configure working-directory: ./build run: | - cmake .. ${{ matrix.config.cmake_extra_args }} -DCMAKE_BUILD_TYPE=${{ matrix.config.config }} -DSMALL_DEVELOPER_MODE=ON + cmake .. ${{ matrix.config.cmake_extra_args }} -D CMAKE_BUILD_TYPE=${{ matrix.config.config }} -DSMALL_DEVELOPER_MODE=ON - name: Build working-directory: ./build run: cmake --build . --parallel ${{ matrix.config.cores }} --config ${{ matrix.config.config }} @@ -88,15 +96,23 @@ jobs: run: ctest --parallel ${{ matrix.config.cores }} -C ${{ matrix.config.config }} --verbose - name: Install working-directory: ./build - run: ${{ matrix.config.sudocmd }} cmake --install . - - name: Integration Test - working-directory: ./test/integration + run: ${{ matrix.config.sudocmd }} cmake --install . --prefix "${{ matrix.config.install_dir }}" + - name: CMake Subdir Test + working-directory: ./test/cmake + run: | + mkdir build_with_subdir + cd build_with_subdir + cmake .. ${{ matrix.config.cmake_extra_args }} -D CMAKE_BUILD_TYPE=${{ matrix.config.config }} + cmake --build . --parallel ${{ matrix.config.cores }} --config ${{ matrix.config.config }} + ctest -C ${{ matrix.config.config }} --verbose + - name: CMake Find Package Test + working-directory: ./test/cmake run: | - mkdir build - cd build - cmake .. ${{ matrix.config.cmake_extra_args }} -DCMAKE_BUILD_TYPE=${{ matrix.config.config }} + mkdir build_with_package + cd build_with_package + cmake .. ${{ matrix.config.cmake_extra_args }} -D CMAKE_BUILD_TYPE=${{ matrix.config.config }} -D BOOST_CI_INSTALL_TEST=ON -D Small_DIR="${{ matrix.config.install_dir }}" cmake --build . --parallel ${{ matrix.config.cores }} --config ${{ matrix.config.config }} - continue-on-error: true + ctest -C ${{ matrix.config.config }} --verbose - name: Create packages working-directory: ./build run: ${{ matrix.config.sudocmd }} cpack diff --git a/CMakeLists.txt b/CMakeLists.txt index 7d475d0..b272b11 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,7 +54,7 @@ if (SMALL_BUILD_INSTALLER) ) # Install headers - install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/small + install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/small DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} FILES_MATCHING PATTERN "*.hpp" ) diff --git a/test/cmake/CMakeLists.txt b/test/cmake/CMakeLists.txt new file mode 100644 index 0000000..8baa563 --- /dev/null +++ b/test/cmake/CMakeLists.txt @@ -0,0 +1,80 @@ +# +# Copyright (c) 2022 alandefreitas (alandefreitas@gmail.com) +# +# Distributed under the Boost Software License, Version 1.0. +# https://www.boost.org/LICENSE_1_0.txt +# + +####################################################### +### Project properties ### +####################################################### +cmake_minimum_required(VERSION 3.15) + +project(cmake_subdir_test LANGUAGES CXX) + +####################################################### +### Integration ### +####################################################### +if (BOOST_CI_INSTALL_TEST) + find_package(small REQUIRED) +else () + set(SMALL_DIR ../..) + set(SMALL_BINARY_DIR alandefreitas/small) + add_subdirectory(${SMALL_DIR} ${SMALL_BINARY_DIR}) +endif () + +####################################################### +### Print small target properties ### +####################################################### +# This is useful output for CI +if(NOT CMAKE_PROPERTY_LIST) + execute_process(COMMAND cmake --help-property-list OUTPUT_VARIABLE CMAKE_PROPERTY_LIST) + + # Convert command output into a CMake list + string(REGEX REPLACE ";" "\\\\;" CMAKE_PROPERTY_LIST "${CMAKE_PROPERTY_LIST}") + string(REGEX REPLACE "\n" ";" CMAKE_PROPERTY_LIST "${CMAKE_PROPERTY_LIST}") +endif() + +function(print_properties) + message("CMAKE_PROPERTY_LIST = ${CMAKE_PROPERTY_LIST}") +endfunction() + +function(print_target_properties target) + if(NOT TARGET ${target}) + message(STATUS "There is no target named '${target}'") + return() + endif() + + foreach(property ${CMAKE_PROPERTY_LIST}) + string(REPLACE "" "${CMAKE_BUILD_TYPE}" property ${property}) + + # Fix https://stackoverflow.com/questions/32197663/how-can-i-remove-the-the-location-property-may-not-be-read-from-target-error-i + if(property STREQUAL "LOCATION" OR property MATCHES "^LOCATION_" OR property MATCHES "_LOCATION$") + continue() + endif() + + get_property(was_set TARGET ${target} PROPERTY ${property} SET) + if(was_set) + get_target_property(value ${target} ${property}) + message("${target} ${property} = ${value}") + endif() + endforeach() +endfunction() + +print_target_properties(small::small) + +####################################################### +### Target ### +####################################################### +add_executable(main main.cpp) +target_link_libraries(main small::small) +if (MSVC) + target_compile_options(main PRIVATE /EHsc) +endif() + +####################################################### +### Tests ### +####################################################### +enable_testing() +add_test(NAME main COMMAND main) +add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C $) \ No newline at end of file diff --git a/test/cmake/main.cpp b/test/cmake/main.cpp new file mode 100644 index 0000000..5282725 --- /dev/null +++ b/test/cmake/main.cpp @@ -0,0 +1,14 @@ +// +// Copyright (c) 2022 alandefreitas (alandefreitas@gmail.com) +// +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt +// + +#include + +int +main() { + small::vector v(5); + return (!v.empty()) ? 0 : 1; +} \ No newline at end of file