On Thu, Mar 14, 2019 at 12:53 PM frodak17 <froda...@gmail.com> wrote:
> > > On Thu, Mar 14, 2019 at 1:13 AM Paul Smith <p...@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 > Sorry, It didn't register at first that about the cpp file that needs to get compiled into the library. That makes it a little more complicated. In that case you need to keep ${MyParserOutput} and set the GENERATED properties for the files. Also the building the custom target needs to be done in a separate directory as the add_custom_commands() need to be in a different CMakeLists.txt file from the libraries. Otherwise the rules get pulled into the libraries and cause the commands to be run multiple times.
-- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: https://cmake.org/mailman/listinfo/cmake