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

Luis Díaz Más piponazo at gmail.com
Mon Oct 10 08:46:01 EDT 2016


Hi,

I just want to confirm that I have the same problem on Windows with the
Ninja generator. Even when I always use both keywords (debug & optimized)
in my *target_link_libraries *commands I still got a *ninja.build *file
that has bad $-escape characters.

I think that this problem is happening only when I tried to compile a
library twice (shared and static) and I tried to propagate the
*LINK_LIBRARIES* property from the shared library to the static one:

        add_library(mylib SHARED ${mylib_all_sources})
        add_library(mylib_static STATIC EXCLUDE_FROM_ALL ${mylib
_all_sources})

        target_link_libraries(mylib PUBLIC ${SOME_LIBS})
        target_link_libraries(mylib_static PUBLIC
$<TARGET_PROPERTY:mylib,LINK_LIBRARIES>)

Only in that situation is when I got the weird bad $-escape characters on
the ninja.build file. This is an example of the line with these problems:

  LINK_LIBRARIES = C:\myProject\buildRelease\bin64\library1.lib
  C:\myProject\buildRelease\bin64\library2.lib
  C:\myProject\libs\gmock.lib
  C:\myProject\libs\CGAL-vc120-mt-4.4.lib
  C:\myProject\libs\exiv2.lib
  C:\myProject\libs\ceres.lib
  ... // removing some lines
  $<$<NOT:$<CONFIG:DEBUG>>:C:/myProject\libs/CGAL-vc120-mt-4.4.lib>
  $<$<CONFIG:DEBUG>:C:/myProject\libs/CGAL-vc120-mt-gd-4.4.lib>
  ... // removing some lines
  $<$<NOT:$<CONFIG:DEBUG>>:C:/myProject\libs/exiv2.lib>
  $<$<CONFIG:DEBUG>:C:/myProject\libs/exiv2d.lib>
  $<$<NOT:$<CONFIG:DEBUG>>:C:/myProject\libs/ceres.lib>
  $<$<CONFIG:DEBUG>:C:/myProject\libs/ceres-debug.lib>
  ...
  kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib
oleaut32.lib uuid.lib comdlg32.lib advapi32.lib

I will try to create a minimum example to reproduce this issue.

Cheers,
Luis


2016-10-05 16:39 GMT+02:00 Luis Díaz Más <piponazo at gmail.com>:

> 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/20161010/1c025eae/attachment.html>


More information about the CMake mailing list