Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. CMake: how to instruct automoc to ignore certain files?
Forum Updated to NodeBB v4.3 + New Features

CMake: how to instruct automoc to ignore certain files?

Scheduled Pinned Locked Moved Qt Creator and other tools
8 Posts 2 Posters 4.4k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nemesis
    wrote on last edited by A Former User
    #1

    Hi fellow devs

    I'm using CMake (v. 3.4.3) for my C++ project (min. cmake version 3.0), and Qt 5.6.0. Some of my libraries are UI related, some not. For the UI-related ones, I'm getting errors in my files which do not define the Q_OBJECT macro (it must be like that, I don't need all files with Q_OBJECT). This is the error:

    Error: Class declaration lacks Q_OBJECT macro
    

    Does anyone have an idea of how to tell cmake not to run moc on these files without Q_OBJECT? I'm running a CentOS 7.2 machine, 64bit. Thanks for your time.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Are you talking about designer based widgets ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • N Offline
        N Offline
        nemesis
        wrote on last edited by
        #3

        Hi

        Thanks for answering. The UI layout I make in designer, and the functionality I implement in C++, normal stuff. But not all of my C++ classes need to be backed up by a widget.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          So if I understand correctly, you are removing the Q_OBJECT macro from your UI based widgets ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • N Offline
            N Offline
            nemesis
            wrote on last edited by
            #5

            No, it's the other way around. For UI-based widgets, I have the Q_OBJECT macro, for the other classes not.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Can you show your CMakeLists.txt and a sample class that triggers this problem ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • N Offline
                N Offline
                nemesis
                wrote on last edited by
                #7

                Sure, here they are. My apologies for not posting this earlier to save us both time.

                CMakeLists.txt (ignore the comments, they are from an old project)

                set (LIBNAME kissqt)
                
                file (GLOB HEADERS
                	  "*.h"
                	  "*.hpp")
                
                file (GLOB SOURCES "*.cpp")
                file (GLOB UI_FILES "*.ui")
                
                # Create named folders for the sources within the .vcproj
                # Empty name lists them directly under the .vcproj
                source_group("headers" FILES ${HEADERS})
                source_group("src" FILES ${SOURCES})
                source_group("ui" FILES ${UI_FILES})
                
                # Properties->C/C++->General->Additional Include Directories
                include_directories (.)
                include_directories (..)
                include_directories (/home/ksoft/Qt5.6.0/5.6/gcc_64/include/)
                
                set(CMAKE_AUTOMOC_RELAXED_MODE TRUE)
                
                find_package(Qt5Widgets)
                QT5_WRAP_CPP(tst_hdr_moc ${HEADERS})
                QT5_WRAP_UI(tst_form_hdr ${UI_FILES})
                set(CMAKE_INCLUDE_CURRENT_DIR ON)
                
                # Set Properties->General->Configuration Type to Dynamic Library(.dll)
                # Creates math.dll with the listed sources collected in the variables
                # Also adds sources to the Solution Explorer
                add_library(${LIBNAME} SHARED ${tst_hdr_moc} ${tst_form_hdr})
                
                set_target_properties(${LIBNAME} PROPERTIES 
                	AUTOMOC ON
                	AUTOUIC ON
                	DEFINE_SYMBOL "KISSQT_LIB"
                	OUTPUT_NAME ${LIBNAME}${LIB_END}
                	OUTPUT_NAME_DEBUG ${LIBNAME}${LIB_END_DEBUG}
                	OUTPUT_NAME_RELEASE ${LIBNAME}${LIB_END_RELEASE})
                
                # Set the library dependencies
                qt5_use_modules(${LIBNAME} Core Widgets Gui OpenGL Designer)
                
                # Creates a folder "libraries" and adds target project (math.vcproj) under it
                set_property(TARGET ${LIBNAME} PROPERTY FOLDER "lib")
                
                # Adds logic to INSTALL.vcproj to copy math.dll to the destination directory
                install (TARGETS ${LIBNAME}
                		 RUNTIME DESTINATION ${PROJECT_BINARY_DIR}/bin
                		 LIBRARY DESTINATION ${PROJECT_BINARY_DIR}/bin)
                
                

                and here the class

                #ifndef KQTDYNAMICINTERFACE_H
                #define KQTDYNAMICINTERFACE_H
                
                /*
                several forward declarations
                class CalcModule;
                etc...
                */
                
                class KQtDynamicInterface
                {
                public:
                	KQtDynamicInterface(CalcModule &module, QWidget *parent = 0);
                	virtual ~KQtDynamicInterface();
                	
                	/*
                	other methods
                		...
                	*/
                	
                protected:
                	/*
                	other methods
                		...
                	*/
                };
                
                #endif
                

                The error I get is this.

                kQtDynamicInterface.h:563: Error: Class declaration lacks Q_OBJECT macro.
                make[2]: *** [moc_kQtDynamicInterface.cpp] Error 1
                make[1]: *** [CMakeFiles/all] Error 2
                make: *** [all] Error 2
                07:13:42: The process "/usr/bin/make" exited with code 2.
                Error while building/deploying project 03-2017Linux (kit: Desktop)
                When executing step "Make"
                
                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  It's your use of QT5_WRAP_CPP which expect QObject based classes that triggers that error. Since you are using automoc, don't use QT5_WRAP_CPP.

                  There's also autouic IIRC.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved