2

I have re-organized a CMake Qt5 project in multiple subdirectory, the final folder structure looks like this:

├── CMakeLists.txt
├── headers
│   ├── a.h
│   ├── b.h
├── LICENSE
├── README.md
├── resources
│   ├── images
│   │   ├── img.png
│   └── res.qrc
├── sources
│   ├── main.cpp
│   ├── a.cpp
│   ├── b.cpp
└── ui
    ├── a.ui
    └── b.ui

The problems comes when i try to compile the whole project: in fact the compiler say that it cannot find headers ui files(e.g. ui_main.h and ui_sub.h), this is the error:

In file included from /home/vbm/test/headers/a.h:13,
             from /home/vbm/test/headers/b.h:14,
             from /home/vbm/test/sources/main.cpp:6:
/home/vbm/test/headers/a.h:12:10: fatal error: ui_a.h: No such file or directory
#include "ui_a.h"
         ^~~~~~~~

This is my CMakeLists.txt file:

cmake_minimum_required(VERSION 3.9)
project(test VERSION 0.1)

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

find_package(Qt5Widgets REQUIRED)
find_package(Qt5Core REQUIRED)

# Declaring files
set( SOURCES
     sources/main.cpp
     source/a.cpp
     source/b.cpp
)


set( HEADERS
     headers/a.h
     headers/b.h
)

set( UIS
     ui/a.ui
     ui/b.ui
)

set( RES
     resources/res.qrc
)


add_executable(test ${SOURCES} ${HEADERS} ${UIS} ${RES})
target_link_libraries(test Qt5::Widgets Qt5::Core)

How can i specify the output directory of those header UI files?

--EDIT--
I have already added the CMAKE_AUTOUIC_SEARCH_PATHS property without any success, the compiler still gave me the same error.

This is what i've added to the CMakeLists.txt: set(CMAKE_AUTOUIC_SEARCH_PATHS "${PROJECT_SOURCE_DIR}/ui")

beep
  • 1,057
  • 2
  • 11
  • 23
  • https://cmake.org/cmake/help/latest/prop_tgt/AUTOUIC.html – Trass3r Dec 13 '18 at 19:17
  • So there's https://cmake.org/cmake/help/latest/prop_tgt/AUTOGEN_BUILD_DIR.html#prop_tgt:AUTOGEN_BUILD_DIR – Trass3r Dec 13 '18 at 19:18
  • I guess it didn't find your .ui files in the first place though. Please check that and try moving the ui files to sources or set https://cmake.org/cmake/help/latest/prop_tgt/AUTOUIC_SEARCH_PATHS.html – Trass3r Dec 13 '18 at 23:12
  • Possible duplicate of [How to place header and ui file in different folders using autouic in cmake](https://stackoverflow.com/questions/40630820/how-to-place-header-and-ui-file-in-different-folders-using-autouic-in-cmake) – eyllanesc Dec 14 '18 at 00:59
  • @Trass3r i have tried to set the CMAKE_AUTOUIC_SEARCH_PATH to the "ui" folder(`set(CMAKE_AUTOUIC_SEARCH_PATH ui)`) but without any success. I also tried to move the ui files into the sources directory, but neither this solution has been helpful. – beep Dec 14 '18 at 14:19
  • There's an S missing in PATHS. If it's just a typo here did you try an absolute path? – Trass3r Dec 14 '18 at 14:24
  • @Trass3r It was a typo error(here), however it doesn't work...i also tried to specify the path with `"${PROJECT_SOURCE_DIR}/ui"` – beep Dec 14 '18 at 14:30
  • Maybe `--debug-output` or `--trace` can help. – Trass3r Dec 14 '18 at 23:32

0 Answers0