Skip to content

Commit

Permalink
CMake subdir tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alandefreitas committed Apr 17, 2022
1 parent ed82967 commit 982759c
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 9 deletions.
32 changes: 24 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -62,6 +68,7 @@ jobs:
sudocmd: "sudo",
artifact_name: "Linux",
cores: 2,
install_dir: "/usr/local/"
}
- {
name: "MacOSX/10.15/Static/X64/Release",
Expand All @@ -71,6 +78,7 @@ jobs:
sudocmd: "sudo",
artifact_name: "MacOSX",
cores: 4,
install_dir: "/usr/local/"
}
steps:
- uses: actions/checkout@v2
Expand All @@ -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 }}
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
80 changes: 80 additions & 0 deletions test/cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#
# Copyright (c) 2022 alandefreitas ([email protected])
#
# 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 "<CONFIG>" "${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 $<CONFIG>)
14 changes: 14 additions & 0 deletions test/cmake/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// Copyright (c) 2022 alandefreitas ([email protected])
//
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
//

#include <small/vector.hpp>

int
main() {
small::vector<int> v(5);
return (!v.empty()) ? 0 : 1;
}

0 comments on commit 982759c

Please sign in to comment.