cmake 2.8.12.2 AUTOUIC 不工作:错误或缺少功能?

cmake 2.8.12.2 AUTOUIC not working: bug or missing feature?

我正在使用 CMake 创建一个 Qt 项目ui。 在 macOS 或 Windows 上使用 cmake-3.8.2 一切正常。在 Ubuntu 14 上,我有 cmake-2.8.12.2,moc 是 运行,但 uic 不是 运行。 在 CMakeLists.txt 我有:

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)

和 .ui 文件未在任何地方指定(但与 class 相同,所以我有 SDFDialog.h、SDFDialog.cpp、SDFDialog.ui)

在 Ubuntu 14 上使用 cmake-2.8.12.2 这是输出:

$ cmake --build .
Scanning dependencies of target v_repExtSDF_automoc
[  4%] Automoc for target v_repExtSDF
Generating moc_SDFDialog.cpp
Generating moc_UIFunctions.cpp
Generating moc_UIProxy.cpp
[  4%] Built target v_repExtSDF_automoc
Scanning dependencies of target v_repExtSDF
[  8%] Building CXX object CMakeFiles/v_repExtSDF.dir/ImportOptions.cpp.o
[ 12%] Building CXX object CMakeFiles/v_repExtSDF.dir/SDFDialog.cpp.o
/home/user/Development/V-REP_PRO_EDU_V3_4_0_64_Linux.rev9/programming/v_repExtSDF/SDFDialog.cpp:4:26: fatal error: ui_SDFDialog.h: No such file or directory
 #include "ui_SDFDialog.h"
                          ^
compilation terminated.
make[2]: *** [CMakeFiles/v_repExtSDF.dir/SDFDialog.cpp.o] Error 1
make[1]: *** [CMakeFiles/v_repExtSDF.dir/all] Error 2
make: *** [all] Error 2

在 macOS 上使用 cmake-3.8.2 uic 是正确的 运行:

$ cmake --build .
Scanning dependencies of target v_repExtSDF_autogen
[  4%] Automatic MOC and UIC for target v_repExtSDF
Generating MOC source v_repExtSDF_autogen/EWIEGA46WW/moc_SDFDialog.cpp
Generating MOC source v_repExtSDF_autogen/EWIEGA46WW/moc_UIFunctions.cpp
Generating MOC source v_repExtSDF_autogen/EWIEGA46WW/moc_UIProxy.cpp
Generating MOC compilation v_repExtSDF_autogen/moc_compilation.cpp
Generating UIC header v_repExtSDF_autogen/include/ui_SDFDialog.h
[  4%] Built target v_repExtSDF_autogen
...

这是错误还是缺少功能? 如果它是一个缺失的功能,最低 required cmake 版本是多少? 是否有一些解决方法可以在 cmake-2.8.12.2 上也使 uic 运行 不改变 CMakeLists.txt 太多?

CMake 2.8.6 引入了 AUTOMOC 功能。 AUTOUIC 功能已由 CMake 3.0.x.

引入

因此,在 Windows 和 macOS 上,您可以使用它们,因为您拥有包含这两个功能的 CMake 版本。在 Ubuntu,您的 2.8.12 版本不支持 AUTOUIC,因此您无法使用它。

来源:https://cmake.org/cmake/help/v2.8.12/cmake.html

由于您的 Ubuntu 版本很旧,升级到下一个 LTS (16.04) 可能是个好主意。或者,您可以尝试安装更新的 CMake 版本:

感谢@vre 和@Antwane 提供的信息,我将此解决方法添加到我的 CMakeLists.txt 中,现在它也支持 CMake 2.8:

if(${CMAKE_VERSION} VERSION_LESS 3.0)
    qt5_wrap_ui(FORMS SDFDialog.ui)
    add_custom_target(uic_cmake28_compat ALL DEPENDS ${FORMS})
endif()

当 Ubuntu 14.04 生命周期结束时,我最终会摆脱这个解决方法。