[CMake] Ninja fails, Make succeeds...

Rolf Eike Beer eike at sf-mail.de
Wed Jun 27 02:59:01 EDT 2012


> Sigh, now I sent you the code from the wrong directory, but the code for
> the "Backend" component is virtually identical.  I don't know how to use
> functions with CMake, so I simply made a verbatim copy of the below code
> in
> each subfolder and edited it to match the subfolder.  So the Backend
> project looks like this:
>
> project(Backend)
>
> set(PublicHeaders
>     "Backend.hpp"
>     "Context.hpp"
> )
> set(PublishedHeaders "")
> foreach(Header IN LISTS PublicHeaders)
>     get_filename_component(HeaderFilename "${Header}" NAME)
>     set(Source "${CMAKE_CURRENT_SOURCE_DIR}/${Header}")
>     set(Output "${CMAKE_CURRENT_BINARY_DIR}/${HeaderFilename}")
>     list(APPEND PublishedHeaders "${Output}")
>     add_custom_command(
>         OUTPUT "${Output}"
>         COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${Source}"
> "${Output}"
>         MAIN_DEPENDENCY "${Source}"
>         COMMENT "Publishing ${HeaderFilename}"
>         VERBATIM
>     )

Why don't you simply use configure_file(... COPYONLY) here?

> endforeach()
> add_custom_target(
>     publish_backend_headers
>     ALL
>     DEPENDS ${PublishedHeaders}
>     SOURCES ${PublicHeaders}
> )
> include_directories("${CMAKE_BINARY_DIR}/../")

This is almost certainly wrong. Guess my build dir is /tmp/foo, why on
earth do you want to include /tmp? I could understand if it would be
${CMAKE_CURRENT_BINARY_DIR}/.. if you are in a subdirectory, but otherwise
this is likely completely bogus.

> include_directories("$ENV{LLVM}/include")
>
> add_definitions(-D__STDC_CONSTANT_MACROS)
> add_definitions(-D__STDC_LIMIT_MACROS)
>
> add_library(Backend
>     "Backend.cpp"
> )
>
> add_dependencies(Backend publish_backend_headers)

I think you can avoid the whole add_custom_target/add_library by just writing

add_library(Backend Backend.cpp ${PublishedHeaders})

(Untested. May only reliably work if you use configure_file. ymmv).

Eike


More information about the CMake mailing list