Search code examples
c++qtcmakeqt5moc

CMake Automoc Error 1 - Can't compile project


I just moved a project I built in Qt5 into my CMake project tree. I exported the project in the CMake directory. However as I try to build the project the compiler gives me the following error: [src/GUIconceptStudy/CMakeFiles/GUIconceptStudy_automoc] Error 1

See also the following print screen attached: Automoc Error 1

Also the CMakeLists.txt files is below:

cmake_minimum_required (VERSION 3.1)
project(GUIconceptStudy)

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

find_package( OpenCV REQUIRED )
find_package( Boost COMPONENTS system thread filesystem REQUIRED)

#find_package (sqlite3)
find_package(Qt5 REQUIRED COMPONENTS Core Quick)

###
### make sure we use c++11
###
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

###
###boost include stuff (required for all libcam)
###
INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIR} )

find_package(Qt5Widgets)
find_package(Qt5PrintSupport)
#find all the qt UI stuff
file(GLOB UI
    "ui/*.ui"
)

#make them into headers
qt5_wrap_ui (UI_HDRS  ${UI})

###
### add all your non QT sources
###

# find all non ui sources
file(GLOB SRCS
    "src/*.h"
    "src/*.cpp"
    "src/*.hpp"
)

# find all ui related sources
file(GLOB UI_SRCS
    "ui/*.h"
    "ui/*.cpp"
    "ui/*.hpp"
)

###
### Add executables
###
add_executable(GUIconceptStudy main/main.cpp ui/qrc/res.qrc ${SRCS} ${UI_HDRS} ${UI_SRCS})
target_link_libraries (GUIconceptStudy  Qt5::Widgets  ${Boost_LIBRARIES} ${OpenCV_LIBS} Qt5::PrintSupport Qt5::Core Qt5::Quick)

###
### Add Library
###
add_library(GUIconceptStudy_lib SHARED ui/qrc/res.qrc ${SRCS} ${UI_HDRS} ${UI_SRCS})
target_link_libraries (GUIconceptStudy_lib Qt5::Widgets  ${Boost_LIBRARIES} ${OpenCV_LIBS} Qt5::PrintSupport Qt5::Core Qt5::Quick)

After looking at different on-line sources I could't find anything particularly useful. Anyone who can shed a little bit of light on what the problem could be?


Solution

  • It's a shot in a dark but this is most likely caused by the missing set(CMAKE_INCLUDE_CURRENT_DIR ON). As said in the documentation it needs to be enabled because generated files are located outside of your source directory:

    Generated moc_*.cpp and *.moc files are placed in the build directory so it is convenient to set the CMAKE_INCLUDE_CURRENT_DIR variable.

    Another mistake I see people making is mixing Qt processing pipelines. I've mentioned this already in my other answers. As it says in documentation on AUTOUIC property you shouldn't use qt5_wrap_ui function when this property is enabled.