[CMake] Dependencies of generated files

Petr Kmoch petr.kmoch at gmail.com
Thu Feb 14 02:44:57 EST 2013


Hi Olaf.

You're missing a DEPENDS argument in your custom command to make
${foo_STATIC_LEXER_HPP} depend on ${foo_LEXER_HPP}. (Or, in your case,
MAIN_DEPENDENCY would probably be more appropriate).

Next, the custom target driving the lexer generation should depend on
its output, not its input - if no target requires a custom command's
output, that command is not run.

Finally, you don't need to set the dependency on
generate_foo_static_lexer - CMake does that automatically for
executable targets used in custom commands. Also, the GENERATED
property will be set by CMake.

In all, your CMakeList should look like this:

project(foo)

# generate foo's static lexer into the root of out-of-source build directory
set(foo_INCLUDE_PATH ${CMAKE_BINARY_DIR}/include/foo/io/foo)
set(foo_STATIC_LEXER_HPP ${foo_INCLUDE_PATH}/foo_static_lexer.hpp)
file(MAKE_DIRECTORY ${foo_INCLUDE_PATH})
set(foo_LEXER_HPP ${CMAKE_SOURCE_DIR}/include/foo/io/foo/lexer_impl.hpp)

add_executable(generate_foo_static_lexer generate_foo_static_lexer.cpp)
set_target_properties(generate_foo_static_lexer PROPERTIES
COMPILE_DEFINITIONS
"foo_LEXER_DYNAMIC_TABLES;BOOST_SPIRIT_LEXERTL_DEBUG")

add_custom_command(
   OUTPUT  ${foo_STATIC_LEXER_HPP}
   COMMAND generate_foo_static_lexer ${foo_STATIC_LEXER_HPP}
   MAIN_DEPENDENCY ${foo_LEXER_HPP}
   COMMENT "Generating foo static DFA lexer header ${foo_STATIC_LEXER_HPP}"
   )
add_custom_target(foo_dfa DEPENDS ${foo_STATIC_LEXER_HPP})

Hope this helps.

Petr

On Wed, Feb 13, 2013 at 7:20 PM, Olaf Peter <ope-devel at gmx.de> wrote:
>
> Hello,
>
> obviously I have a problem with the understanding of generating dependencies of generated files.
>
> generate_foo_static_lexer is using ${foo_LEXER_HPP} to generate a header file ${foo_STATIC_LEXER_HPP}. Each time ${foo_STATIC_LEXER_HPP} is changed the header shall be regenerated. Later, ${foo_STATIC_LEXER_HPP} can be more than one file (maybe list(xxx_HPP A;B;C)?? ).
>
> But this doesn't happen, only the exe is re-created. What's wrong?
>
> project(foo)
>
> # generate foo's static lexer into the root of out-of-source build directory
> set(foo_INCLUDE_PATH ${CMAKE_BINARY_DIR}/include/foo/io/foo)
> set(foo_STATIC_LEXER_HPP ${foo_INCLUDE_PATH}/foo_static_lexer.hpp)
> file(MAKE_DIRECTORY ${foo_INCLUDE_PATH})
> set(foo_LEXER_HPP ${CMAKE_SOURCE_DIR}/include/foo/io/foo/lexer_impl.hpp)
>
> add_executable(generate_foo_static_lexer generate_foo_static_lexer.cpp)
> set_target_properties(generate_foo_static_lexer PROPERTIES COMPILE_DEFINITIONS "foo_LEXER_DYNAMIC_TABLES;BOOST_SPIRIT_LEXERTL_DEBUG")
>
> add_custom_command(
>    OUTPUT  ${foo_STATIC_LEXER_HPP}
>    COMMAND generate_foo_static_lexer ${foo_STATIC_LEXER_HPP}
>    COMMENT "Generating foo static DFA lexer header ${foo_STATIC_LEXER_HPP}"
>    )
> add_custom_target(foo_dfa DEPENDS ${foo_LEXER_HPP})
> add_dependencies(foo_dfa generate_foo_static_lexer)
> set_source_files_properties(${foo_STATIC_LEXER_HPP} PROPERTIES GENERATED 1)
> --
>
> 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