[CMake] Potential bug: Having executables named "test" causes Ninja generator to generate ambiguous rules...

Malfettone, Kris Kris.Malfettone at sig.com
Wed Feb 15 09:06:49 EST 2017


So I was able to reproduce the problem with this very simple CMakeLists.txt setup.  I cannot attach source files due to my company's mail server automatically stripping them out attachments with code but here is all you would need to reproduce the problem:

Single CMakeLists.txt with the following:
cmake_minimum_required(VERSION 3.7)
enable_testing()
project("bugreproduce")
add_executable( "Foo.test" foo_test.cpp )
add_executable( "Bar.test" bar_test.cpp )
set_target_properties("Foo.test" PROPERTIES OUTPUT_NAME test )
set_target_properties("Bar.test" PROPERTIES OUTPUT_NAME test )
add_test(NAME "Foo.test" COMMAND test)
add_test(NAME "Bar.test" COMMAND test )
Two source files named foo_test.cpp and bar_test.cpp both containing the following code in the same directory:
int main( int, char** )
{
   return 0;
}

If you generate a Makefile based solution everything works fine.  However, if you generate a ninja based solution then you get the following:
ninja: warning: multiple rules generate test. builds involving this target will not be correct; continuing anyway [-w dupbuild=warn]
ninja: warning: multiple rules generate test. builds involving this target will not be correct; continuing anyway [-w dupbuild=warn]

-Kris

From: CMake [mailto:cmake-bounces at cmake.org] On Behalf Of Malfettone, Kris
Sent: Wednesday, February 15, 2017 8:27 AM
To: Nils Gladitz <nilsgladitz at gmail.com>; cmake at cmake.org
Subject: Re: [CMake] Potential bug: Having executables named "test" causes Ninja generator to generate ambiguous rules...

Good to know.  Thanks for the quick response.  Though I do not believe I am violating that particular rule here.  That is why I do not receive either a warning or error from CMake in my output.

The only warning I see is from ninja:
ninja: warning: multiple rules generate MD/MDF/Formats/SIG/BCP/v0_1/test. builds involving this target will not be correct; continuing anyway [-w dupbuild=warn]
ninja: warning: multiple rules generate MD/MDF/Formats/SIG/BCP/v0_2/test. builds involving this target will not be correct; continuing anyway [-w dupbuild=warn]
ninja: warning: multiple rules generate test. builds involving this target will not be correct; continuing anyway [-w dupbuild=warn]

I think the difference is that my target names are:
MD.MDF.Formats.SIG.BCP.v0_1.test
MD.MDF.Formats.SIG.BCP.v0_2.test

It is the ninja generator that is trying to setup aliases for each of them as a shortened form.  So I think one of the following statements are true:

*         The cmake rule intended for the above two target names to be invalid.  But the check to issue a warning or error has a bug causing them to be missed.  This would explain why I do not get the error in my configure results.

*         The cmake rule intended for the above two target names to be valid.  However, on further reflection the rule should be made stricter to include my target names above.  This would then require and update to the cmake code checking that policy and lead to me actually getting a warning or error from cmake during configure.

*         The ninja generator has a bug and is setting up ambiguous aliases for what CMake considers valid target names.

My project is huge so I will try and craft a simplified CMakeLists.txt example to reproduce the problem as well.

Does this make sense?  Am I still missing something?

-Kris

From: Nils Gladitz [mailto:nilsgladitz at gmail.com]
Sent: Wednesday, February 15, 2017 3:36 AM
To: Malfettone, Kris <Kris.Malfettone at msx.bala.susq.com<mailto:Kris.Malfettone at msx.bala.susq.com>>; cmake at cmake.org<mailto:cmake at cmake.org>
Subject: Re: [CMake] Potential bug: Having executables named "test" causes Ninja generator to generate ambiguous rules...

On 14.02.2017 22:53, Malfettone, Kris wrote:
If so, are executables named "test" no longer supported?
Am I missing something or wrong in some way?


Issues existed before 3.0 but since 3.0 "test" and similarly problematic target names have been explicitly reserved.

Any CMake Version >= 3.0 will issue a warning (when the required version is < 3.0) or an error (when the required version is >= 3.0) by default:
    https://cmake.org/cmake/help/v3.8/policy/CMP0037.html

Nils

________________________________

IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.

________________________________

IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20170215/6dfac0c7/attachment-0001.html>


More information about the CMake mailing list