[CMake] CTest not searching for the correct executable

Nils Gladitz nilsgladitz at gmail.com
Fri Jan 5 11:16:21 EST 2018


On 05.01.2018 17:11, Saad Khattak wrote:
> Hi,
>
> Suppose I have something like this:
>
> add_executable(MyTest main.cpp)
> set_target_properties(MyTest
>   PROPERTIES
>   DEBUG_POSTFIX _d
>   RELEASE_POSTFIX _r
>   )
> add_test(RunTests MyTest) # where MyTest is the <command>
>
> I expect CMake to recognize that "MyTest" has executables that are 
> named "MyTest_d" and "MyTest_r" and NOT MyTest. I expect this because 
> in the CMake documentation the <command> can be an executable target 
> where CMake then replaces it with the location of the executable.
>
> However, what I get is errors when running "ctest" where it complains 
> that it cannot find "MyTest" when it should really be searching for 
> "MyTest_d" and "MyTest_r".
>
> Am I doing something wrong or is this a bug in CMake?

You are using the old signature (without NAME|COMMAND) for which the 
documentation states [1]:
     "Unlike the above |NAME| signature no transformation is performed 
on the command-line to support target names or generator expressions."

Use the new signature instead e.g.:
     add_test(NAME RunTests COMMAND MyTest)

Nils

[1] https://cmake.org/cmake/help/latest/command/add_test.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20180105/fc02440c/attachment.html>


More information about the CMake mailing list