title: Qt5 with CMake not compiling .ui file when related source files are put into a library
body: <p>I am trying to compile a Qt5 project with multiple subdirectories with CMake. Some of the Qt .ui file related code is compiled as library using <code>add_library</code> command. I found that the <code>ui_*.h</code> header file is not compiled with <code>uic</code> at all. But if I put .ui related sources files in <code>add_executable</code>, then the <code>ui_*.h</code> file is automatically generated. Here I provided a sample project that helps demonstrate this problem. The entire zipped project file can be accessed through <a href="https://www.dropbox.com/s/q2i9imexhjarsbf/qt5-cmake.zip?dl=0" rel="nofollow">https://www.dropbox.com/s/q2i9imexhjarsbf/qt5-cmake.zip?dl=0</a>. The CMakeLists.txt file is shown below. I know there are other posts related to <code>ui_*.h</code> files not generated, but they don't seem to have a answer that can solve my problem.</p>
  
  <pre><code>cmake_minimum_required(VERSION 2.8.11)
  
  project(helloworld)
  
  # Find includes in the build directories
  set(CMAKE_INCLUDE_CURRENT_DIR ON)
  
  # Turn on automatic invocation of the MOC
  set(CMAKE_AUTOMOC ON)
  
  
  # Add a compiler flag
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
  
  # Find the QtWidgets library
  find_package(Qt5Widgets REQUIRED)
  
  # Generate code from ui files
  qt5_wrap_ui(UI_HEADERS mainwindow.ui)
  
  # Generate rules for building source files from the resources
  qt5_add_resources(QRCS resources.qrc)
  
  add_library(window mainwindow.cpp)
  target_link_libraries(window Qt5::Widgets)
  # Tell CMake to create the helloworld executable
  #add_executable(helloworld main.cpp mainwindow.cpp ${UI_HEADERS} ${QRCS})
  add_executable(helloworld main.cpp ${UI_HEADERS})
  
  # Add the Qt5 Widgets for linking
  target_link_libraries(helloworld window Qt5::Widgets)
  </code></pre>