【发布时间】:2020-01-13 09:09:39
【问题描述】:
我有一个正在开发的 QT 项目,它有几个子模块,我在项目的 .pro 文件中将它们列为:
if(!include(module/my_module.pri)){
error("module my_module not found")
}
我尝试了什么:
好吧,我找到了一个我打算使用的库,它是一个 CMake 项目libcrashreporter-qt。 我只是为了完整性而链接项目 - 这个库没有任何问题(据我所知)
问题:
我想我会尝试包含 CMakeLists.txt 文件,就像我会包含 .pri 文件一样:
if(!include(libcrashreporter-qt/CMakeLists.txt)){
error("module libcrashreporter-qt not found")
}
libcrashreporter-qt 文件夹位于我项目的根目录中
一些代码:
这样做时,我会收到一大堆编译器错误:
$project_dir/libcrashreporter-qt/CMakeLists.txt:1: 'project' is not a recognized test function.
$project_dir/libcrashreporter-qt/CMakeLists.txt:2: 'cmake_minimum_required' is not a recognized test function.
$project_dir/libcrashreporter-qt/CMakeLists.txt:4: Extra characters after test expression.
$project_dir/libcrashreporter-qt/CMakeLists.txt:5: 'cmake_policy' is not a recognized test function.
$project_dir/libcrashreporter-qt/CMakeLists.txt:6: 'endif' is not a recognized test function.
$project_dir/libcrashreporter-qt/CMakeLists.txt:10: 'find_package' is not a recognized test function.
$project_dir/libcrashreporter-qt/CMakeLists.txt:12: Opening parenthesis without prior test name.
$project_dir/libcrashreporter-qt/CMakeLists.txt:16: 'string' is not a recognized test function.
$project_dir/libcrashreporter-qt/CMakeLists.txt:17: 'string' is not a recognized test function.
$project_dir/libcrashreporter-qt/CMakeLists.txt:18: 'endif' is not a recognized test function.
$project_dir/libcrashreporter-qt/CMakeLists.txt:20: 'add_subdirectory' is not a recognized test function.
$project_dir/libcrashreporter-qt/CMakeLists.txt:21: 'add_subdirectory' is not a recognized test function.
CMake 文件内容 (注意,我稍微更改了文件,试图通过删除多行 if 语句来解决构建问题并注释了 option 行) :
project(libcrashreporter-qt)
cmake_minimum_required(VERSION 3.1)
if(POLICY CMP0071)
cmake_policy(SET CMP0071 NEW)
endif()
#option(ENABLE_GPL_CODE OFF)
find_package(Qt5 COMPONENTS Core Network Widgets)
if((CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_FLAGS) OR (UNIX AND NOT APPLE AND CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
# Breakpad uses GNU compiler extensions like typeof.
# Luckily these features are not used on OSX, so we can build the
# crashreporter there with the normal C++11 standard.
string(REPLACE "-std=c++11" "-std=gnu++11" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
string(REPLACE "-std=c++14" "-std=gnu++14" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
endif()
add_subdirectory(3rdparty)
add_subdirectory(src)
这让我相信 Qt .pro 文件兼容性和相互使用的 CMake 项目存在问题。
问题:
如何访问此 CMake 项目的库函数,并与我的项目一起编译它(即不更改 CMake 项目本身),或者如何最好地将 CMake 项目转换为兼容的 @987654332 @项目?
【问题讨论】:
-
qmake 和 cmake 是两种不同的技术,所以你不能加入它们。唯一的选择是为外部库创建一个 .pro / .pri。
标签: qt cmake qt5 qt-creator qmake