Discussion:
[cmake-developers] Race between ADD_CUSTOM_COMMAND()
Oleh Kravchenko
2018-07-04 16:52:23 UTC
Permalink
Hello CMake Developers!

Looks like I found interesting bug in CMake:
- ADD_CUSTOM_TARGET() always creates Makefile rule for ADD_CUSTOM_COMMAND().
- As result build simetimes failed if specified -jN for make.

Please find attached simple project which reproduce the problem.
[ 12%] Generate /home/kaa/cmake_add_custom_command-target/build/config
[ 25%] Generate /home/kaa/cmake_add_custom_command-target/build/config
[ 37%] Generate /home/kaa/cmake_add_custom_command-target/build/config
[ 50%] Generate /home/kaa/cmake_add_custom_command-target/build/config
[ 62%] Generate /home/kaa/cmake_add_custom_command-target/build/config
[ 75%] Generate /home/kaa/cmake_add_custom_command-target/build/config
[ 87%] Generate /home/kaa/cmake_add_custom_command-target/build/config
[100%] Generate /home/kaa/cmake_add_custom_command-target/build/config
CMake Error at
/home/kaa/cmake_add_custom_command-target/cmake/config.cmake:3
   CONFIGURE_FILE Problem configuring file
make[2]: *** [CMakeFiles/config2.dir/build.make:61: config] Error 1
make[2]: *** Deleting file 'config'
CMake Error at
/home/kaa/cmake_add_custom_command-target/cmake/config.cmake:3
   CONFIGURE_FILE Problem configuring file
make[2]: *** [CMakeFiles/config5.dir/build.make:61: config] Error 1
make[2]: *** Deleting file 'config'
make[1]: *** [CMakeFiles/Makefile2:216: CMakeFiles/config5.dir/all]
Error 2
make[1]: *** Waiting for unfinished jobs....
make[1]: *** [CMakeFiles/Makefile2:253: CMakeFiles/config2.dir/all]
Error 2
[100%] Built target config1
[100%] Built target config4
[100%] Built target config7
[100%] Built target config6
CMake Error at
/home/kaa/cmake_add_custom_command-target/cmake/config.cmake:3
   CONFIGURE_FILE Problem configuring file
CMake Error at
/home/kaa/cmake_add_custom_command-target/cmake/config.cmake:3
   CONFIGURE_FILE Problem configuring file
make[2]: *** [CMakeFiles/config0.dir/build.make:61: config] Error 1
make[2]: *** Deleting file 'config'
make[1]: *** [CMakeFiles/Makefile2:142: CMakeFiles/config0.dir/all]
Error 2
make[2]: *** [CMakeFiles/config3.dir/build.make:61: config] Error 1
make[1]: *** [CMakeFiles/Makefile2:327: CMakeFiles/config3.dir/all]
Error 2
make: *** [Makefile:84: all] Error 2
--

Best regards,
Oleh Kravchenko
Nils Gladitz
2018-07-04 17:19:57 UTC
Permalink
Post by Oleh Kravchenko
Hello CMake Developers!
- ADD_CUSTOM_TARGET() always creates Makefile rule for ADD_CUSTOM_COMMAND().
- As result build simetimes failed if specified -jN for make.
FWIW this is documented behavior (so not exactly a bug):
https://cmake.org/cmake/help/latest/command/add_custom_command.html

"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[...]".

Nils
--
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-developers
Oleh Kravchenko
2018-07-04 19:21:32 UTC
Permalink
Hi Nils,
Thank you for your answer!

In my case I can't use target for this.
There are any hard limits which block fixing of this behaviour?

By the way, can I have two and more targets in one build directory?
Post by Nils Gladitz
Post by Oleh Kravchenko
Hello CMake Developers!
- ADD_CUSTOM_TARGET() always creates Makefile rule for ADD_CUSTOM_COMMAND().
- As result build simetimes failed if specified -jN for make.
https://cmake.org/cmake/help/latest/command/add_custom_command.html
"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[...]".
Nils
--
Best regards,
Oleh Kravchenko
Nils Gladitz
2018-07-04 20:16:28 UTC
Permalink
Post by Oleh Kravchenko
In my case I can't use target for this.
You mean you can't use a proxy target? Why?
Post by Oleh Kravchenko
There are any hard limits which block fixing of this behaviour?
Perhaps CMake could do implicitly what you now have to do explicitly but
I haven't really thought it through.
Post by Oleh Kravchenko
By the way, can I have two and more targets in one build directory?
You can have any number of targets per directory scope ... but I am
probably misunderstanding the question?

Nils
--
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-developers
Loading...