title: Cmake Library With Qt Object?
body: <p>I am trying to make a shared library that my other Qt projects can use. In the library I have a class that looks similar to this:</p>
  
  <pre><code>A.h
  
  class A : public QWidget
  {
      Q_OBJECT
  public:
      A(QWidget *parent = 0);
      ~A();
  
  protected:
      void overriddenQtFunc() Q_DECL_OVERRIDE; // Overriding a QtWidget function.
  
      // other variables and functions here...
  
  }
  
  A.cpp
  A::A(QWidget *parent):QWidget(parent){}
  A::~A(){}
  void A::overriddenQtFunc(){  // Custom implementation here...  }
  // Other function implementations.
  </code></pre>
  
  <p>My Cmake for the library looks as follows:</p>
  
  <pre><code>cmake_minimum_required(VERSION 3.0.2)
  set(LIB_NAME "TestLib")
  
  find_package(QT5Widgets)
  
  include_directories("includes") # Where my A.h file lives along with
                                  # my other custom library code.
  
  set(SRCS # Source list here)
  set(HDRS # Header list here)
  
  add_library(${LIB_NAME} ${SRCS} ${HDRS})
  
  target_include_directories(${LIB_NAME} PRIVATE ${Qt5Widgets_INCLUDE_DIRS})
  target_include_directories(${LIB_NAME} PUBLIC "includes")
  </code></pre>
  
  <p>Everything compiles and works ok when I take "Q_OBJECT" out of the class along with my overridden method. Otherwise when I want to compile with them, I get</p>
  
  <pre><code>LNK2001: unresolved external symbol "protected: virtual void __thiscall A::overriddenQtFunc(void)"
  </code></pre>
  
  <p>Is there something else I need to do to get it to link properly? Does it have something to do with my sources not being "moc"ed?</p>