cmake: Add/test find_package/add_subdirectory support

This commit is contained in:
Juan Ramos 2023-03-31 12:37:22 -06:00 committed by Christophe
parent 280a68ef17
commit bedbde277e
11 changed files with 113 additions and 45 deletions

View file

@ -22,13 +22,13 @@ on:
- main
jobs:
build_test:
build_and_test:
runs-on: ${{matrix.os}}
strategy:
fail-fast: false
matrix:
config: [Debug, Release]
os: [ ubuntu-latest, windows-latest, macos-latest ]
os: [ ubuntu-20.04, ubuntu-22.04, windows-latest, macos-latest ]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
@ -37,7 +37,17 @@ jobs:
- name: Configure
run: cmake -S. -B build -D VUL_WERROR=ON -D VUL_TESTS=ON -D CMAKE_BUILD_TYPE=${{matrix.config}} -D UPDATE_DEPS=ON
- name: Build
run: cmake --build build --config ${{matrix.config}}
run: cmake --build build --config ${{matrix.config}} --verbose
- name: Tests
working-directory: ./build
run: ctest -C ${{matrix.config}} --output-on-failure
- name: Install
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 }}/external/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 GITHUB_VULKAN_HEADER_SOURCE_DIR=${{ github.workspace }}/external/Vulkan-Headers/
cmake --build tests/add_subdirectory/build --config ${{matrix.config}} --verbose

View file

@ -16,21 +16,16 @@ cmake_minimum_required(VERSION 3.17.2)
project(VUL LANGUAGES CXX)
include(GNUInstallDirs)
string(COMPARE EQUAL ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR} VUL_IS_TOP_LEVEL) # Remove when min is 3.21
set_property(GLOBAL PROPERTY USE_FOLDERS ON) # Remove when min is 3.26, see CMP0143
option(VUL_TESTS "Build utility libraries tests")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_CXX_VISIBILITY_PRESET "hidden")
set(CMAKE_VISIBILITY_INLINES_HIDDEN "YES")
# NOTE: The idiom for open source projects is to not enable warnings as errors.
# This reduces problems for users who simply want to build the repository.
add_subdirectory(scripts)
find_package(VulkanHeaders CONFIG QUIET)
option(VUL_WERROR "Treat compiler warnings as errors")
if (VUL_WERROR)
add_compile_options("$<IF:$<CXX_COMPILER_ID:MSVC>,/WX,-Werror>")
@ -39,14 +34,20 @@ if (VUL_WERROR)
endif()
endif()
find_package(PythonInterp 3.7.2 REQUIRED)
add_subdirectory(src)
add_subdirectory(include)
add_subdirectory(scripts)
find_package(VulkanHeaders REQUIRED CONFIG QUIET)
if (VUL_TESTS)
if (VUL_IS_TOP_LEVEL)
option(VUL_TESTS "Build tests")
if (VUL_TESTS)
enable_testing()
endif()
add_subdirectory(tests)
endif()
add_subdirectory(layer_utils)
include(GNUInstallDirs)
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/vulkan" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
set_target_properties(VulkanLayerUtils PROPERTIES EXPORT_NAME "LayerUtils")
install(TARGETS VulkanLayerUtils EXPORT VulkanUtilityLibrariesConfig INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(EXPORT VulkanUtilityLibrariesConfig DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/VulkanUtilityLibraries NAMESPACE Vulkan::)
endif()

19
include/CMakeLists.txt Normal file
View file

@ -0,0 +1,19 @@
# Copyright (c) 2023 Valve Corporation
# Copyright (c) 2023 LunarG, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
target_include_directories(VulkanLayerUtils PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
target_compile_features(VulkanLayerUtils PUBLIC cxx_std_17)
target_sources(VulkanLayerUtils PRIVATE vulkan/layer/vk_layer_settings.h)

View file

@ -1,7 +1,7 @@
/*
* Copyright (c) 2015-2023 The Khronos Group Inc.
* Copyright (c) 2015-2023 Valve Corporation
* Copyright (c) 2015-2023 LunarG, Inc.
* Copyright (c) 2023 The Khronos Group Inc.
* Copyright (c) 2023 Valve Corporation
* Copyright (c) 2023 LunarG, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -60,4 +60,5 @@ Strings GetLayerSettingStrings(const char *layer_key, const char *setting_key);
// Query setting data for LIST setting type in the layer manifest
List GetLayerSettingList(const char *layer_key, const char *setting_key);
} // namespace vku

View file

@ -12,21 +12,19 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set(CMAKE_FOLDER "${CMAKE_FOLDER}/libs")
add_library(VulkanLayerUtils STATIC)
add_library(Vulkan::LayerUtils ALIAS VulkanLayerUtils)
target_sources(VulkanLayerUtils PRIVATE
vk_layer_settings.cpp
vk_layer_settings.h
)
target_link_Libraries(VulkanLayerUtils PRIVATE Vulkan::Headers)
# NOTE: Because Vulkan::Headers header files are exposed in the public facing interface
# we must expose this library as public to users.
target_link_Libraries(VulkanLayerUtils PUBLIC Vulkan::Headers)
if(WIN32)
target_compile_definitions(VulkanLayerUtils PUBLIC _CRT_SECURE_NO_WARNINGS)
endif()
if(VUL_TESTS)
enable_testing()
add_subdirectory(tests)
target_compile_definitions(VulkanLayerUtils PRIVATE _CRT_SECURE_NO_WARNINGS)
endif()

View file

@ -22,8 +22,7 @@
* - Courtney Goeltzenleuchter
* - Tobin Ehlis
*/
#include "vk_layer_settings.h"
#include "vulkan/layer/vk_layer_settings.h"
#include <cstdlib>
#include <cassert>

View file

@ -12,23 +12,23 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set(CMAKE_FOLDER "${CMAKE_FOLDER}/tests")
find_package(GTest REQUIRED CONFIG)
include(GoogleTest)
add_executable(tests_util)
add_executable(vul_tests)
target_sources(tests_util PRIVATE
target_sources(vul_tests PRIVATE
test_util.cpp
)
target_link_libraries(tests_util PRIVATE
target_link_libraries(vul_tests PRIVATE
GTest::gtest
GTest::gtest_main
Vulkan::Headers
VulkanLayerUtils
Vulkan::LayerUtils
)
set_target_properties(tests_util PROPERTIES FOLDER "VulkanLayerUtils-tests")
include(GoogleTest)
gtest_discover_tests(tests_util)
gtest_discover_tests(vul_tests)

View file

@ -0,0 +1,18 @@
cmake_minimum_required(VERSION 3.17)
project(TEST_FIND_PACKAGE LANGUAGES CXX)
add_library(add_subdirectory_example STATIC)
target_sources(add_subdirectory_example PRIVATE client.cpp)
# NOTE: Because VulkanHeaders is a PUBLIC dependency it needs to be found prior to VulkanUtilityLibraries
add_subdirectory(${GITHUB_VULKAN_HEADER_SOURCE_DIR} ${PROJECT_BINARY_DIR}/headers)
add_subdirectory(${PROJECT_SOURCE_DIR}/../../ ${PROJECT_BINARY_DIR}/vul)
if (NOT TARGET Vulkan::LayerUtils)
message(FATAL_ERROR "Vulkan::LayerUtils target not defined!")
endif()
target_link_libraries(add_subdirectory_example PRIVATE Vulkan::LayerUtils)

View file

@ -0,0 +1,3 @@
#include <vulkan/layer/vk_layer_settings.h>
bool foobar() { return vku::IsLayerSetting("layer_name", "setting_key"); }

View file

@ -0,0 +1,20 @@
cmake_minimum_required(VERSION 3.17)
project(TEST_FIND_PACKAGE LANGUAGES CXX)
add_library(find_package_example STATIC)
target_sources(find_package_example PRIVATE
${CMAKE_CURRENT_LIST_DIR}/../add_subdirectory/client.cpp
)
# 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::LayerUtils)
message(FATAL_ERROR "Vulkan::LayerUtils target not defined!")
endif()
target_link_libraries(find_package_example PRIVATE Vulkan::LayerUtils)

View file

@ -18,10 +18,9 @@
* - Christophe Riccio <christophe@lunarg.com>
*/
#include <vulkan/vulkan.h>
#include <gtest/gtest.h>
#include "../vk_layer_settings.h"
#include "vulkan/layer/vk_layer_settings.h"
TEST(test_library_util, Something) {
EXPECT_TRUE(true);