Important: Please read the Qt Code of Conduct -

CMake QT5_WRAP_UI issue

  • Hi all,

    I am trying to make a transition from QMake based build system to CMake one.
    So far everything worked quite okish but I run onto the problem I am unable to solve.

    I do have UI file which I need to be processed and appropriate header file generated. This is usually done by UIC.exe and its kind of automatic in QMake.

    Now I am having a CMakeLists.txt file as follows (more or less, I have simplified it):

    cmake_minimum_required (VERSION 2.8.11)
    project (WorkspacePlugin)
    set (SOURCES
    set (HEADERS
    set (UIS
    find_package (Qt5Core)
    find_package (Qt5Gui)
    find_package (Qt5Widgets)
    target_link_libraries (${PROJECT_NAME} CorePlugin Qt5::Core Qt5::Gui Qt5::Widgets)

    Now, while building the project I do get the following error:

    [ 92%] Generating ui_AddConfiguration.h
    	cd D:\Projects\CPP\Builds\EGETools-Desktop_Qt_5_8_0_MSVC2015_64bit-Debug\EditorPlugins\WorkspacePlugin
    	o D:/Projects/CPP/Builds/EGETools-Desktop_Qt_5_8_0_MSVC2015_64bit-Debug/EditorPlugins/WorkspacePlugin/ui_AddConfiguration.h D:/Projects/CPP/EGETools/EditorPlugins/WorkspacePlugin/Implementation/AddConfiguration.ui
    'o' is not recognized as an internal or external command,
    operable program or batch file.

    I have looked into generated make file and I have found the following rule generated for it:

    EditorPlugins\WorkspacePlugin\ui_AddConfiguration.h: D:\Projects\CPP\EGETools\EditorPlugins\WorkspacePlugin\Implementation\AddConfiguration.ui
    	@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --blue --bold --progress-dir=D:\Projects\CPP\Builds\EGETools-Desktop_Qt_5_8_0_MSVC2015_64bit-Debug\CMakeFiles --progress-num=$(CMAKE_PROGRESS_2) "Generating ui_AddConfiguration.h"
    	cd D:\Projects\CPP\Builds\EGETools-Desktop_Qt_5_8_0_MSVC2015_64bit-Debug\EditorPlugins\WorkspacePlugin
    	-o D:/Projects/CPP/Builds/EGETools-Desktop_Qt_5_8_0_MSVC2015_64bit-Debug/EditorPlugins/WorkspacePlugin/ui_AddConfiguration.h D:/Projects/CPP/EGETools/EditorPlugins/WorkspacePlugin/Implementation/AddConfiguration.ui
    	cd D:\Projects\CPP\Builds\EGETools-Desktop_Qt_5_8_0_MSVC2015_64bit-Debug

    It can be seen that in that rule '-o' is used rather than plain 'o'. Though I am not sure if that even means anything.

    Does anyone happen to know what the problem is here and how to solve it ?

    Thanks in advance

    PS my environment is: Windows 10 x64, QtCreator 4.2.1, Qt 5.8.0, CMake 3.8.2

  • Lifetime Qt Champion


    Since you have a recent version of CMake, there's also CMAKE_AUTOUIC that should make your life easier but you will have to change the minimum cmake requirement.

    See this Wiki entry for more details.

  • @SGaist Yes indeed there is. And that one seems to be working fine. However, it requires UI file to be next to the ones which do include generated headers (implementation files in my case). I do want to keep them separately from the source files.

  • Ok. I have found the issue.

    Since QT5_WRAP_UI macro is delivered as part of Qt5Widget packacge it is necessery to make a call to find_package (Qt5Widget) before issuing QT5_WRAP_UI call.

    Ehh :D

  • I'm having the exact same problem and I resorted to a ugly hack of calling

    SET(Qt5Widgets_UIC_EXECUTABLE "uic")

    before calling QT5_WRAP_UI

    I don't know why but the value of Qt5Widgets_UIC_EXECUTABLE comes up as empty string (or unset)