gpt4 book ai didi

cmake - 使用 CMake 和 conan 包管理器正确设置 Vulkan、glfw 和 spdlog

转载 作者:行者123 更新时间:2023-12-03 02:00:18 26 4
gpt4 key购买 nike

我正在开发 Vulkan API 的渲染器。我在使用 CMake 和 conan 包管理器正确设置项目时遇到了很大的麻烦。让我们看一下我的 conanfile.py 的依赖设置:

from conans import ConanFile, CMake

class InexorConan(ConanFile):

settings = (
"os",
"compiler",
"build_type",
"arch"
)

requires = (
"benchmark/1.5.0",
"glm/0.9.9.7",
"gtest/1.10.0",
"spdlog/1.5.0",
"glfw/3.3.2@bincrafters/stable",
"toml11/3.1.0",
"imgui/1.75",
"assimp/5.0.1",
"enet/1.3.14 "
)

generators = "cmake"

default_options = {
}

def imports(self):
# Copies all dll files from packages bin folder to my "bin" folder (win)
self.copy("*.dll", dst="bin", src="bin")
# Copies all dylib files from packages lib folder to my "lib" folder (macosx)
self.copy("*.dylib*", dst="lib", src="lib") # From lib to lib
# Copies all so files from packages lib folder to my "lib" folder (linux)
self.copy("*.so*", dst="lib", src="lib") # From lib to lib

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

所有 conan 设置都工作正常,从 CMake 输出可以看出: enter image description here

遗憾的是,Vulkan API 没有 conan 设置。所以我使用 Sascha Willem 的 github 存储库的一些代码。我的 CMake 文件如下所示:

cmake_minimum_required(VERSION 3.4)

project(inexor-vulkan-renderer)

file(GLOB_RECURSE source_files
"src/*.hpp"
"src/*.cpp"
)

# Use the folder structure in source code directory as project structure in Visual Studio.
function(assign_source_group)
foreach(source_files IN ITEMS ${ARGN})
if (IS_ABSOLUTE "${source_files}")
file(RELATIVE_PATH _source_rel "${CMAKE_CURRENT_SOURCE_DIR}" "${source_files}")
else()
set(_source_rel "${source_files}")
endif()
get_filename_component(_source_path "${_source_rel}" PATH)
string(REPLACE "/" "\\" _source_path_msvc "${_source_path}")
source_group("${_source_path_msvc}" FILES "${source_files}")
endforeach()
endfunction(assign_source_group)

# Use CMake to find Vulkan SDK.
if (NOT CMAKE_VERSION VERSION_LESS 3.7.0)
message(STATUS "Using module to find Vulkan")
find_package(Vulkan)
endif()

# Dependency setup via conan.
# Download conan executer in case it does not exists.
if(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/conan.cmake")
message(STATUS "Downloading conan.cmake from https://github.com/conan-io/cmake-conan")
file(DOWNLOAD "https://raw.githubusercontent.com/conan-io/cmake-conan/v0.14/conan.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/conan.cmake")
endif()

# Execute conan build instructions.
include(${CMAKE_CURRENT_BINARY_DIR}/conan.cmake)

conan_cmake_run(CONANFILE conanfile.py
BASIC_SETUP
BUILD outdated
PROFILE default
PROFILE_AUTO build_type
KEEP_RPATHS
)

# Use the folder structure in source code directory as project structure in Visual Studio.
assign_source_group(${source_files})

add_executable(inexor-vulkan-renderer src/main.cpp ${source_files})

target_link_libraries(inexor-vulkan-renderer PUBLIC ${Vulkan_LIBS} ${CONAN_LIBS})

# Use C++17!
target_compile_features(inexor-vulkan-renderer PRIVATE cxx_std_17)

IF(WIN32)
target_compile_definitions(inexor-vulkan-renderer PRIVATE VK_USE_PLATFORM_WIN32_KHR)
ENDIF()

target_include_directories(inexor-vulkan-renderer PRIVATE Vulkan::Vulkan)

target_link_libraries(inexor-vulkan-renderer Vulkan::Vulkan)

当我使用此设置生成 Visual Studio 项目文件时,我必须手动将 glfw3.lib、spdlogd.lib 和 fmtd.lib 添加到项目中。其他存储库(例如官方 Vulkan 示例)采用更传统的方法,只需将库直接粘贴到存储库文件夹中。我不想这样做,因为我想让柯南为我工作。六个月来我一直在努力解决这个问题。

尽管 conan 可以找到所需的库,但为什么 CMake 没有链接它们?

谢谢你。

最佳答案

我找到了解决方案:有一个名为 conan_target_link_libraries 的函数,必须使用它来代替 target_link_libraries。感谢您的回答。

关于cmake - 使用 CMake 和 conan 包管理器正确设置 Vulkan、glfw 和 spdlog,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60422367/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com