我已经在多个子目录中重新组织了一个CMake Qt5项目,最终的文件夹结构如下所示:
├── 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
当我尝试编译整个项目时,问题就来了:实际上,编译器说它找不到ui文件的头文件(例如ui_main.h
和ui_sub.h
),这是错误消息:
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"
^~~~~~~~
这是我的CMakeLists.txt文件:
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)
如何指定这些标题UI文件的输出目录?
-编辑-
我已经添加了CMAKE_AUTOUIC_SEARCH_PATHS
属性,但没有成功,编译器仍然给了我同样的错误。
这是我添加到CMakeLists.txt中的内容:
set(CMAKE_AUTOUIC_SEARCH_PATHS "${PROJECT_SOURCE_DIR}/ui")