title: Cmake and Qt5: Using different components of Qt5 in different subdirectories
body: <p>I want to use the Qt5 library in my subdirectories without adding the all components to each subdirectory. In the parent CMakeLists I use <code>find_package(Qt5)</code> to make sure that the library exists and the <code>Qt5_DIR</code> variable is set. Example:</p>
  
  <p><strong>CMakeLists.txt</strong>   </p>
  
  <pre><code>cmake_minimum_required(VERSION 3.0)
  
  find_package(Qt5 COMPONENTS Core REQUIRED)
  
  add_subdirectory(exec1)
  add_subdirectory(exec2) 
  </code></pre>
  
  <p>In the subdirectory <code>exec1</code> I want to use the <code>Qt5::Xml</code> component. As far as I have understood CMake, the <code>Qt5_DIR</code> variable is passed to the subdirectories. Therefore I do not have to use <code>find_package</code> again. Is this assumption correct? Example:</p>
  
  <p><strong>exec1/CMakeLists.txt</strong>   </p>
  
  <pre><code>project(exec1)
  set(SRC exec1.cpp)
  set(HDR exec1.h)
  
  add_executable(exec1 ${SRC} ${HDR})
  target_link_libraries(exec1 Qt5::Core Qt5::Xml)
  </code></pre>
  
  <p>In a second subdirectory <code>exec2</code> I want to add other components of Qt5. Example:</p>
  
  <p><strong>exec2/CMakeLists.txt</strong>   </p>
  
  <pre><code>project(exec2)
  set(SRC exec2.cpp)
  set(HDR exec2.h)
  
  add_executable(exec2 ${SRC} ${HDR})
  target_link_libraries(exec2 Qt5::Core Qt5::Websockets)
  </code></pre>
  
  <p>Does it make any difference if I add all components in the parent CMakeLists.txt instead of choosing for each subproject only some components?
  How do I handle this case so that I can exchange Qt5 components in the subdirectories without affecting other subdirectories?
  Or is it more convenient to add the <code>find_package</code> to each subdirectory instead of using it once in the parent CMakeLists.txt?</p>
  
  <p>Any suggestions and tipps are appreciated.</p>