[CMake] Visual Studio generator running custom_command twice

frodak17 frodak17 at gmail.com
Thu Mar 14 12:53:09 EDT 2019


On Thu, Mar 14, 2019 at 1:13 AM Paul Smith <paul at mad-scientist.net> wrote:

> I have a situation where I've created a custom command to generate .cpp
> files to be compiled (in my case running bison/flex).
>
> I'm using CMake 3.13.4
>
>   set(MyParserOutput
>       ${OUT_DIR}/MyParser.tab.cpp
>       ${OUT_DIR}/MyParser.tab.hpp)
>
>   add_custom_target(MyGenParser DEPENDS ${MyParserOutput})
>
> Then I have two different libraries, both depending on this:
>
>   add_library(OneLib STATIC ${MyParserOutput} ...)
>   add_dependencies(OneLib MyGenparser)
>
>
>   add_library(TwoLib STATIC ${MyParserOutput} ...)
>   add_dependencies(TwoLib MyGenparser)
>
>
> From add_custom_command()
Do not list the output in more than one independent target that may build
in parallel or the two instances of the rule may conflict (instead use the
add_custom_target()
<https://cmake.org/cmake/help/v3.14/command/add_custom_target.html#command:add_custom_target>
command to drive the command and make the other targets depend on that one)

Removing ${MyParserOutput} from both add_library() should fix the issue.

Best regards,
F
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20190314/b75aa0c7/attachment.html>


More information about the CMake mailing list