[CMake] Using ${CMAKE_CFG_INTDIR} in ADD_TEST property WORKING_DIRECTORY

Guillaume Blanc guillaumeblanc.sc at gmail.com
Wed Jul 4 17:42:49 EDT 2012


Some tests that I run need to access files (using a relative path) that are
located in the same directory as the test executable itself. So I'm trying
to use ADD_TEST property WORKING_DIRECTORY in the following way:

ADD_TEST(
  NAME mytest
  WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}
  COMMAND myexec)

When using a multiple configuration build system like Visual Studio, I
expect the working directory to be set, in the example of a debug build, to
"c:/path/to/runtime/dir/Debug", but it fails. To test that I've printed the
return of getcwd(), which would be"c:/path/to/runtime/" in this particular
example. I've also tried to hard code "c:/path/to/runtime/dir/Debug" as the
working direcory property of the add_test command, it works fine.

So I'm wondering if  CMAKE_CFG_INTDIR can be used in that case, or if there
are other solutions to acheive this objective ?

I know I could use $<TARGET_FILE_DIR:myexec> as an argument of my test
command, but this is not the test I want to do.

I also tried the command explained in that thread:
http://www.mail-archive.com/cmake@cmake.org/msg24194.html. I did this
simple test case : add_test(mytest ${CMAKE_COMMAND} -E chdir "c:/"
$<TARGET_FILE:myexec>), but it fails to execute. I don't really understand
this syntax, it seems that it tries to run 2 commands sequentially. Is this
is supposed to work ?

My environment is CMake 2.8.8, Visual Studio 2010, Windows XP.

Best regards
Guillaume
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20120704/04b236b6/attachment.htm>


More information about the CMake mailing list