我想使用cmake将Qt框架与SFML集成,希望在VS2022中。目前我的存储库中已经有SFML,cmake看起来像这样:
cmake_minimum_required(VERSION 3.16)
project(CMakeSFMLProject LANGUAGES CXX)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
include(FetchContent)
FetchContent_Declare(SFML
GIT_REPOSITORY https://github.com/SFML/SFML.git
GIT_TAG 2.6.x)
FetchContent_MakeAvailable(SFML)
add_executable(CMakeSFMLProject src/main.cpp)
target_link_libraries(CMakeSFMLProject PRIVATE sfml-graphics)
target_compile_features(CMakeSFMLProject PRIVATE cxx_std_17)
if(WIN32)
add_custom_command(
TARGET CMakeSFMLProject
COMMENT "Copy OpenAL DLL"
PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${SFML_SOURCE_DIR}/extlibs/bin/$<IF:$<EQUAL:${CMAKE_SIZEOF_VOID_P},8>,x64,x86>/openal32.dll $<TARGET_FILE_DIR:CMakeSFMLProject>
VERBATIM)
endif()
install(TARGETS CMakeSFMLProject)
字符串
因此,在这个过程中,我想以某种方式添加Qt库。
我也想用VS编程,现在我只是打开这个仓库所在的文件夹,VS可以正常工作。我已经安装了Qt for VS,它可以工作,但我不知道如何将这两个框架集成在一起,也不知道如何使用它们。
目前更新后,我有以下内容:
cmake_minimum_required(VERSION 3.16)
project(PathFinder VERSION 1.0.0 LANGUAGES CXX)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
find_package(Qt6 REQUIRED COMPONENTS Core)
include(FetchContent)
FetchContent_Declare(SFML
GIT_REPOSITORY https://github.com/SFML/SFML.git
GIT_TAG 2.6.x)
FetchContent_MakeAvailable(SFML)
add_executable(PathFinder src/main.cpp)
target_link_libraries(PathFinder PRIVATE
Qt6::Core
Qt6::Widgets
sfml-graphics
)
target_compile_features(PathFinder PRIVATE cxx_std_17)
if(WIN32)
add_custom_command(
TARGET PathFinder
COMMENT "Copy OpenAL DLL"
PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${SFML_SOURCE_DIR}/extlibs/bin/$<IF:$<EQUAL:${CMAKE_SIZEOF_VOID_P},8>,x64,x86>/openal32.dll $<TARGET_FILE_DIR:CMakeSFMLProject>
VERBATIM)
endif()
install(TARGETS PathFinder)
型
但出于某种原因
By not providing "FindQt6.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "Qt6", but
CMake did not find one.
Could not find a package configuration file provided by "Qt6" with any of
the following names:
Qt6Config.cmake
qt6-config.cmake
Add the installation prefix of "Qt6" to CMAKE_PREFIX_PATH or set "Qt6_DIR"
to a directory containing one of the above files. If "Qt6" provides a
separate development package or SDK, be sure it has been installed. PathFinder C:\Users\nhorv\Desktop\proba\CMakeLists.txt 7
型
但我想在本地包含Qt,这样用户就不必手动设置PATH变量。我想将Qt作为依赖项安装,而不是在系统范围内安装。这可以使用Qt的git repo吗?
1条答案
按热度按时间vwoqyblh1#
这是我的
CMakeLists.txt
文件:字符串
这是一个最小的例子:
型
输出量:
的数据
但问题是,我的操作系统是Ubuntu 22.04,对于Windows,你需要用同样的方法来做。意思是这样的:
型