Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing cmake's automoc on external header files without knowing their filenames
    primarykey
    data
    text
    <p>In essence I want to be able to moc header files that are not part of any target in cmake with the additional difficulty that I don't know the filenames of those headers.</p> <p>The actual project is quite complex and part of an automated build system. The following is an easy example. Consider a project structured like this:</p> <p>CMakeLists.txt <br> src/lib/source.cpp <br> src/lib/CMakeLists.txt <br> src/include/some_header.hpp # which is included in source.cpp <br> <br><br> Content of main CMakeLists.txt:</p> <pre><code>cmake_mimimum_required(VERSION 2.8.6) project("automoctest") add_subdirectory(src/lib) </code></pre> <p><br><br> Content of src/lib/CMakeLists.txt:</p> <pre><code>include_directories(${CMAKE_HOME_DIRECTORY}/src/include) find_package(Qt4 4.8 REQUIRED QtCore) include(UseQt4) include_directories(${CMAKE_CURRENT_BINARY_DIR}) add_library(foo SHARED source.cpp) target_link_libraries(foo ${QT_LIBRARIES}) set_target_properties(foo PROPERTIES AUTOMOC true) </code></pre> <p><br><br> Inside source.cpp the file some_header.hpp is included like this:</p> <pre><code>#include "some_header.hpp" </code></pre> <p><br><br> The Problem:<br> The file some_header.hpp includes a Q_OBJECT and has some signals, so moc needs to work its magic. But as the header is not inside the actual project the header will not get mocked. I don't even know the filename of some_header.hpp so I can't add it specifically to be mocked. Obviously AUTOMOC does not check the include_directories for mockable files even when a source file includes one of them.</p> <p>What I tried (unsuccessfully):</p> <ul> <li>use #include moc_some_header.cpp in source.cpp <br> as it is described in the cmake documentation. This leads to an error in which cmake complains that it could not find some_header{.h,.hpp,.hxx,.H}</li> <li>setting CMAKE_AUTOMOC_RELAXED_MODE to true. Even though it's not clear from the doc what this actually does. Made no difference anyway.</li> <li>setting AUTOMOC_MOC_OPTIONS to -Isrc/include or -I/path/to/project/src/include or -I${CMAKE_HOME_DIRECTORY}/src/include <br> Doesn't do anything that I could see.</li> </ul> <p>The great thing about AUTOMOC is that I don't need to know which files actually need to be mocked. In this case however I would need to know all the headers that might have a Q_OBJECT inside, that are included by my source files.</p> <p>Is there a way to tell AUTOMOC where exactly to look for mockable files?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload