[CMake] target_link_libraries <target> must have been created in the current directory?
abachrach at gmail.com
Thu Nov 29 11:05:18 EST 2012
In the cmake documentation for target_link_libraries() it says that:
> The named <target> must have been created in the current directory by a
> command such as add_executable or add_library.
Can someone provide a reason for that, and is there a work-around?
We have a large project that is composed of many smaller semi-independent
modules (each module builds one or more libraries and/or executables). Each
module contains its own CMakeLists.txt file which is added to the top level
project's CMakeLists.txt file with add_subdirectory(). Each module stores
the set of public libraries that it generates, allowing us to specify
dependencies between targets and modules (multiple targets).
However for this to work, the CMakeLists.txt in the module directory must
be parsed by cmake before the CMakeLists.txt of the target target.
Currently, we manually specify the order that modules get built, however
this is fragile and error prone.
The cleanest way that I have thought of to remedy this situation would be
to aggregate the target->module dependencies into a cached file, and then
parse this file as the last thing cmake does, calling
target_link_libraries() as needed. Unfortunately, this would require a
function that could call target_link_libraries() from a directory that is
different than the directory where the target was created :-/
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the CMake