Joh*_*der 3 cmake vulkan conan
我正在为 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()
Run Code Online (Sandbox Code Playgroud)
从 CMake 输出可以看出,所有 conan 设置都正常工作:

遗憾的是,Vulkan API 没有柯南设置。所以我正在使用 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)
Run Code Online (Sandbox Code Playgroud)
当我使用此设置生成 Visual Studio 项目文件时,我必须手动将 glfw3.lib、spdlogd.lib 和 fmtd.lib 添加到项目中。其他存储库(如官方 Vulkan 示例)采用更传统的方法,只需将库直接粘贴到 repo 文件夹中即可。我不想这样做,因为我想让柯南为我工作。我一直在努力解决这个问题 6 个月了。
为什么 CMake 没有链接所需的库,尽管柯南可以找到它们?
谢谢。
| 归档时间: |
|
| 查看次数: |
787 次 |
| 最近记录: |