2

I'm trying to build an exacutable which uses QObject so I have to use moc to generate metadata files. I have the following CMakeList:

PROJECT(dald)
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
CMAKE_POLICY(SET CMP0015 NEW)
###########################
# COMPILATION DEFINITIONS #
###########################
ADD_DEFINITIONS(-Wall -std=c++11)
#####################################
# INCLUDE USED MACROS AND FUNCTIONS #
#####################################
FILE(GLOB MODULES CMake/modules/*.cmake)
FOREACH(MODULE ${MODULES})
    INCLUDE(${MODULE})
ENDFOREACH(MODULE)
###########################
# ADD PROJECT DEFINITIONS #
###########################
SET(CPPUTEST CppUTest CppUTestExt)
SET(SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
SET(TESTS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tests)
SET(MOCKS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/mocks)
FILE(GLOB_RECURSE SRC src/*.cpp)
FILE(GLOB_RECURSE MOCKS mocks/*.cpp)
INCLUDE_DIRECTORIES(include)
##################
# CONFIGURE LIBS #
##################
SET(LIBS)
# Configure BOOST
SET(BOOST_MODULES thread system)
CONFIGURE_BOOST(${BOOST_MODULES})
# Configure Qt5
SET(QT5_MODULES Core DBus)
CONFIGURE_QT5("${QT5_MODULES}")
set(QT_HEADERS
    include/networkconfigendpoint.h
)
QT5_WRAP_CPP(MOC_SRCS ${QT_HEADERS})
######################
# TARGET DEFINITIONS #
######################
# Fake target add only to make the headers visible in Qt Creator
FILE(GLOB_RECURSE LibFiles "include/*.h")
ADD_CUSTOM_TARGET(headers SOURCES ${LibFiles})
# Fake target add only to make the headers visible in Qt Creator
FILE(GLOB_RECURSE SrcFiles "src/*.cpp")
ADD_CUSTOM_TARGET(sources SOURCES ${SrcFiles})
# Fake target add only to make the headers visible in Qt Creator
FILE(GLOB_RECURSE MocksFiles "mocks/*.cpp")
ADD_CUSTOM_TARGET(mocks SOURCES ${MocksFiles})
# executable
add_executable(dald ${SRC} ${MOC_SRCS})
TARGET_LINK_LIBRARIES(dald ${LIBS})

and the compilation output is as follows:

[ 20%] Generating include/moc_networkconfigendpoint.cpp
/bin/sh: 1: @/home/pawel/.CLion2016.1/system/cmake/generated/dal-1d1e3f88/1d1e3f88/Debug/include/moc_networkconfigendpoint.cpp_parameters: not found
CMakeFiles/dald.dir/build.make:61: command for object 'include/moc_networkconfigendpoint.cpp' 
make[2]: *** [include/moc_networkconfigendpoint.cpp] Error 127

The rsult of this cmake is only the moc_networkconfigendpoint.cpp_parameters file which contains:

-I/home/pawel/Downloads/dal/include
-I/home/pawel/Downloads/dal/include
-I/usr/include
-o
/home/pawel/Downloads/dal/build/include/moc_networkconfigendpoint.cpp
/home/pawel/Downloads/dal/include/networkconfigendpoint.h

Can anyone help with this? I've tried also to use SET(CMAKE_AUTOMOC ON) but in this case I've got no moc result and error when linking the nonexistent moc file.

===== PS. The body of CONFIGURE_QT5

FUNCTION(configure_qt5 QT5_MODULES)
    FOREACH(QT5_MODULE ${QT5_MODULES})
        FIND_PACKAGE(Qt5${QT5_MODULE})
        SET(LIB_NAME "Qt5::${QT5_MODULE}")
        LIST(APPEND LIBS ${LIB_NAME})
    ENDFOREACH(QT5_MODULE)
    SET(LIBS ${LIBS} PARENT_SCOPE)
    MESSAGE(STATUS "Configuring Qt5 - done")
ENDFUNCTION(configure_qt5)
PaulWebbster
  • 1,480
  • 2
  • 14
  • 27
  • Sorry I forget it. It's cmake function. I add it to original post. – PaulWebbster Jul 14 '16 at 12:06
  • 2
    Try to make automoc work (post the code and the error). It's not productive to be digging lots of cmake code when the whole Qt config can be done in 5-6 lines. Start from [there](http://stackoverflow.com/a/36181462/4742108). – Velkan Jul 14 '16 at 14:10

0 Answers0