[CMake] Question about generate a source file during the build

Sébastien Barthélémy barthelemy at crans.org
Sun Feb 3 11:18:59 EST 2013


Hi Olaf,

Le 3 févr. 2013 14:03, "Olaf Peter" <ope-devel at gmx.de> a écrit :
> ---8<---
> project(coolcoding)
>
> # generate coolcoding's static lexer
> set(COOLCODING_BAR_HPP
${PROJECT_BINARY_DIR}/include/foo/io/coolcoding/coolcoding_bar.hpp)
>
> add_executable(generate_coolcoding_bar generate_coolcoding_bar.cpp)
>
> add_custom_command(
>    OUTPUT  ${COOLCODING_BAR_HPP}
>    COMMAND generate_coolcoding_bar ${COOLCODING_BAR_HPP}
>    )

You might want to add

DEPENDS generate_coolcoding_bar

to this command.

> add_custom_target(coolcoding_dfa DEPENDS ${COOLCODING_BAR_HPP})

I'm not sure why you need this.

> What is the recommended way the generate header not in the source-build
dir self (means where the generate_coolcoding_bar.cpp is placed)?

I do not know if it is the recommended way or not, but usually, my
generators take an input argument with the desired outup file path. You can
then easily pass that full path from cmake (in the add_custom_command).

Hope it helps
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20130203/d49cb541/attachment.htm>


More information about the CMake mailing list