[CMake] Ninja fails, Make succeeds...

David Cole david.cole at kitware.com
Wed Jun 27 08:21:40 EDT 2012


On Wed, Jun 27, 2012 at 2:59 AM, Rolf Eike Beer <eike at sf-mail.de> wrote:
>> 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?
>

I prefer add_custom_command build-time copying over configure_file
configure-time copying almost always.

I don't want to add to the (serial, non-parallelizable) CMake
configure time unnecessarily when I could be doing a "make -j 8" or a
ninja full-parallel build to achieve the same copy tasks 8x (or more!)
faster...

As a general rule of thumb, always defer things that take any
significant time to build-time when possible.

Just my opinion, but the custom command route is well proven when
dependencies are specified correctly in the CMakeLists files.


2 cents, :-)
David


>> 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
> --
>
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake


More information about the CMake mailing list