OSX上的GLFW + Vulkan

时间:2017-09-05 16:28:44

标签: c++ macos cmake glfw vulkan

我正在为我的一个项目设置GLFW和Vulkan。对于Vulkan,我使用MoltenVk获取Vulkan compat和GLFW用于创建窗口。我使用的IDE是CLion,它使用CMake系统。

从一些github问题来看,似乎支持这种设置,但没有人提到它是如何完成的。

GLFW通过自制软件和MoltenVK手动安装,将MoltenVK和vulkan文件夹添加到usr / local / include,将MacOS文件夹的内容添加到usr / local / lib(尽管我很确定MoltenVK.framework不应该是有)。

此时,Clion可以看到GLFW和Vulkan标题,但我仍需要正确链接它们。

现在是完整的CMakeLists.txt文件:

cmake_minimum_required(VERSION 3.8)
project(VulkanEngine)

#set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} “${CMAKE_SOURCE_DIR}/cmake/Modules”)

set(CMAKE_CXX_STANDARD 17)

set(SOURCE_FILES src/main.cpp)
add_executable(VulkanEngine ${SOURCE_FILES})

#Finding and linking GLFW3

find_package(glfw3 3.2 REQUIRED)
if (glfw3_FOUND)
    include_directories(${glfw3_INCLUDE_DIRS})
    target_link_libraries (VulkanEngine ${glfw3_LIBRARIES})
endif (glfw3_FOUND)

#Finding and linking Vulkan

find_package (Vulkan)
if (Vulkan_FOUND)
    include_directories(${Vulkan_INCLUDE_DIRS})
    target_link_libraries (VulkanEngine ${Vulkan_LIBRARIES})
endif (Vulkan_FOUND)

控制台在cmake项目重新加载时告诉以下内容:

-- Could NOT find Vulkan (missing:  Vulkan_LIBRARY) 
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/mtesseract/dev/cpp/VulkanEngine/cmake-build-debug

对我而言,这表明GLFW已被发现并链接,但当我尝试构建" hello world"对于GLFW,我收到以下消息:

Undefined symbols for architecture x86_64:
  "_glfwInit", referenced from:
      _main in main.cpp.o

我从GLFW github页面https://git.io/v5ggN获得了FindVulkan.cmake,因为它支持MoltenVK,但我不确定它是否被CMake拾取。 (我把文件放在(projectroot)/ cmake / modules /)

此时,我不知道为什么事情没有正确连接,所以请帮助。

2 个答案:

答案 0 :(得分:0)

我找到了一种解决方案,至少在某种程度上似乎有效。在这一点上,我还有另外一个需要处理的问题(GLFW似乎没有接受MoltenVK的存在)。

到目前为止的流程如下(可以在我的github页面上找到(github.com/mtesseracttech/VulkanEngine):

Vulkan + GLFW + GLM Setup Process with CMake and Package Managers

Windows:

Preparation:
Create CLion Application Project 
Install MSYS2 (Cygwin-like package manager that includes a windows port of Arch's PacMan)
Install LunarG VK SDK
Download FindVulkan.cmake from GFLW's Github (it includes a path for MoltenVK(for OSX Later)) and put it in (proj_root/cmake/modules)

MSYS2 Commands:

$ pacman -Su //Updates pacman
$ pacman -Ss {packageName} //Is used for searching for exact package names

Installed Packages through msys2:

$ pacman -S mingw-w64-x86_64-toolchain //Installs the CLion toolchain that includes CMake, Make, GCC, etc.
$ pacman -S mingw-w64-x86_64-glfw //Installs GLFW
$ pacman -S mingw-w64-x86_64-glm //Installs GLM
$ pacman -S mingw-w64-x86_64-vulkan //Vulkan can also be installed through this method, but I went with LunarG

Enter the following in the CMakeLists.txt file in the root of the project:

######################################################################################

cmake_minimum_required(VERSION 3.8)
project(VulkanEngine)

set(CMAKE_CXX_STANDARD 17)

set(SOURCE_FILES src/main.cpp)
add_executable(VulkanEngine ${SOURCE_FILES})

#Setting up PkgConfig

find_package(PkgConfig REQUIRED)

#Finding and linking GLFW3

pkg_search_module(GLFW3 3.2 REQUIRED glfw3)
if(GLFW3_FOUND)
    message(STATUS "Found GLFW, Including and Linking now")
    include_directories(${GLFW3_INCLUDE_DIRS})
    target_link_libraries(VulkanEngine ${GLFW3_STATIC_LIBRARIES})
endif(GLFW3_FOUND)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")

#Finding and linking Vulkan

find_package (Vulkan)
if (VULKAN_FOUND)
    message(STATUS "Found Vulkan, Including and Linking now")
    include_directories(${VULKAN_INCLUDE_DIR})
    target_link_libraries (VulkanEngine ${VULKAN_LIBRARY})
endif (VULKAN_FOUND)

######################################################################################




OSX:

Preparation

Create CLion Application Project 
Install HomeBrew (package manager)
Download MoltenVK
Download FindVulkan.cmake from GFLW's Github (it includes a path for MoltenVK(for OSX Later)) and put it in (proj_root/cmake/modules)

Homebrew:
brew update //Updates homebrew
brew install glfw //Installs GLFW
brew install glm //Installs GLM

MoltenVK:
Place MoltenVK/macOS's contents into /usr/local/lib
Place MoltenVK/macOS/MoltenVK.framework/headers's contents into /usr/local/inc/MoltenVK

CMake: 
Same as on windows, but in the FindVulkan.cmake file, add at the very end of the elseif(APPLE) block the line:
set(VULKAN_INCLUDE_DIR "/usr/local/include/MoltenVK")
This is not a pretty or flexible solution, but for now it will do.

我很确定这个解决方案并不理想,因为GLFW并没有采用这种策略来接受MoltenVK,但至少可以编译,所以我认为这是进步。

答案 1 :(得分:0)

似乎您的问题是您尚未定义VULKAN_SDK变量。确保将其指向SDK内的/ lib&/ include的父文件夹,并且FindVulkan应该可以工作

VULKAN_SDK=/opt/vulkan/x86_64 cmake.