diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index af73b5d..842b229 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,19 +29,10 @@ jobs: uses: lukka/get-cmake@latest with: cmakeVersion: 3.17.2 - - run: cmake -S. -B build -D VUL_WERROR=ON -D BUILD_TESTS=ON -D CMAKE_BUILD_TYPE=${{matrix.config}} -D UPDATE_DEPS=ON -D UPDATE_DEPS_DIR=ext/ + - run: cmake -S. -B build -D VUL_WERROR=ON -D BUILD_TESTS=ON -D CMAKE_BUILD_TYPE=${{matrix.config}} -D UPDATE_DEPS=ON - run: cmake --build build --config ${{matrix.config}} --verbose - - working-directory: ./build - run: ctest -C ${{matrix.config}} --output-on-failure - - run: cmake --install build --prefix ${{ github.workspace }}/install --config ${{matrix.config}} - - name: Test find_package support - run: | - cmake -S tests/find_package -B tests/find_package/build -D CMAKE_PREFIX_PATH="${{ github.workspace }}/install;${{ github.workspace }}/ext/Vulkan-Headers/build/install" -D CMAKE_BUILD_TYPE=${{matrix.config}} - cmake --build tests/find_package/build --config ${{matrix.config}} --verbose - - name: Test add_subdirectory support - run: | - cmake -S tests/add_subdirectory -B tests/add_subdirectory/build -D CMAKE_BUILD_TYPE=${{matrix.config}} -D VULKAN_HEADER_SOURCE_DIR=${{ github.workspace }}/ext/Vulkan-Headers/ - cmake --build tests/add_subdirectory/build --config ${{matrix.config}} --verbose + - run: ctest -C ${{matrix.config}} --output-on-failure + working-directory: build/ android: runs-on: ubuntu-22.04 diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c039f5d..3bf1283 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -37,6 +37,32 @@ target_link_libraries(vul_tests PRIVATE Vulkan::CompilerConfiguration ) +# Test add_subdirectory suppport +add_test(NAME integration.add_subdirectory + COMMAND ${CMAKE_CTEST_COMMAND} + --build-and-test ${CMAKE_CURRENT_LIST_DIR}/integration + ${CMAKE_CURRENT_BINARY_DIR}/add_subdirectory + --build-generator ${CMAKE_GENERATOR} + --build-options -DFIND_PACKAGE_TESTING=OFF -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH} +) + +set(test_install_dir "${CMAKE_CURRENT_BINARY_DIR}/install") +add_test(NAME integration.install + COMMAND ${CMAKE_COMMAND} --install ${PROJECT_BINARY_DIR} --prefix ${test_install_dir} --config $ +) + +# Test find_package suppport +add_test(NAME integration.find_package + COMMAND ${CMAKE_CTEST_COMMAND} + --build-and-test ${CMAKE_CURRENT_LIST_DIR}/integration + ${CMAKE_CURRENT_BINARY_DIR}/find_package + --build-generator ${CMAKE_GENERATOR} + --build-options -DFIND_PACKAGE_TESTING=ON "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH};${test_install_dir}" +) + +# Installing comes before testing +set_tests_properties(integration.find_package PROPERTIES DEPENDS integration.install) + if (CMAKE_CROSSCOMPILING) return() endif() diff --git a/tests/find_package/CMakeLists.txt b/tests/find_package/CMakeLists.txt deleted file mode 100644 index a255389..0000000 --- a/tests/find_package/CMakeLists.txt +++ /dev/null @@ -1,59 +0,0 @@ -# Copyright 2023 The Khronos Group Inc. -# Copyright 2023 Valve Corporation -# Copyright 2023 LunarG, Inc. -# -# SPDX-License-Identifier: Apache-2.0 -cmake_minimum_required(VERSION 3.17) - -project(TEST_FIND_PACKAGE LANGUAGES C) - -add_library(find_package_example STATIC) - -# Test c99 support as well as find_package support -target_compile_features(find_package_example PRIVATE c_std_99) - -target_sources(find_package_example PRIVATE - ${CMAKE_CURRENT_LIST_DIR}/../add_subdirectory/vk_layer_settings.c - ${CMAKE_CURRENT_LIST_DIR}/../add_subdirectory/vk_enum_string_helper.c - ${CMAKE_CURRENT_LIST_DIR}/../add_subdirectory/vk_dispatch_table.c - ${CMAKE_CURRENT_LIST_DIR}/../add_subdirectory/vk_format_utils.c -) - -# NOTE: Because VulkanHeaders is a PUBLIC dependency it needs to be found prior to VulkanUtilityLibraries -find_package(VulkanHeaders REQUIRED CONFIG) - -find_package(VulkanUtilityLibraries REQUIRED CONFIG) - -if (NOT TARGET Vulkan::LayerSettings) - message(FATAL_ERROR "Vulkan::LayerSettings target not defined!") -endif() - -if (NOT TARGET Vulkan::UtilityHeaders) - message(FATAL_ERROR "Vulkan::UtilityHeaders target not defined!") -endif() - -target_link_libraries(find_package_example PRIVATE - Vulkan::LayerSettings - Vulkan::UtilityHeaders -) - -# NOTE: Because Vulkan::Headers header files are exposed in the public facing interface -# we must expose this library to users. -get_target_property(property Vulkan::LayerSettings INTERFACE_LINK_LIBRARIES) -if (NOT property MATCHES "Vulkan::Headers") - message(FATAL_ERROR "Vulkan::Headers not linked properly!") -endif() -get_target_property(property Vulkan::UtilityHeaders INTERFACE_LINK_LIBRARIES) -if (NOT property MATCHES "Vulkan::Headers") - message(FATAL_ERROR "Vulkan::Headers not linked properly!") -endif() - -# Prevent regression of https://github.com/KhronosGroup/Vulkan-Utility-Libraries/issues/103 -get_target_property(property Vulkan::LayerSettings INTERFACE_COMPILE_OPTIONS) -if (NOT property STREQUAL "property-NOTFOUND") - message(FATAL_ERROR "Vulkan::LayerSettings shouldn't export compile options! ${property}") -endif() -get_target_property(property Vulkan::UtilityHeaders INTERFACE_COMPILE_OPTIONS) -if (NOT property STREQUAL "property-NOTFOUND") - message(FATAL_ERROR "Vulkan::UtilityHeaders shouldn't export compile options! ${property}") -endif() diff --git a/tests/add_subdirectory/CMakeLists.txt b/tests/integration/CMakeLists.txt similarity index 57% rename from tests/add_subdirectory/CMakeLists.txt rename to tests/integration/CMakeLists.txt index ecb48b1..2da2eef 100644 --- a/tests/add_subdirectory/CMakeLists.txt +++ b/tests/integration/CMakeLists.txt @@ -5,15 +5,43 @@ # SPDX-License-Identifier: Apache-2.0 cmake_minimum_required(VERSION 3.17) -project(TEST_ADD_SUBDIRECTORY LANGUAGES C) +project(INTEGRATION LANGUAGES C) -if (NOT DEFINED VULKAN_HEADER_SOURCE_DIR) - message(FATAL_ERROR "VULKAN_HEADER_SOURCE_DIR not defined!") +add_library(foobar STATIC) + +target_compile_features(foobar PRIVATE c_std_99) + +target_sources(foobar PRIVATE + vk_dispatch_table.c + vk_enum_string_helper.c + vk_layer_settings.c + vk_format_utils.c + vk_format_utils_2.c # Need two translation units to test if header file behaves correctly. +) + +# NOTE: Because VulkanHeaders is a PUBLIC dependency it needs to be found prior to VulkanUtilityLibraries +find_package(VulkanHeaders REQUIRED CONFIG) + +if (FIND_PACKAGE_TESTING) + find_package(VulkanUtilityLibraries REQUIRED CONFIG) +else() + add_subdirectory(${PROJECT_SOURCE_DIR}/../../ ${PROJECT_BINARY_DIR}/vul) endif() -add_subdirectory(${VULKAN_HEADER_SOURCE_DIR} ${PROJECT_BINARY_DIR}/headers) +# The intent is ensuring we don't accidentally change the names of these +# targets. Since it would break downstream users. +if (NOT TARGET Vulkan::LayerSettings) + message(FATAL_ERROR "Vulkan::LayerSettings target not defined!") +endif() -add_subdirectory(${PROJECT_SOURCE_DIR}/../../ ${PROJECT_BINARY_DIR}/vul) +if (NOT TARGET Vulkan::UtilityHeaders) + message(FATAL_ERROR "Vulkan::UtilityHeaders target not defined!") +endif() + +target_link_libraries(foobar PRIVATE + Vulkan::LayerSettings + Vulkan::UtilityHeaders +) get_filename_component(VUL_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/../../include/" ABSOLUTE) @@ -53,29 +81,23 @@ foreach(header IN LISTS public_headers) endif() endforeach() -# The intent is ensuring we don't accidentally change the names of these -# targets. Since it would break downstream users. -if (NOT TARGET Vulkan::LayerSettings) - message(FATAL_ERROR "Vulkan::LayerSettings target not defined!") +# NOTE: Because Vulkan::Headers header files are exposed in the public facing interface +# we must expose this library to users. +get_target_property(property Vulkan::LayerSettings INTERFACE_LINK_LIBRARIES) +if (NOT property MATCHES "Vulkan::Headers") + message(FATAL_ERROR "Vulkan::Headers not linked properly!") endif() -if (NOT TARGET Vulkan::UtilityHeaders) - message(FATAL_ERROR "Vulkan::UtilityHeaders target not defined!") +get_target_property(property Vulkan::UtilityHeaders INTERFACE_LINK_LIBRARIES) +if (NOT property MATCHES "Vulkan::Headers") + message(FATAL_ERROR "Vulkan::Headers not linked properly!") endif() -add_library(add_subdirectory_example STATIC) - -# Test c99 support -target_compile_features(add_subdirectory_example PRIVATE c_std_99) - -target_sources(add_subdirectory_example PRIVATE - vk_dispatch_table.c - vk_enum_string_helper.c - vk_layer_settings.c - vk_format_utils.c - vk_format_utils_2.c # Need two translation units to test if header file behaves correctly. -) - -target_link_libraries(add_subdirectory_example PRIVATE - Vulkan::LayerSettings - Vulkan::UtilityHeaders -) +# Prevent regression of https://github.com/KhronosGroup/Vulkan-Utility-Libraries/issues/103 +get_target_property(property Vulkan::LayerSettings INTERFACE_COMPILE_OPTIONS) +if (NOT property STREQUAL "property-NOTFOUND") + message(FATAL_ERROR "Vulkan::LayerSettings shouldn't export compile options! ${property}") +endif() +get_target_property(property Vulkan::UtilityHeaders INTERFACE_COMPILE_OPTIONS) +if (NOT property STREQUAL "property-NOTFOUND") + message(FATAL_ERROR "Vulkan::UtilityHeaders shouldn't export compile options! ${property}") +endif() diff --git a/tests/add_subdirectory/vk_dispatch_table.c b/tests/integration/vk_dispatch_table.c similarity index 100% rename from tests/add_subdirectory/vk_dispatch_table.c rename to tests/integration/vk_dispatch_table.c diff --git a/tests/add_subdirectory/vk_enum_string_helper.c b/tests/integration/vk_enum_string_helper.c similarity index 100% rename from tests/add_subdirectory/vk_enum_string_helper.c rename to tests/integration/vk_enum_string_helper.c diff --git a/tests/add_subdirectory/vk_format_utils.c b/tests/integration/vk_format_utils.c similarity index 100% rename from tests/add_subdirectory/vk_format_utils.c rename to tests/integration/vk_format_utils.c diff --git a/tests/add_subdirectory/vk_format_utils_2.c b/tests/integration/vk_format_utils_2.c similarity index 100% rename from tests/add_subdirectory/vk_format_utils_2.c rename to tests/integration/vk_format_utils_2.c diff --git a/tests/add_subdirectory/vk_layer_settings.c b/tests/integration/vk_layer_settings.c similarity index 100% rename from tests/add_subdirectory/vk_layer_settings.c rename to tests/integration/vk_layer_settings.c