安装glfw
在glfw下载目录下载预编译的Mac库文件:
解压后可以放置在 ~/sdk
目录下。
安装Vulkan
在Vulkan下载路径下载 Vulkan SDK,默认安装目录,即为 ~/VulkanSDK
。
创建CMake项目
mkdir -p demo1
cd demo1
touch main.cpp CMakeLists.txt
main.cpp 的内容如下:
#define GLFW_INCLUDE_VULKAN
#include <GLFW/glfw3.h>
#include <iostream>
int main() {
glfwInit();
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
GLFWwindow *window = glfwCreateWindow(1000, 600, "Vulkan window", nullptr, nullptr);
uint32_t extensionCount = 0;
vkEnumerateInstanceExtensionProperties(nullptr, &extensionCount, nullptr);
std::cout << extensionCount << " extensions supported\n";
while (!glfwWindowShouldClose(window)) {
glfwPollEvents();
}
glfwDestroyWindow(window);
glfwTerminate();
return 0;
}
CMakeLists.txt 的内容如下:
cmake_minimum_required(VERSION 3.24)
project(demo1)
set(CMAKE_CXX_STANDARD 17)
# glfw3的目录
include_directories(~/sdk/glfw/include)
link_directories(~/sdk/glfw/lib)
# Vulkan的目录
include_directories(~/VulkanSDK/1.3.239.0/macOS/include/)
link_directories(~/VulkanSDK/1.3.239.0/macOS/lib)
add_executable(demo1 main.cpp)
target_link_libraries(demo1 glfw3 vulkan "-framework Cocoa" "-framework IOKit")
编译并运行:
mkdir -p build && cd build && cmake ..
make
./demo1
标签:Vulkan,CMake,--,directories,nullptr,demo1,glfw,include
From: https://www.cnblogs.com/bfstudy/p/17159411.html