[CMake] Help Accommodating Ninja when including CMAKE_CURRENT_BINARY_DIR

Stephen McDowell sjm324 at cornell.edu
Sat Apr 28 05:02:41 EDT 2018


​After much deliberation, I was never successful in getting a synthetic
target to work as expected.  The dilemma is that `add_custom_command`
cannot specify both `TARGET` and `OUTPUT`, the work flow was something like

add_custom_target(resource-dependency)
add_custom_command(TARGET resource-dependency ... PRE_BUILD)
add_custom_command(OUTPUT <files that are generated> DEPENDS
resource-dependency)
...
add_library(actual-obj-library OBJECt <files that are generated> ... others
...)
add_dependencies(actual-obj-library resource-dependency)

I'm sure that's a flawed approach, but in the end I realized I can actually
generate these files at *configure* time <3  The add_custom_command was
just a call to ${CMAKE_COMMAND} ... resources/bin2c.cmake.  So in the end,
it's actually a lot cleaner for us to just include(resources/bin2c.cmake).

I doubt this solution will be widely applicable to many projects, but if
you ever find yourself in a situation where you are doing
add_custom_command, where the custom command is calling ${CMAKE_COMMAND},
don't rely on PRE_BUILD because it's not a guarantee.  If you can, just
execute the script at configure time via an include(...) call.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20180428/177a7f0a/attachment-0001.html>


More information about the CMake mailing list