Heads-up : automoc changes in CMake 3.8
Christophe Giboudeaux
christophe at krop.fr
Thu Apr 27 18:23:21 UTC 2017
Hi,
CMake 3.8 comes with a change that could break compilation under certain
circumstances.(*)
in CMake < 3.8, automoc'ed files are stored in <CMAKE_CURRENT_BINARY_DIR>.
Starting with CMake 3.8, they're now created in :
<CMAKE_CURRENT_BINARY_DIR>/<TARGETNAME>_autogen/include
What does it change ?
In most cases, nothing. moc files will be re-created.
The situation may be different when you invoke automoc manually and also
#include the file elsewhere.
Example in plasma-framework :
1/ src/plasmaquick/private/configcategory_p.cpp does:
#include "private/moc_configcategory_p.cpp"
2/ CMake creates
KF5PlasmaQuick_autogen/include/private/moc_configcategory_p.cpp as expected
3/ autotests/configmodeltest.cpp does:
#include "plasmaquick/private/configcategory_p.cpp
4/ build fails because private/moc_configcategory_p.cpp cannot be found when
building the autotests.
The solution :
the new moc files location is exported in the target's INCLUDE_DIRECTORIES
variable. you then have to add it to the $otherTarget's
target_include_directories' call
for this example, adding :
target_include_directories(${_testname} PRIVATE "$<BUILD_INTERFACE:
$<TARGET_PROPERTY:KF5PlasmaQuick,INCLUDE_DIRECTORIES>>;")
in autotests/CMakeLists.txt is enough.
i.e: tell <other target> to add <original target>'s INCLUDE_DIRECTORIES to
its -I parameters.
Christophe
(*) https://cmake.org/cmake/help/v3.8/release/3.8.html#other-changes
More information about the Kde-frameworks-devel
mailing list