使用CMAKE_AUTORCC始终重建rcc文件,因此始终链接项目

时间:2016-05-30 12:41:19

标签: qt cmake

使用cmake 3.5.0(在Windows上)和CMAKE_AUTORCC以及add_executable中的一个rcc.qrc文件,每次构建(使用ninja)都会编译rcc文件并再次链接,即使没有任何更改。这是正常的还是我的cmakelists.txt文件中缺少某些内容?

cmake_minimum_required(VERSION 3.2)
project(auto_moc_uic_rcc)

set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)

find_package (Qt5Widgets REQUIRED)

add_executable(${PROJECT_NAME}
  main.cpp
  MainWindow
  MainWindow.ui
  rcc.qrc
)

target_link_libraries(${PROJECT_NAME} Qt5::Widgets)

如果我删除CMAKE_AUTORCC并将其替换为qt5_add_resources(RCC rcc.qrc)并将${RCC}添加到可执行文件中,则项目仅在实际发生更改时才构建和链接。

cmake的输出(来自cmake_gui):

The C compiler identification is GNU 4.9.1
The CXX compiler identification is GNU 4.9.1
Check for working C compiler using: Ninja
Check for working C compiler using: Ninja -- works
Detecting C compiler ABI info
Detecting C compiler ABI info - done
Detecting C compile features
Detecting C compile features - done
Check for working CXX compiler using: Ninja
Check for working CXX compiler using: Ninja -- works
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Detecting CXX compile features
Detecting CXX compile features - done
Configuring done

首先运行ninja -v

[1/7] cmd.exe /C "cd /D E:\source\builds\qt\debug\Test\junk\auto_moc_uic_rcc\auto_moc_uic_rcc && E:\bin\cmake\bin\cmake.exe -E cmake_autogen E:/source/builds/qt/debug/Test/junk/auto_moc_uic_rcc/auto_moc_uic_rcc/CMakeFiles/auto_moc_uic_rcc_automoc.dir/ Debug"
Generating ui_MainWindow.h
Generating moc_MainWindow.cpp
[2/7] E:\Qt\mingw\bin\c++.exe   -DQT_CORE_LIB -DQT_GUI_LIB -DQT_WIDGETS_LIB -I. -IE:/source/src/Test/junk/autouic/auto_moc_uic-rcc -isystem E:/Qt/qt/include -isystem E:/Qt/qt/include/QtWidgets -isystem E:/Qt/qt/include/QtGui -isystem E:/Qt/qt/include/QtCore -isystem E:/Qt/qt/mkspecs/win32-g++ -g -MMD -MT CMakeFiles/auto_moc_uic_rcc.dir/CMakeFiles/auto_moc_uic_rcc.dir/qrc_rcc.cpp.obj -MF CMakeFiles/auto_moc_uic_rcc.dir/CMakeFiles/auto_moc_uic_rcc.dir/qrc_rcc.cpp.obj.d -o CMakeFiles/auto_moc_uic_rcc.dir/CMakeFiles/auto_moc_uic_rcc.dir/qrc_rcc.cpp.obj -c CMakeFiles/auto_moc_uic_rcc.dir/qrc_rcc.cpp
[3/7] E:\Qt\mingw\bin\c++.exe   -DQT_CORE_LIB -DQT_GUI_LIB -DQT_WIDGETS_LIB -I. -IE:/source/src/Test/junk/autouic/auto_moc_uic-rcc -isystem E:/Qt/qt/include -isystem E:/Qt/qt/include/QtWidgets -isystem E:/Qt/qt/include/QtGui -isystem E:/Qt/qt/include/QtCore -isystem E:/Qt/qt/mkspecs/win32-g++ -g -MMD -MT CMakeFiles/auto_moc_uic_rcc.dir/MainWindow.cpp.obj -MF CMakeFiles/auto_moc_uic_rcc.dir/MainWindow.cpp.obj.d -o CMakeFiles/auto_moc_uic_rcc.dir/MainWindow.cpp.obj -c E:/source/src/Test/junk/autouic/auto_moc_uic-rcc/MainWindow.cpp
[4/7] E:\Qt\mingw\bin\c++.exe   -DQT_CORE_LIB -DQT_GUI_LIB -DQT_WIDGETS_LIB -I. -IE:/source/src/Test/junk/autouic/auto_moc_uic-rcc -isystem E:/Qt/qt/include -isystem E:/Qt/qt/include/QtWidgets -isystem E:/Qt/qt/include/QtGui -isystem E:/Qt/qt/include/QtCore -isystem E:/Qt/qt/mkspecs/win32-g++ -g -MMD -MT CMakeFiles/auto_moc_uic_rcc.dir/main.cpp.obj -MF CMakeFiles/auto_moc_uic_rcc.dir/main.cpp.obj.d -o CMakeFiles/auto_moc_uic_rcc.dir/main.cpp.obj -c E:/source/src/Test/junk/autouic/auto_moc_uic-rcc/main.cpp
[5/7] cmd.exe /c
[6/7] E:\Qt\mingw\bin\c++.exe   -DQT_CORE_LIB -DQT_GUI_LIB -DQT_WIDGETS_LIB -I. -IE:/source/src/Test/junk/autouic/auto_moc_uic-rcc -isystem E:/Qt/qt/include -isystem E:/Qt/qt/include/QtWidgets -isystem E:/Qt/qt/include/QtGui -isystem E:/Qt/qt/include/QtCore -isystem E:/Qt/qt/mkspecs/win32-g++ -g -MMD -MT CMakeFiles/auto_moc_uic_rcc.dir/auto_moc_uic_rcc_automoc.cpp.obj -MF CMakeFiles/auto_moc_uic_rcc.dir/auto_moc_uic_rcc_automoc.cpp.obj.d -o CMakeFiles/auto_moc_uic_rcc.dir/auto_moc_uic_rcc_automoc.cpp.obj -c auto_moc_uic_rcc_automoc.cpp
[7/7] cmd.exe /C "cd . && E:\Qt\mingw\bin\c++.exe  -g   CMakeFiles/auto_moc_uic_rcc.dir/main.cpp.obj CMakeFiles/auto_moc_uic_rcc.dir/MainWindow.cpp.obj CMakeFiles/auto_moc_uic_rcc.dir/auto_moc_uic_rcc_automoc.cpp.obj CMakeFiles/auto_moc_uic_rcc.dir/CMakeFiles/auto_moc_uic_rcc.dir/qrc_rcc.cpp.obj  -o auto_moc_uic_rcc.exe -Wl,--out-implib,libauto_moc_uic_rcc.dll.a -Wl,--major-image-version,0,--minor-image-version,0  E:/Qt/qt/lib/libQt5Widgetsd.a E:/Qt/qt/lib/libQt5Guid.a E:/Qt/qt/lib/libQt5Cored.a -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."

