MantisBT - CMake
View Issue Details
0015907CMakeCMakepublic2016-01-10 11:152016-05-02 08:30
Philippe 
Nils Gladitz 
normalminoralways
closedno change required 
LinuxDebianunstable
CMake 3.4.1 
 
0015907: [ninja] wrong dependency management with imported targets from external project or custom target
Here is a simple CMakeLists to reproduce my problem:

    # in my case, this line is actually an ExternalProject_Add
    add_custom_target(outfile COMMAND gcc ${CMAKE_CURRENT_SOURCE_DIR}/lib.c -shared -o liboutfile.so)

    add_library( mylib SHARED IMPORTED )
    set_property( TARGET mylib PROPERTY IMPORTED_LOCATION liboutfile.so )
    add_dependencies( mylib outfile )

    add_executable( testexe test.c )
    target_link_libraries( testexe mylib )

This ensures that before we try to link with the mylib target, the outfile target is built. Except it works only with the Unix Makefiles generator but not with the Ninja one.

With Ninja I get this error before it tries to do any work:

    ninja: error: 'liboutfile.so', needed by 'testexe', missing and no known rule to make it

I'm attaching a simple and complete test project to reproduce.
1. download and uncompress the attached testproj
2. configure with the Ninja generator
3. try build with ninja and get an error
No tags attached.
bz2 testproj.tar.bz2 (570) 2016-01-10 11:15
https://public.kitware.com/Bug/file/5604/testproj.tar.bz2
Issue History
2016-01-10 11:15PhilippeNew Issue
2016-01-10 11:15PhilippeFile Added: testproj.tar.bz2
2016-01-10 12:21Nils GladitzNote Added: 0040172
2016-01-10 12:35PhilippeNote Added: 0040173
2016-01-11 05:06Nils GladitzStatusnew => resolved
2016-01-11 05:06Nils GladitzResolutionopen => no change required
2016-01-11 05:06Nils GladitzAssigned To => Nils Gladitz
2016-05-02 08:30Robert MaynardNote Added: 0040997
2016-05-02 08:30Robert MaynardStatusresolved => closed

Notes
(0040172)
Nils Gladitz   
2016-01-10 12:21   
For Ninja you need to declare liboutfile.so a byproduct (BYPRODUCTS keyword in add_custom_command()).

ExternalProject_Add() supports this through the BUILD_BYPRODUCTS option.
(0040173)
Philippe   
2016-01-10 12:35   
Indeed, it works! Thank you. You can close this :)
(0040997)
Robert Maynard   
2016-05-02 08:30   
Closing resolved issues that have not been updated in more than 4 months.