Issue
I'm trying to include vulkan hpp library using cmake with fetch_content (I want to automate this and I don't want the user to manually install vulkan, if this is a wrong approach let me know because I'm just starting with cmake) as shown in the following code snippet
include(FetchContent)
FetchContent_Declare(
vulkanhpp
GIT_REPOSITORY https://github.com/KhronosGroup/Vulkan-Hpp.git
GIT_TAG b97783be3ed973f4e0d96fc7c680920f5ab0aa3a #1.2.191
)
FetchContent_GetProperties(vulkanhpp)
if ( NOT vulkanhpp_POPULATED )
message ( STATUS "Fetching vulkanhpp" )
FetchContent_Populate(vulkanhpp)
set ( SAMPLES_BUILD OFF CACHE INTERNAL "Build the vulkan hpp samples" )
set ( VULKAN_HPP_INSTALL OFF CACHE INTERNAL "Install vulkan hpp" )
add_subdirectory ( ${vulkanhpp_SOURCE_DIR} ${vulkanhpp_BINARY_DIR} )
endif ()
Now my problem is that I don't know how to include the "include" folder in my main.cpp file when I put in the cpp file:
#include "vulkan/vulkan.hpp"
without putting the full path in CMakeLists.txt and instead using some CMake variable
My other cmake list is as follows
include_directories ( "" ) ### what should I put here for include vulkan hpp library ###
# Add source to this project's executable.
add_executable ( example "main.cpp" )
Is this the correct way for automatic managing the vulkan hpp dependency? Are there any other alternative without using find_package?
Solution
The repository you specified does not actually contain the Vulkan headers. Use this instead. It provides a CMakeLists.txt
file which adds the headers to a library called Vulkan::Headers
so you can just add the subdirectory and then link to them using target_link_libraries(example PRIVATE Vulkan::Headers)
.
But why would you do this? To use Vulkan you have to have the Vulkan SDK installed (the actual libraries) and the SDK also includes the headers.
Answered By - octowaddle