[CMake] Cannot add target-level dependencies to non-existent target

Parag Chandra parag at ionicsecurity.com
Tue Jun 30 10:35:30 EDT 2015


I’ve run into similar problems, but I think this is by design: CMake isn’t going to let you do anything to a target until that target exists. For me, it was pretty straightforward to adjust my CMakeLists to satisfy the requirement.

If you don’t want to split apart your macro, one thing you might try is checking for the existence of the target inside your macro, and then creating it if it doesn’t. Something like:

IF (NOT TARGET targetName)
ADD_LIBRARY(targetName ${sources} ${sources_no_pch} ${headers})
ENDIF ()

You would need additional parameters in your macro, which could make this pretty messy.


Parag Chandra
Senior Software Engineer, Mobile Team
Mobile: +1.919.824.1410

[https://www.ionicsecurity.com/IonicSigHz.png]<https://ionic.com>

Ionic Security Inc.
1170 Peachtree St. NE STE 400, Atlanta, GA 30309











From: Glenn Coombs <glenn.coombs at gmail.com<mailto:glenn.coombs at gmail.com>>
Reply-To: "glenn.coombs at gmail.com<mailto:glenn.coombs at gmail.com>" <glenn.coombs at gmail.com<mailto:glenn.coombs at gmail.com>>
Date: Tuesday, June 30, 2015 at 9:16 AM
To: cmake Mailing List <cmake at cmake.org<mailto:cmake at cmake.org>>
Subject: [CMake] Cannot add target-level dependencies to non-existent target

I am getting the error in the subject.  The code I have looks like this:

    if (PRE_COMPILED_HEADERS_FOUND)
        ADD_PRECOMPILED_HEADER(${header_pch} ${source_pch} sources systemc)
    endif()

    add_library(systemc ${sources} ${sources_no_pch} ${headers})

where the call to add_dependency is in the ADD_PRECOMPILED_HEADER macro and is adding a dependency on the systemc target about to be created on the next line.  I could split the macro into 2 and call one before the add_library and one after the add_library but that is rather messy.

At the point I try to add the dependency the target does not exist, but it is added shortly after.  Is this the way CMake is supposed to behave or should it only cause an error if the target doesn't exist at generate time ?

--
Glenn
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150630/3ddc6699/attachment-0001.html>


More information about the CMake mailing list