Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

automoc usage in cmake



  • Hi,

    I am using qt for one of my project. So My CMakeLists look like this. I removed some lines from this cmakelists which i shared because i felt that is not relevant to this particular problem.
    So I am using uic_dummy.h in the sources list which contains qt related objects.the reason for not using set(CMAKE_AUTOUIC ON) is because we lost the ui file and so for the time being we are using that header file generated by uic compiler. I am also currently working to recreate ui by going through this header.

    set (CMAKE_CXX_STANDARD 11)
    include(FetchContent)
    
    find_package(Qt5Core CONFIG REQUIRED)
    find_package(Qt5Widgets)
    
    set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--export-all-symbols")
    set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
    
    find_package(Eigen3 CONFIG REQUIRED HINTS ${CMAKE_SOURCE_DIR}/libs/eigen/share/eigen3/cmake)
    set(OpenCV_STATIC ON)
    find_package(OpenCV CONFIG REQUIRED HINTS ${CMAKE_SOURCE_DIR}/libs/opencv)
    
    
    # include directories
    include_directories(inc)
    include_directories(${CMAKE_BINARY_DIR})
    include_directories(${OpenCV_INCLUDE_DIRS})
    include_directories(${EIGEN3_INCLUDE_DIR})
    # specify target
    set(TARGET_NAME dummy)
    set (TARGET_SOURCES
      inc/uic_dummy.h
      inc/dummy.h
      inc/stdafx.h
            src/moc_dummy.cpp 
    	src/dummy.cpp
    	src/stdafx.cpp
    )
    
    target_link_libraries(${TARGET_NAME} PRIVATE Qt5::Widgets tinyxml2::tinyxml2 ${OpenCV_LIBS})
    

    In my case dummy class is declared in dummy.h and the definition of it is given in dummy.cpp. I am using #include"moc_dummy.cpp" in dummy.cpp for build time optimization things.

    Given "dummy.h" and "dummy.cpp", and a project managed by cmake, the build system should direct moc to generate output like:
    moc_dummy.cpp from dummy.h, iff dummy.h contains Q_OBJECT macro.

    and in dummy.h contains Q_Object Macro.

    So i am currently using moc_dummy.cpp in dummy.cpp by #include"moc_dummy.cpp". I wanted to do like this because in dummy.cpp i have a funciton where i am using connect function (connecting signals and slots) so i need to have moc included in this file.

    so now my question is , Since i have moc file which is already created/used by someone and if i include that moc file its working properly but i wanted to generate moc file everytime when we build and then automatically do something like #include"moc_dummy.cpp".

    The reason to do this kind of things because i planned to change a bit few things so i am trying to fix this first.

    Please pardon me if my question misses some clarity. I tried my best to give more clarity. If you are missing some clarity i will try to develop my question based on your comments.
    Please also ignore question title as i didnt get much better title

    Any help is much appreciated.


  • Lifetime Qt Champion


  • Lifetime Qt Champion



  • @jsulm Thanks for the reply. I alreay tried by seeing this manual. May be i might also done wrong. But i will let you know what i have done.

    In CMakeLists.txt i made few changes which can be seen below

    set (CMAKE_CXX_STANDARD 11)
    include(FetchContent)
    
    find_package(Qt5Core CONFIG REQUIRED)
    find_package(Qt5Widgets)
    
    set(CMAKE_AUTOMOC ON)
    
    set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--export-all-symbols")
    set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
    
    find_package(Eigen3 CONFIG REQUIRED HINTS ${CMAKE_SOURCE_DIR}/libs/eigen/share/eigen3/cmake)
    set(OpenCV_STATIC ON)
    find_package(OpenCV CONFIG REQUIRED HINTS ${CMAKE_SOURCE_DIR}/libs/opencv)
    
    
    # include directories
    include_directories(inc)
    include_directories(${CMAKE_BINARY_DIR})
    include_directories(${OpenCV_INCLUDE_DIRS})
    include_directories(${EIGEN3_INCLUDE_DIR})
    # specify target
    set(TARGET_NAME dummy)
    set (TARGET_SOURCES
      inc/uic_dummy.h
      inc/dummy.h
      inc/stdafx.h
    	src/dummy.cpp
    	src/stdafx.cpp
    )
    
    target_link_libraries(${TARGET_NAME} PRIVATE Qt5::Widgets tinyxml2::tinyxml2 ${OpenCV_LIBS})
    

    and in my dummy.cpp i used like this

    #include "stdafx.h"
    #include "moc_dummy.cpp"
    #include <string>
    #include <ctime>
    

    and the error comes like

    AutoMoc error
    2>  -------------
    2>  "SRC:/dummy/src/dummy.cpp"
    2>  includes the moc file "moc_dummy.cpp",
    2>  but a header "dummy.{h,hh,h++,hm,hpp,hxx,in,txx}"
    2>  could not be found in the following directories
    2>    "SRC:/dummy/src"
    2>    "SRC:/dummy/inc"
    2>    "BIN:"
    2>    "SRC:/libs/eigen/include/eigen3"
    2>    "SRC:/libs/opencv/include"
    2>    "C:/ADTF/3.3.3/pkg/adtffiltersdk/include"
    2>    "C:/ADTF/3.3.3/pkg/a_utils/include"
    2>    "C:/ADTF/3.3.3/pkg/adtfucom3/include"
    2>    "C:/ADTF/3.3.3/pkg/adtfbase/include"
    2>    "C:/ADTF/3.3.3/pkg/adtfstreaming3/include"
    2>    "C:/ADTF/3.3.3/pkg/adtfsystemsdk/include"
    2>    "C:/ADTF/3.3.3/pkg/adtfmediadescription/include"
    2>    "C:/ADTF/3.3.3/pkg/adtfddl/include"
    2>    "C:/ADTF/3.3.3/pkg/adtfremotesdk/include"
    2>    "C:/ADTF/3.3.3/pkg/adtfrpc/include"
    2>    "C:/ADTF/3.3.3/pkg/easy_profiler/include"
    2>    "C:/Qt/5.12.2/msvc2015_64/include"
    2>    "C:/Qt/5.12.2/msvc2015_64/include/QtWidgets"
    2>    "C:/Qt/5.12.2/msvc2015_64/include/QtGui"
    2>    "C:/Qt/5.12.2/msvc2015_64/include/QtANGLE"
    2>    "C:/Qt/5.12.2/msvc2015_64/include/QtCore"
    2>    "C:/Qt/5.12.2/msvc2015_64/mkspecs/win32-msvc"
    2>    "SRC:/libs/tinyxml2/include"
    2>    "C:/ADTF/3.3.3/pkg/adtfui/include"
    

    From the error file i can say that it couldnt find dummy.h but dummy.h is there.So I am currently seeing what i have done wrong. Like checking paths and such things because from the error i can find this info only.



  • @aravmadd @jsulm My mistake. Spell error in one of the header files. The reason for popping out this error is i named one of the header file as dumy.h instead of dummy.h


Log in to reply