mirror of
https://github.com/KhronosGroup/Vulkan-Utility-Libraries.git
synced 2025-05-18 18:58:41 +00:00
cmake: Add/test find_package/add_subdirectory support
This commit is contained in:
parent
280a68ef17
commit
bedbde277e
11 changed files with 113 additions and 45 deletions
16
.github/workflows/vul.yml
vendored
16
.github/workflows/vul.yml
vendored
|
@ -22,13 +22,13 @@ on:
|
||||||
- main
|
- main
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build_test:
|
build_and_test:
|
||||||
runs-on: ${{matrix.os}}
|
runs-on: ${{matrix.os}}
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
config: [Debug, Release]
|
config: [Debug, Release]
|
||||||
os: [ ubuntu-latest, windows-latest, macos-latest ]
|
os: [ ubuntu-20.04, ubuntu-22.04, windows-latest, macos-latest ]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-python@v4
|
- uses: actions/setup-python@v4
|
||||||
|
@ -37,7 +37,17 @@ jobs:
|
||||||
- name: Configure
|
- 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
|
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
|
- name: Build
|
||||||
run: cmake --build build --config ${{matrix.config}}
|
run: cmake --build build --config ${{matrix.config}} --verbose
|
||||||
- name: Tests
|
- name: Tests
|
||||||
working-directory: ./build
|
working-directory: ./build
|
||||||
run: ctest -C ${{matrix.config}} --output-on-failure
|
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
|
||||||
|
|
|
@ -16,21 +16,16 @@ cmake_minimum_required(VERSION 3.17.2)
|
||||||
|
|
||||||
project(VUL LANGUAGES CXX)
|
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
|
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_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.
|
add_subdirectory(scripts)
|
||||||
# This reduces problems for users who simply want to build the repository.
|
|
||||||
|
find_package(VulkanHeaders CONFIG QUIET)
|
||||||
|
|
||||||
option(VUL_WERROR "Treat compiler warnings as errors")
|
option(VUL_WERROR "Treat compiler warnings as errors")
|
||||||
if (VUL_WERROR)
|
if (VUL_WERROR)
|
||||||
add_compile_options("$<IF:$<CXX_COMPILER_ID:MSVC>,/WX,-Werror>")
|
add_compile_options("$<IF:$<CXX_COMPILER_ID:MSVC>,/WX,-Werror>")
|
||||||
|
@ -39,14 +34,20 @@ if (VUL_WERROR)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
find_package(PythonInterp 3.7.2 REQUIRED)
|
add_subdirectory(src)
|
||||||
|
add_subdirectory(include)
|
||||||
|
|
||||||
add_subdirectory(scripts)
|
if (VUL_IS_TOP_LEVEL)
|
||||||
|
option(VUL_TESTS "Build tests")
|
||||||
|
if (VUL_TESTS)
|
||||||
|
enable_testing()
|
||||||
|
add_subdirectory(tests)
|
||||||
|
endif()
|
||||||
|
|
||||||
find_package(VulkanHeaders REQUIRED CONFIG QUIET)
|
include(GNUInstallDirs)
|
||||||
|
|
||||||
if (VUL_TESTS)
|
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/vulkan" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
||||||
enable_testing()
|
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()
|
endif()
|
||||||
|
|
||||||
add_subdirectory(layer_utils)
|
|
||||||
|
|
19
include/CMakeLists.txt
Normal file
19
include/CMakeLists.txt
Normal 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)
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2015-2023 The Khronos Group Inc.
|
* Copyright (c) 2023 The Khronos Group Inc.
|
||||||
* Copyright (c) 2015-2023 Valve Corporation
|
* Copyright (c) 2023 Valve Corporation
|
||||||
* Copyright (c) 2015-2023 LunarG, Inc.
|
* Copyright (c) 2023 LunarG, Inc.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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
|
// Query setting data for LIST setting type in the layer manifest
|
||||||
List GetLayerSettingList(const char *layer_key, const char *setting_key);
|
List GetLayerSettingList(const char *layer_key, const char *setting_key);
|
||||||
|
|
||||||
} // namespace vku
|
} // namespace vku
|
|
@ -12,21 +12,19 @@
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
set(CMAKE_FOLDER "${CMAKE_FOLDER}/libs")
|
||||||
|
|
||||||
add_library(VulkanLayerUtils STATIC)
|
add_library(VulkanLayerUtils STATIC)
|
||||||
add_library(Vulkan::LayerUtils ALIAS VulkanLayerUtils)
|
add_library(Vulkan::LayerUtils ALIAS VulkanLayerUtils)
|
||||||
|
|
||||||
target_sources(VulkanLayerUtils PRIVATE
|
target_sources(VulkanLayerUtils PRIVATE
|
||||||
vk_layer_settings.cpp
|
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)
|
if(WIN32)
|
||||||
target_compile_definitions(VulkanLayerUtils PUBLIC _CRT_SECURE_NO_WARNINGS)
|
target_compile_definitions(VulkanLayerUtils PRIVATE _CRT_SECURE_NO_WARNINGS)
|
||||||
endif()
|
|
||||||
|
|
||||||
if(VUL_TESTS)
|
|
||||||
enable_testing()
|
|
||||||
add_subdirectory(tests)
|
|
||||||
endif()
|
endif()
|
|
@ -22,8 +22,7 @@
|
||||||
* - Courtney Goeltzenleuchter
|
* - Courtney Goeltzenleuchter
|
||||||
* - Tobin Ehlis
|
* - Tobin Ehlis
|
||||||
*/
|
*/
|
||||||
|
#include "vulkan/layer/vk_layer_settings.h"
|
||||||
#include "vk_layer_settings.h"
|
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cassert>
|
#include <cassert>
|
|
@ -12,23 +12,23 @@
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
set(CMAKE_FOLDER "${CMAKE_FOLDER}/tests")
|
||||||
|
|
||||||
find_package(GTest REQUIRED CONFIG)
|
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
|
test_util.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(tests_util PRIVATE
|
target_link_libraries(vul_tests PRIVATE
|
||||||
GTest::gtest
|
GTest::gtest
|
||||||
GTest::gtest_main
|
GTest::gtest_main
|
||||||
Vulkan::Headers
|
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)
|
18
tests/add_subdirectory/CMakeLists.txt
Normal file
18
tests/add_subdirectory/CMakeLists.txt
Normal 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)
|
3
tests/add_subdirectory/client.cpp
Normal file
3
tests/add_subdirectory/client.cpp
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
#include <vulkan/layer/vk_layer_settings.h>
|
||||||
|
|
||||||
|
bool foobar() { return vku::IsLayerSetting("layer_name", "setting_key"); }
|
20
tests/find_package/CMakeLists.txt
Normal file
20
tests/find_package/CMakeLists.txt
Normal 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)
|
|
@ -18,12 +18,11 @@
|
||||||
* - Christophe Riccio <christophe@lunarg.com>
|
* - Christophe Riccio <christophe@lunarg.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <vulkan/vulkan.h>
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
#include "../vk_layer_settings.h"
|
#include "vulkan/layer/vk_layer_settings.h"
|
||||||
|
|
||||||
TEST(test_library_util, Something) {
|
TEST(test_library_util, Something) {
|
||||||
EXPECT_TRUE(true);
|
EXPECT_TRUE(true);
|
||||||
EXPECT_FALSE(vku::IsLayerSetting("layer_name", "setting_key"));
|
EXPECT_FALSE(vku::IsLayerSetting("layer_name", "setting_key"));
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue