[CMake] Error with ninja generator when using target_link_library with the debug keyword

Luis Díaz Más piponazo at gmail.com
Wed Oct 5 10:39:53 EDT 2016


Hi all,

I have found a problem while configuring a project and I want to share the
experience with you to figure out whether it is a known problem or a bug in
CMake.

In some cases I use the cmake command *target_link_libraries *specifying
different libraries for the *debug* and *optimized* modes. This normally
work as expected. However recently we got a problem with the Ninja
generator. This is what I could see in the console when I try to compile
the project:

ninja: error: build.ninja:4956: bad $-escape (literal $ must be written as
$$)


The content of the file in that particular line has something like this:

$<$<CONFIG:DEBUG>:/home/luis/xxxx//lib/libCGAL.so>

Examining my cmake configuration I noticed that a colleague introduced
something like that in the *target_link_libraries* call:

            ${ZLIB_LIBRARIES}
            debug;${CGAL_LIB}
            ${GMP_LIB}

If we specify the debug & optimized modes we do not have problems. However
in this particular case, it seems that we only need to link against the
CGAL in debug mode and not in release mode. Note that with a Make generator
we can compile normally the project.

The work around for this case is to link normally against CGAL when we are
in Debug mode:

        if (${CMAKE_BUILD_TYPE} STREQUAL Debug)
            target_link_libraries(myTarget ${CGAL_LIB}
        endif()

So ... the questions are:


   - Is it possible to use *target_link_libraries *only with one of the
   modes (debug  / optimized) ?
   - The Make generator works properly for this case. Could it be a bug
   with the Ninja generator? I tried with the most recent versions of CMake &
   Ninja.

Best regards,
Luis Diaz Mas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20161005/51c8f9c5/attachment.html>


More information about the CMake mailing list