On macOS with Ninja generator, AUTOMOC fails with framework target dependency under CMake 3.9
Single project setup (see attached sample project cmake_macos_fw_test.zip):
- Homebrew toolchain/dependencies CMake 3.9.2 (and 3.8.2), Ninja 1.7.2, Qt 5.9.1
- On macOS 10.11.6, with Xcode 8.2.1
- Building a library as a macOS framework, e.g.
my_lib.framework
, with a target name ofmy_lib
- Building test executables, using AUTOMOC, that link to the framework, adding its dependency as
my_lib
Under CMake 3.8.2, no issues with _autogen
targets and Ninja.
Under CMake 3.9.2, errors with the following during generation:
ninja: error: 'output/lib/my_lib.framework/my_lib', needed by 'test/CMakeFiles/mylibtest_autogen', missing and no known rule to make it
I can work around the issue by adding the framework dependency using the $<TARGET_FILE:my_lib>
generator expression instead, which appears to overcome the now-missing rule for the my_lib.framework/<my_lib symlink>
byproduct of the framework build, but this seems unnecessary.
Another (quite clumsy) workaround is to add the my_lib.framework/<my_lib symlink>
byproduct to the framework's target using something like this:
if(CMAKE_GENERATOR MATCHES "Ninja" AND NOT "${CMAKE_VERSION}" VERSION_LESS "3.2")
# generate phony target for <binary output>/my_lib*.framework/<my_lib* symlink>
# (referenced by automoc _autogen targets)
add_custom_command(TARGET my_lib
PRE_LINK
COMMAND echo ""
BYPRODUCTS "output/lib/my_lib.framework/my_lib"
)
endif()
Seems to me this is a regression in 3.9.x (over 3.8.x), but I am unsure if it is with the framework's build generation (missing rule for the my_lib.framework/<my_lib symlink>
) or in the new AUTOMOC changes, where the my_lib
framework target is treated as if it was an IMPORT LOCATION (base symlink), instead of its versioned framework path.