Skip to content

CMake: C++20-Module installation and integration testing #538

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Apr 25, 2025
7 changes: 2 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
with:
cmakeVersion: ${{ matrix.cmake-version }}
- uses: ilammy/msvc-dev-cmd@v1
- run: cmake -S . -B build -D VULKAN_HEADERS_ENABLE_TESTS=ON -D VULKAN_HEADERS_ENABLE_INSTALL=ON -G Ninja
- run: cmake -S . -B build -D VULKAN_HEADERS_ENABLE_TESTS=ON -D VULKAN_HEADERS_ENABLE_INSTALL=ON
- run: cmake --build ./build
- run: cmake --install build/ --prefix build/install
- run: ctest --output-on-failure
Expand All @@ -46,7 +46,7 @@ jobs:
with:
cmakeVersion: ${{ matrix.cmake-version }}
- uses: ilammy/msvc-dev-cmd@v1
- run: cmake -S . -B build -D VULKAN_HEADERS_ENABLE_TESTS=ON -D VULKAN_HEADERS_ENABLE_INSTALL=ON -G Ninja
- run: cmake -S . -B build -D VULKAN_HEADERS_ENABLE_TESTS=ON -D VULKAN_HEADERS_ENABLE_INSTALL=ON
- run: cmake --build ./build
- run: cmake --install build/ --prefix build/install
- run: ctest --output-on-failure
Expand All @@ -68,7 +68,6 @@ jobs:
-D CMAKE_BUILD_TYPE=Release `
-D VULKAN_HEADERS_ENABLE_TESTS=ON `
-D VULKAN_HEADERS_ENABLE_INSTALL=ON `
-G Ninja
- run: cmake --build ./build
- run: cmake --install build/ --prefix build/install
- run: ctest --output-on-failure
Expand All @@ -95,7 +94,6 @@ jobs:
-D VULKAN_HEADERS_ENABLE_MODULE=ON \
-D VULKAN_HEADERS_ENABLE_MODULE_STD=OFF \
-D CMAKE_CXX_COMPILER=${{ matrix.compiler }} \
-G Ninja
- run: cmake --build ./build
- run: cmake --install build/ --prefix build/install
- run: CXX=${{ matrix.compiler }} ctest --output-on-failure
Expand All @@ -120,7 +118,6 @@ jobs:
-D VULKAN_HEADERS_ENABLE_INSTALL=ON `
-D VULKAN_HEADERS_ENABLE_MODULE=ON `
-D VULKAN_HEADERS_ENABLE_MODULE_STD=OFF `
-G Ninja
- run: cmake --build ./build
- run: cmake --install build/ --prefix build/install
- run: ctest --output-on-failure
Expand Down
23 changes: 19 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ if (VULKAN_HEADERS_ENABLE_MODULE)
endif()

# set up Vulkan-HppModule
add_library(Vulkan-HppModule)
add_library(Vulkan-HppModule OBJECT)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be made into a pure interface library like Vulkan-Headers?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadly no, targets with C++20-module sources cannot be made interface:

[cmake] target_sources File set TYPE "CXX_MODULES" may not have "INTERFACE" visibility

It's the conundrum of being able to treat .cppm as both a header and a source file

add_library(Vulkan::HppModule ALIAS Vulkan-HppModule)
target_sources(Vulkan-HppModule
PUBLIC
Expand Down Expand Up @@ -114,10 +114,25 @@ if (VULKAN_HEADERS_ENABLE_INSTALL)
# Preserve source permissions https://github.com/KhronosGroup/Vulkan-Headers/issues/336
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/registry" DESTINATION "${CMAKE_INSTALL_DATADIR}/vulkan" USE_SOURCE_PERMISSIONS)

set_target_properties(Vulkan-Headers PROPERTIES EXPORT_NAME "Headers")
install(TARGETS Vulkan-Headers EXPORT VulkanHeadersConfig INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

install(EXPORT VulkanHeadersConfig NAMESPACE "Vulkan::" DESTINATION "share/cmake/VulkanHeaders")
set_target_properties(Vulkan-Headers PROPERTIES EXPORT_NAME "Headers")
install(TARGETS Vulkan-Headers
EXPORT VulkanHeadersConfig
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
if (VULKAN_HEADERS_ENABLE_MODULE)
set_target_properties(Vulkan-HppModule PROPERTIES EXPORT_NAME "HppModule")
install(TARGETS Vulkan-HppModule
EXPORT VulkanHeadersConfig
FILE_SET module DESTINATION ".")
install(EXPORT VulkanHeadersConfig
NAMESPACE "Vulkan::"
DESTINATION "share/cmake/VulkanHeaders"
CXX_MODULES_DIRECTORY ".")
else()
install(EXPORT VulkanHeadersConfig
NAMESPACE "Vulkan::"
DESTINATION "share/cmake/VulkanHeaders")
endif()

set(version_config "${CMAKE_CURRENT_BINARY_DIR}/generated/VulkanHeadersConfigVersion.cmake")
write_basic_package_version_file("${version_config}" COMPATIBILITY SameMajorVersion ARCH_INDEPENDENT)
Expand Down
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ add_test(NAME integration.find_package
--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=${test_install_dir}
--build-options -DFIND_PACKAGE_TESTING=ON -DCMAKE_PREFIX_PATH=${test_install_dir} -DVULKAN_HEADERS_ENABLE_MODULE=${VULKAN_HEADERS_ENABLE_MODULE}
)

# Installing comes before testing
Expand Down
4 changes: 1 addition & 3 deletions tests/integration/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ if (FIND_PACKAGE_TESTING)
message(FATAL_ERROR "VulkanHeaders_VERSION not defined!")
endif()
message(STATUS "VulkanHeaders_VERSION = ${VulkanHeaders_VERSION}")
endif()

if (NOT FIND_PACKAGE_TESTING)
else()
# Consuming vulkan-headers via add_subdirectory should NOT add installation code to the parent CMake project.
if (DEFINED CMAKE_INSTALL_INCLUDEDIR)
message(FATAL_ERROR "CMAKE_INSTALL_INCLUDEDIR was defined!")
Expand Down
4 changes: 2 additions & 2 deletions tests/vk_hpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
#include <vulkan/vulkan.hpp>

int header_version()
int test_version()
{
return VK_HEADER_VERSION;
return static_cast<int>(vk::makeApiVersion(1, 0, 0, 0));
}