cmake: Minor CMake cleanup

- Fix project name to be less confusing
- Better testing
This commit is contained in:
Juan Ramos 2023-03-15 13:51:43 -06:00 committed by Juan Ramos
parent d732b2de30
commit 65ad768d86
3 changed files with 19 additions and 6 deletions

View file

@ -41,13 +41,11 @@ function(vlk_get_header_version)
endfunction()
vlk_get_header_version()
project(Vulkan-Headers LANGUAGES C VERSION ${VK_VERSION_STRING})
message(DEBUG "${PROJECT_NAME} = ${PROJECT_VERSION}")
project(VULKAN_HEADERS LANGUAGES C VERSION ${VK_VERSION_STRING})
add_library(Vulkan-Headers INTERFACE)
target_include_directories(Vulkan-Headers INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)
add_library(Vulkan::Headers ALIAS Vulkan-Headers)
target_include_directories(Vulkan-Headers INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)
if (CMAKE_VERSION VERSION_LESS "3.21")
# https://cmake.org/cmake/help/latest/variable/PROJECT_IS_TOP_LEVEL.html

View file

@ -18,6 +18,8 @@
# NOTE: For us testing just means that these header files compile
# with reasonable warnings.
message(STATUS "${PROJECT_NAME} = ${PROJECT_VERSION}")
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)
@ -38,3 +40,7 @@ target_link_libraries(vk_icd PRIVATE Vulkan::Headers)
# vk_layer.h
add_library(vk_layer MODULE vk_layer.c)
target_link_libraries(vk_layer PRIVATE Vulkan::Headers)
if (NOT TARGET Vulkan-Headers)
message(FATAL_ERROR "Backcompat for Vulkan-Headers target broken!")
endif()

View file

@ -1,8 +1,8 @@
cmake_minimum_required(VERSION 3.10.2)
cmake_minimum_required(VERSION 3.14.2)
project(TEST_VULKAN_HEADERS_FIND_PACKAGE_SUPPORT LANGUAGES C)
find_package(VulkanHeaders REQUIRED CONFIG)
find_package(VulkanHeaders REQUIRED CONFIG)
if (NOT TARGET Vulkan::Headers)
message(FATAL_ERROR "Vulkan::Headers target not defined")
@ -21,3 +21,12 @@ if (NOT DEFINED VulkanHeaders_VERSION)
message(FATAL_ERROR "VulkanHeaders_VERSION not defined!")
endif()
message(STATUS "VulkanHeaders_VERSION = ${VulkanHeaders_VERSION}")
add_library(foobar STATIC)
target_link_libraries(foobar PRIVATE Vulkan::Headers)
target_sources(foobar PRIVATE
../vk_icd.c
../vk_layer.c
)