Skip to content
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

FindVulkan.cmake for macOS #116

Closed
danginsburg opened this Issue Mar 28, 2018 · 6 comments

Comments

Projects
None yet
4 participants
@danginsburg
Copy link
Collaborator

danginsburg commented Mar 28, 2018

It would be useful for cross-platform Vulkan projects using cmake for Windows/Linux if there was also support for FindVulkan.cmake on macOS using the LunarG SDK/MoltenVK. T

@oscarbg

This comment has been minimized.

Copy link

oscarbg commented Mar 29, 2018

+1

@karl-lunarg

This comment has been minimized.

Copy link
Collaborator

karl-lunarg commented Mar 29, 2018

I believe that a lot of things are already in place for this to work.

CMake 3.10 (the version that is installed on macOS via brew) installs a /usr/local/share/cmake/Modules/FindVulkan.cmake file.
It contains, in part:

else()
    find_path(Vulkan_INCLUDE_DIR
      NAMES vulkan/vulkan.h
      PATHS
        "$ENV{VULKAN_SDK}/include")
    find_library(Vulkan_LIBRARY
      NAMES vulkan
      PATHS
        "$ENV{VULKAN_SDK}/lib")
endif()

The else() path would run on macOS.

So I think that if you set the VULKAN_SDK environment variable to

<path to your SDK folder>/macOS

then this shipped FindVulkan should work.

If there is a need to locate the libMoltenVK.dylib for the purposes of copying it into an application bundle to create a self-contained Application, then I suppose that the CMake variable Vulkan_LIBRARY could be (ab)used by copying it to another CMake variable and doing a string substitution on the file name. This is because libMoltenVK.dylib is in the same place as the Vulkan library. But I doubt that this is sort of thing that the CMake guys would add to FindVulkan.

I'll look into it a bit more, but it may just turn out to be an effort to add this to the SDK documentation.

Note that this doesn't address apps that link MoltenVK directly.

@karl-lunarg

This comment has been minimized.

Copy link
Collaborator

karl-lunarg commented Mar 29, 2018

Here's a minimal CMake file that builds the vulkaninfo console (Terminal) client and uses the existing FindVulkan.cmake module:

CMakeLists.txt:

cmake_minimum_required(VERSION 3.10)
project(vulkaninfo)
find_package(vulkan REQUIRED)
add_executable(vulkaninfo vulkaninfo.c)
target_link_libraries(vulkaninfo Vulkan::Vulkan)

Environment Variables:

VK_ICD_FILENAMES=/Users/karl/Desktop/vulkansdk-macos-1.0.69.0/macOS/etc/vulkan/icd.d/MoltenVK_icd.json

VULKAN_SDK=/Users/karl/Desktop/vulkansdk-macos-1.0.69.0/macOS/

Put the above CMakeLists.txt file in an empty directory someplace.

Then get a copy of the vulkaninfo.c file. Be aware that you can't use the latest from the Vulkan-LoaderAndValidationLayers repo because it has been ported to Vulkan 1.1 and you need a 1.0 version for this macOS SDK. This version will work.
Put the vulkaninfo.c file in the same directory as CMakeLists.txt.

Set the specified environment variables, adjusting for the actual location of your SDK.

Then:

mkdir build
cd build
cmake ..
make
./vulkaninfo

and you should see the output of vulkaninfo in your terminal.

Is the above sufficient to address this issue? It illustrates how to locate the Vulkan loader and header files in the SDK from a CMake project.

Edit: projects -> project in CMake file.

@danginsburg

This comment has been minimized.

Copy link
Collaborator Author

danginsburg commented Mar 30, 2018

Is the above sufficient to address this issue? It illustrates how to locate the Vulkan loader and header files in the SDK from a CMake project.

Yes, this is perfect, thanks!

@karl-lunarg

This comment has been minimized.

Copy link
Collaborator

karl-lunarg commented Mar 30, 2018

I've added this information to the SDK's Getting Started guide.

@billhollings I think you can close this issue now.

@billhollings

This comment has been minimized.

Copy link
Contributor

billhollings commented Mar 30, 2018

@karl-lunarg Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.