第二轮ninja -v。连续运行具有相同的输出:

[1/3] cmd.exe /C "cd /D E:\source\builds\qt\debug\Test\junk\auto_moc_uic_rcc\auto_moc_uic_rcc && E:\bin\cmake\bin\cmake.exe -E cmake_autogen E:/source/builds/qt/debug/Test/junk/auto_moc_uic_rcc/auto_moc_uic_rcc/CMakeFiles/auto_moc_uic_rcc_automoc.dir/ Debug"
[2/3] E:\Qt\mingw\bin\c++.exe   -DQT_CORE_LIB -DQT_GUI_LIB -DQT_WIDGETS_LIB -I. -IE:/source/src/Test/junk/autouic/auto_moc_uic-rcc -isystem E:/Qt/qt/include -isystem E:/Qt/qt/include/QtWidgets -isystem E:/Qt/qt/include/QtGui -isystem E:/Qt/qt/include/QtCore -isystem E:/Qt/qt/mkspecs/win32-g++ -g -MMD -MT CMakeFiles/auto_moc_uic_rcc.dir/CMakeFiles/auto_moc_uic_rcc.dir/qrc_rcc.cpp.obj -MF CMakeFiles/auto_moc_uic_rcc.dir/CMakeFiles/auto_moc_uic_rcc.dir/qrc_rcc.cpp.obj.d -o CMakeFiles/auto_moc_uic_rcc.dir/CMakeFiles/auto_moc_uic_rcc.dir/qrc_rcc.cpp.obj -c CMakeFiles/auto_moc_uic_rcc.dir/qrc_rcc.cpp
[3/3] cmd.exe /C "cd . && E:\Qt\mingw\bin\c++.exe  -g   CMakeFiles/auto_moc_uic_rcc.dir/main.cpp.obj CMakeFiles/auto_moc_uic_rcc.dir/MainWindow.cpp.obj CMakeFiles/auto_moc_uic_rcc.dir/auto_moc_uic_rcc_automoc.cpp.obj CMakeFiles/auto_moc_uic_rcc.dir/CMakeFiles/auto_moc_uic_rcc.dir/qrc_rcc.cpp.obj  -o auto_moc_uic_rcc.exe -Wl,--out-implib,libauto_moc_uic_rcc.dll.a -Wl,--major-image-version,0,--minor-image-version,0  E:/Qt/qt/lib/libQt5Widgetsd.a E:/Qt/qt/lib/libQt5Guid.a E:/Qt/qt/lib/libQt5Cored.a -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."

当我使用ninja -v代替CMAKE_AUTORCC时,以下是qt5_add_resources(RCC rcc.qrc)的输出:

