PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, September 12, 2022

[FIXED] How can I add Vulkan to a cross platform CMake project?

 September 12, 2022     c++, cmake, cross-platform, repository, vulkan     No comments   

Issue

In order to make a CMake project as simple and as portable as it can get I have consider to add the "whole" repositories of the libraries I need to the project. The project structure is as follows:

MyProject/
└──CMakeLists.txt
└──src/
    └──MyProject/
        └── *.h & *.cpp
        └── CMakeLists.txt
└──ThirdParty/
    └──Vulkan-Hpp/
        └──(Vulkan Files)
    └──glfw/
        └──(glfw Files)
    └──SFML/
        └──(SFML Files)

All the third party directories are the git submodules of the following repositories: https://github.com/KhronosGroup/Vulkan-Hpp

https://github.com/SFML/SFML

https://github.com/glfw/glfw

Summarizing everything up, I'm having trouble integrating the vulkan and sfml libraries to the project.

MyProject/CMakeLists.txt is as follows:

cmake_minimum_required (VERSION 3.8 FATAL_ERROR)

project ("MyProject")

set (MyProject_VERSION_MAJOR 0)
set (MyProject_VERSION_MINOR 2)
set (MyProject_VERSION_PATCH 1)

set (CMAKE_CXX_STANDARD 17)

# Include sub-projects.
add_subdirectory ("src/MyProject")
add_subdirectory ("ThirdParty/glfw")
add_subdirectory ("ThirdParty/SFML")
add_subdirectory ("ThirdParty/Vulkan-Hpp")

MyProject/src/MyProject/CMakeLists.txt:

cmake_minimum_required (VERSION 3.8 FATAL_ERROR)

project ("MyProject")
find_package(Vulkan REQUIRED FATAL_ERROR) # error
find_package(SFML REQUIRED network audio) # error
find_package(glfw REQUIRED FATAL_ERROR) # error

# Add source to this project's executable.
add_executable (MyProject "MyProject.cpp")

target_include_directories (MyProject 
    PUBLIC ${GLFW_INCLUDE_DIRS}
    PUBLIC ${SFML_INCLUDE_DIR}
    PUBLIC ${VULKAN_INCLUDE_DIRS}
)

target_link_libraries (MyProject glfw)
target_link_libraries (MyProject ${VULKAN_LIB_LIST})
target_link_libraries (MyProject ${SFML_LIBRARIES})

How can I tweak CMake in order to use the third party libraries at my main project? Is the project structure incorrect?


Solution

If your find_package(Vulkan REQUIRED FATAL_ERROR) line is failing, you need to make sure the Vulkan SDK is properly installed, i.e. that you have a VULKAN_SDK environment variable that points to the correct location.

Additionally, do not embed the KhronosGroup/Vulkan-Hpp repository. This repository is for building the Vulkan C++ bindings, but shouldn't be used directly. Instead you should be using the vulkan.hpp header that is bundled with your installation of the Vulkan SDK. Otherwise when people try to build your project and have a different version of the Vulkan SDK installed than is referred to by your embedded KhronosGroup/Vulkan-Hpp

More generally, you are using find_package and then later you're using add_subdirectory to try to incorporate these external projects. That's not how it works. find_package will look for a pre-existing binary of the package, while add_subdirectory isn't designed to just swallow entire existing external CMake projects.

If you want to have your project build these others from source you should investigate the use of CMake's external project functionality. However, you'll probably find this to be more of a burden than it's worth. Alternatively, install vcpkg for your target platform, and use vcpkg to build and install glfw and sfml, then tell CMake to use the vcpkg dependencies (see the vcpkg docs on how to pass the CMAKE_TOOLCHAIN_FILE to your cmake configure line.



Answered By - Jherico
Answer Checked By - Pedro (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing