<html>
  <head>
    <meta content="text/html; charset=ISO-8859-6"
      http-equiv="Content-Type">
    <link href="chrome://translator/skin/floatingPanel.css"
      type="text/css" rel="stylesheet">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix">On 29-Apr-13 23:27, Alexander Neundorf
      wrote:<br>
    </div>
    <blockquote cite="mid:201304292327.30500.a.neundorf-work@gmx.net"
      type="cite">
      <pre wrap="">On Monday 29 April 2013, Haroogan wrote:
</pre>
      <blockquote type="cite">
        <pre wrap="">Have a look at my post on StackOverflow
<a class="moz-txt-link-rfc2396E" href="http://stackoverflow.com/questions/16286872/cmake-automoc-feature-skips-sources-of-executable-targets">&lt;http://stackoverflow.com/questions/16286872/cmake-automoc-feature-skips-so
urces-of-executable-targets&gt;</a> for details.
<a class="moz-txt-link-rfc2396E" href="http://stackoverflow.com/questions/16286872/cmake-automoc-feature-skips-sources-of-executable-targets">&lt;http://stackoverflow.com/questions/16286872/cmake-automoc-feature-skips-so
urces-of-executable-targets&gt;</a>
</pre>
      </blockquote>
      <pre wrap="">
can you please create a small testcase and post it here, or create an entry on 
<a class="moz-txt-link-freetext" href="http://public.kitware.com/Bug">http://public.kitware.com/Bug</a> and attach it there ?

It should work.

Alex

</pre>
    </blockquote>
    I've found the cause, and I think that's very confusing behavior.
    I'll try to do my best explaining it.<br>
    <br>
    Let's begin with top 'CMakeLists.txt':<br>
    <br>
    <tt>...</tt><tt><br>
    </tt><tt><br>
    </tt><tt>set(CMAKE_INCLUDE_CURRENT_DIR ON)</tt><tt><br>
    </tt><tt>set(CMAKE_AUTOMOC ON)</tt><tt><br>
    </tt><tt><br>
    </tt><tt>...</tt><tt><br>
    </tt><tt></tt><br>
    <tt># NOTE: Order matters (the most independent ones go first)<br>
      # because some libraries expose variables through cache (see
      below).</tt><br>
    <tt>add_subdirectory(components/B)</tt><tt><br>
    </tt><tt>add_subdirectory(components/A)</tt><tt><br>
    </tt><tt><br>
    </tt><tt>add_subdirectory(components/Executable)</tt><br>
    <br>
    So imagine that we have the 'FindMyPrecious.cmake' custom CMake
    module to locate 3rd party framework "MyPrecious":<br>
    <br>
    <tt>find_package(Qt4</tt><tt><br>
    </tt><tt>             4.7.4</tt><tt><br>
    </tt><tt>             COMPONENTS QtCore</tt><tt><br>
    </tt><tt>                        QtGui</tt><tt><br>
    </tt><tt>                        QtXml</tt><tt><br>
    </tt><tt>             REQUIRED)</tt><tt><br>
    </tt><tt><br>
    </tt><tt>find_path(MyPrecious_INCLUDE_DIR</tt><tt> ...)</tt><tt><br>
    </tt><tt><br>
    </tt><tt>find_library(MyPrecious_LIBRARY_DEBUG</tt><tt> ...)</tt><tt><br>
    </tt><tt><br>
    </tt><tt>find_library(MyPrecious_LIBRARY_RELEASE</tt><tt> ...</tt><tt>)</tt><tt><br>
    </tt><tt><br>
    </tt><tt>set(QT_DEFINITIONS ${QT_DEFINITIONS}</tt><tt><br>
    </tt><tt>                   -DQT_CORE_LIB</tt><tt><br>
    </tt><tt>                   -DQT_GUI_LIB</tt><tt><br>
    </tt><tt>                   -DQT_XML_LIB)</tt><tt><br>
    </tt><tt><br>
    </tt><tt>if (CMAKE_BUILD_TYPE MATCHES [Dd][Ee][Bb][Uu][Gg])</tt><tt><br>
    </tt><tt>  set(QT_DEFINITIONS ${QT_DEFINITIONS}</tt><tt><br>
    </tt><tt>                     -DQT_DEBUG)</tt><tt><br>
    </tt><tt>else ()</tt><tt><br>
    </tt><tt>  set(QT_DEFINITIONS ${QT_DEFINITIONS}</tt><tt><br>
    </tt><tt>                     -DQT_NO_DEBUG)</tt><tt><br>
    </tt><tt>endif ()</tt><tt><br>
    </tt><tt><br>
    </tt><tt>set(MyPrecious_DEFINITIONS ${QT_DEFINITIONS})</tt><tt><br>
    </tt><tt><br>
    </tt><tt>set(MyPrecious_INCLUDE_DIRS ${MyPrecious_INCLUDE_DIR}</tt><tt><br>
    </tt><tt>                            ${QT_INCLUDE_DIR}</tt><tt><br>
    </tt><tt>                     </tt><tt><tt>       </tt>${QT_QTCORE_INCLUDE_DIR}</tt><tt><br>
    </tt><tt>                   </tt><tt><tt>       </tt> 
      ${QT_QTGUI_INCLUDE_DIR}</tt><tt><br>
    </tt><tt>                  </tt><tt><tt>       </tt>  
      ${QT_QTXML_INCLUDE_DIR})</tt><tt><br>
    </tt><tt><br>
    </tt><tt>set(</tt><tt><tt>MyPrecious</tt>_LIBRARY debug     ${</tt><tt><tt>MyPrecious</tt>_LIBRARY_DEBUG}</tt><tt><br>
    </tt><tt>                       optimized ${</tt><tt><tt>MyPrecious</tt>_LIBRARY_RELEASE})</tt><tt><br>
    </tt><tt><br>
    </tt><tt>set(</tt><tt><tt>MyPrecious</tt>_LIBRARIES ${</tt><tt><tt>MyPrecious</tt>_LIBRARY}</tt><tt><br>
    </tt><tt>                         ${QT_QTCORE_LIBRARY}</tt><tt><br>
    </tt><tt>                         ${QT_QTGUI_LIBRARY}</tt><tt><br>
    </tt><tt>                         ${QT_QTXML_LIBRARY})</tt><tt><br>
    </tt><tt><br>
    </tt><tt>include(FindPackageHandleStandardArgs)</tt><tt><br>
    </tt><tt><br>
    </tt><tt>find_package_handle_standard_args(</tt><tt>MyPrecious</tt><tt><br>
    </tt><tt>                                  DEFAULT_MSG</tt><tt><br>
    </tt><tt>                                  </tt><tt><tt>MyPrecious</tt>_INCLUDE_DIR</tt><tt><br>
    </tt><tt>                                  </tt><tt><tt>MyPrecious</tt>_LIBRARY</tt><tt><br>
    </tt><tt>                                  </tt><tt><tt>MyPrecious</tt>_LIBRARY_DEBUG</tt><tt><br>
    </tt><tt>                                  </tt><tt><tt>MyPrecious</tt>_LIBRARY_RELEASE)</tt><tt><br>
    </tt><tt><br>
    </tt><tt>mark_as_advanced(</tt><tt><tt>MyPrecious</tt>_INCLUDE_DIR</tt><tt><br>
    </tt><tt>                 </tt><tt><tt>MyPrecious</tt>_LIBRARY</tt><tt><br>
    </tt><tt>                 </tt><tt><tt>MyPrecious</tt>_LIBRARY_DEBUG</tt><tt><br>
    </tt><tt>                 </tt><tt><tt>MyPrecious</tt>_LIBRARY_RELEASE)</tt><br>
    <br>
    Everything is cool so far. One thing to note is that since
    "MyPrecious" depends on Qt we are employing transitive dependency
    strategy as recommended on CMake Wiki.<br>
    <br>
    Now let's move to the shared library "A" (from our project) which
    depends on "MyPrecious":<br>
    <br>
    <tt>cmake_minimum_required(VERSION 2.8.10)</tt><tt><br>
    </tt><tt><br>
    </tt><tt>project(A C CXX)</tt><tt><br>
    </tt><tt></tt><tt><tt></tt><br>
    </tt><tt>find_package(MyPrecious REQUIRED)</tt><tt><br>
    </tt><br>
    <tt>file(GLOB CPP_FILES sources/*.cpp)<br>
      <br>
    </tt><tt></tt><tt>add_definitions(${MyPrecious_DEFINITIONS}</tt><tt>)</tt><tt><br>
    </tt><tt><br>
    </tt><tt>include_directories(${B_INCLUDE_DIRS}</tt><tt><tt>                            
        # some other library B (in this case header-only)</tt>; B
      exposed includes with the same strategy<br>
    </tt><tt>                    ${MyPrecious_INCLUDE_DIRS})</tt><tt><br>
    </tt><tt><br>
    </tt><tt>add_library(${PROJECT_NAME} SHARED ${CPP_FILES})</tt><tt><br>
    </tt><tt><br>
    </tt><tt>target_link_libraries(${PROJECT_NAME}
      ${MyPrecious_LIBRARIES})</tt><tt><br>
    </tt><tt><br>
      # Pay attention here, we want to make definitions and includes
      visible (through cache) to the executable since it is going to
      link against this library A<br>
    </tt><tt>set(${PROJECT_NAME}_DEFINITIONS ${MyPrecious_DEFINITIONS}</tt><tt><br>
    </tt><tt>    CACHE INTERNAL "${PROJECT_NAME}: Definitions" FORCE)</tt><tt><br>
    </tt><tt><br>
    </tt><tt>set(${PROJECT_NAME}_INCLUDE_DIRS
      ${PROJECT_SOURCE_DIR}/includes</tt><tt><br>
    </tt><tt>                                 ${B_INCLUDE_DIRS}</tt><tt>               
      # some other library B (in this case header-only);</tt><tt><tt> B
        exposed includes with the same strategy</tt> <br>
    </tt><tt>                                 ${MyPrecious_INCLUDE_DIRS}</tt><tt><br>
    </tt><tt>    CACHE INTERNAL "${PROJECT_NAME}: Include Directories"
      FORCE)</tt><br>
    <br>
    Finally, let's move to the executable project:<br>
    <br>
    <tt>cmake_minimum_required(VERSION 2.8.10)</tt><tt><br>
    </tt><tt><br>
    </tt><tt>project(Executable C CXX)</tt><tt><br>
    </tt><tt><br>
    </tt><tt># -------------------------------<br>
      # ATTENTION: Theoretically, I don't have to add the line below.</tt><br>
    <tt><tt># -------------------------------</tt><br>
    </tt><tt># find_package(MyPrecious REQUIRED)</tt><tt><br>
      # -------------------------------</tt><tt><br>
      # Furthermore, as I said if I use plain old 'qt4_wrap_cpp', I
      don't add it and everything builds fine indeed.<br>
      # However, now when using 'AUTOMOC' approach it turns out that
      without this line CMake does not create 'AUTOMOC' target for
      sources of this project.<br>
      # The above line simply finds "MyPrecious", which you can see is
      not even used any further. I.e. all the definitions and includes
      of Qt, "MyPrecious", B, and A are<br>
      # obtained transitively through the cache variables (see
      below/above). However, we know that the above line finds Qt too.<br>
      # So the only logical thing that comes to my mind is that CMakes
      'AUTOMOC' feature works only when one explicitly or implicitly
      (like in this case) finds Qt (with `</tt><tt>find_package`)<br>
      # for the project which is desired to be 'AUTOMOC'ed. I have to
      admit that it's annoying, confusing, and counter-intuitive. Is
      this the intended behavior? Is this going to be fixed?<br>
      # -------------------------------<br>
    </tt><tt><br>
      file(GLOB CPP_FILES sources/*.cpp)<br>
      <br>
      # Pay attention here, we are utilizing the definitions and
      includes of library A (exposed earlier through cache).<br>
      # Furthermore, we now transitively and implicitly depend on Qt,
      "MyPrecious", and even B (since A depends on them).<br>
    </tt><tt>add_definitions(${A_DEFINITIONS})</tt><tt><br>
    </tt><tt><br>
    </tt><tt>include_directories(${A_INCLUDE_DIRS})</tt><tt><br>
    </tt><tt><br>
    </tt><tt>add_executable(${PROJECT_NAME} ${CPP_FILES})</tt><tt><br>
    </tt><tt><br>
    </tt><tt>target_link_libraries(${PROJECT_NAME} A)</tt><tt><br>
    </tt><br>
    The cause and the corresponding question are above (under the
    ATTENTION).<br>
    <div style="bottom: auto; left: 10px; right: auto; top: 588px;
      display: none;" class="translator-theme-default"
      id="translator-floating-panel">
      <div title="Click to translate"
        id="translator-floating-panel-button"></div>
    </div>
  </body>
</html>