[1/8] cmd.exe /C "cd /D E:\source\builds\qt\debug\Test\junk\auto_moc_uic_rcc\auto_moc_uic && E:\bin\CMake\bin\cmake.exe -E cmake_autogen E:/source/builds/qt/debug/Test/junk/auto_moc_uic_rcc/auto_moc_uic/CMakeFiles/auto_moc_uic_automoc.dir/ """
Generating ui_MainWindow.h
Generating moc_MainWindow.cpp
[2/8] cmd.exe /C "cd /D E:\source\builds\qt\debug\Test\junk\auto_moc_uic_rcc\auto_moc_uic && E:\Qt\qt\bin\rcc.exe -name rcc -o E:/source/builds/qt/debug/Test/junk/auto_moc_uic_rcc/auto_moc_uic/qrc_rcc.cpp E:/source/src/Test/junk/autouic/auto_moc_uic/rcc.qrc"
[3/8] E:\Qt\mingw\bin\g++.exe   -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NO_DEBUG -DQT_WIDGETS_LIB -I. -IE:/source/src/Test/junk/autouic/auto_moc_uic -isystem E:/Qt/qt/include -isystem E:/Qt/qt/include/QtWidgets -isystem E:/Qt/qt/include/QtGui -isystem E:/Qt/qt/include/QtCore -isystem E:/Qt/qt/mkspecs/win32-g++  -MMD -MT CMakeFiles/auto_moc_uic.dir/MainWindow.cpp.obj -MF CMakeFiles/auto_moc_uic.dir/MainWindow.cpp.obj.d -o CMakeFiles/auto_moc_uic.dir/MainWindow.cpp.obj -c E:/source/src/Test/junk/autouic/auto_moc_uic/MainWindow.cpp
[4/8] E:\Qt\mingw\bin\g++.exe   -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NO_DEBUG -DQT_WIDGETS_LIB -I. -IE:/source/src/Test/junk/autouic/auto_moc_uic -isystem E:/Qt/qt/include -isystem E:/Qt/qt/include/QtWidgets -isystem E:/Qt/qt/include/QtGui -isystem E:/Qt/qt/include/QtCore -isystem E:/Qt/qt/mkspecs/win32-g++  -MMD -MT CMakeFiles/auto_moc_uic.dir/qrc_rcc.cpp.obj -MF CMakeFiles/auto_moc_uic.dir/qrc_rcc.cpp.obj.d -o CMakeFiles/auto_moc_uic.dir/qrc_rcc.cpp.obj -c qrc_rcc.cpp
[5/8] E:\Qt\mingw\bin\g++.exe   -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NO_DEBUG -DQT_WIDGETS_LIB -I. -IE:/source/src/Test/junk/autouic/auto_moc_uic -isystem E:/Qt/qt/include -isystem E:/Qt/qt/include/QtWidgets -isystem E:/Qt/qt/include/QtGui -isystem E:/Qt/qt/include/QtCore -isystem E:/Qt/qt/mkspecs/win32-g++  -MMD -MT CMakeFiles/auto_moc_uic.dir/main.cpp.obj -MF CMakeFiles/auto_moc_uic.dir/main.cpp.obj.d -o CMakeFiles/auto_moc_uic.dir/main.cpp.obj -c E:/source/src/Test/junk/autouic/auto_moc_uic/main.cpp
[6/8] cmd.exe /c
[7/8] E:\Qt\mingw\bin\g++.exe   -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NO_DEBUG -DQT_WIDGETS_LIB -I. -IE:/source/src/Test/junk/autouic/auto_moc_uic -isystem E:/Qt/qt/include -isystem E:/Qt/qt/include/QtWidgets -isystem E:/Qt/qt/include/QtGui -isystem E:/Qt/qt/include/QtCore -isystem E:/Qt/qt/mkspecs/win32-g++  -MMD -MT CMakeFiles/auto_moc_uic.dir/auto_moc_uic_automoc.cpp.obj -MF CMakeFiles/auto_moc_uic.dir/auto_moc_uic_automoc.cpp.obj.d -o CMakeFiles/auto_moc_uic.dir/auto_moc_uic_automoc.cpp.obj -c auto_moc_uic_automoc.cpp
[8/8] cmd.exe /C "cd . && E:\Qt\mingw\bin\g++.exe     CMakeFiles/auto_moc_uic.dir/main.cpp.obj CMakeFiles/auto_moc_uic.dir/MainWindow.cpp.obj CMakeFiles/auto_moc_uic.dir/qrc_rcc.cpp.obj CMakeFiles/auto_moc_uic.dir/auto_moc_uic_automoc.cpp.obj  -o auto_moc_uic.exe -Wl,--out-implib,libauto_moc_uic.dll.a -Wl,--major-image-version,0,--minor-image-version,0  E:/Qt/qt/lib/libQt5Widgets.a E:/Qt/qt/lib/libQt5Gui.a E:/Qt/qt/lib/libQt5Core.a -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."

连续跑步:

[1/1] cmd.exe /C "cd /D E:\source\builds\qt\debug\Test\junk\auto_moc_uic_rcc\auto_moc_uic && E:\bin\CMake\bin\cmake.exe -E cmake_autogen E:/source/builds/qt/debug/Test/junk/auto_moc_uic_rcc/auto_moc_uic/CMakeFiles/auto_moc_uic_automoc.dir/ """

0 个答案:

没有答案