[cmake-developers] [CMake 0014089]: add_test() WORKING_DIR don't accept generators AND/OR add_custom_command() generator makes wrong paths

Mantis Bug Tracker mantis at public.kitware.com
Mon Apr 15 10:52:03 EDT 2013


The following issue has been SUBMITTED. 
====================================================================== 
http://www.cmake.org/Bug/view.php?id=14089 
====================================================================== 
Reported By:                Joel Lamotte
Assigned To:                
====================================================================== 
Project:                    CMake
Issue ID:                   14089
Category:                   CMake
Reproducibility:            always
Severity:                   major
Priority:                   normal
Status:                     new
====================================================================== 
Date Submitted:             2013-04-15 10:52 EDT
Last Modified:              2013-04-15 10:52 EDT
====================================================================== 
Summary:                    add_test() WORKING_DIR don't accept generators
AND/OR add_custom_command() generator makes wrong paths
Description: 
I'm pasting here the report I gave there:
http://cmake.3232098.n2.nabble.com/Potential-bug-to-set-a-working-directory-for-test-td7583812.html

----

I'm using CMake 2.10.2 the VS2012(VC11) generator.
I summed-up my problem in the last paragraph.

I'm trying to do this:

add_test( 
    NAME ${TEST_PROJECT_NAME}
    WORKING_DIRECTORY ${TEST_WORKING_DIR}
    COMMAND ${TEST_PROJECT_NAME}
)

In my current setup, I need ${TEST_WORKING_DIR} to be dependent on the build
config name.
${TEST_WORKING_DIR} is equivalent to:
"${MYPROJECT_FINAL_DIR}/$<CONFIGURATION>/myproject"
But this don't work as WORKING_DIRECTORY don't accept generator commands.
(note: ${MYPROJECT_FINAL_DIR} is a full path)

I was considering using two commands, one to do "cd ${TEST_WORKING_DIR}  and one
to call the test project target (which is in another directory, the build one).
There is a restriction that add_test() can't take more than one COMMAND
instruction.

I then figured that I could just call the test automatically on build. I first
wrote this:

add_custom_command( 
    TARGET ${TEST_PROJECT_NAME}
    POST_BUILD
    COMMAND cd ${TEST_WORKING_DIR}
     COMMAND ${TEST_PROJECT_NAME}
	VERBATIM
	)

Unfortunately this cannot work as with the current generator the
${TEST_PROJECT_NAME} is converted to a windows-specific path which is the
relative path from the CMakeLists.txt file.
So the generated commands are something like

    cd E:/projects/myprojects/final/Debug
    ../../../../../../build/Debug/my_test

Understanding this, I changed the command to find explicitly the test executable
file so 
that the generated command would have a full path instead of a relative path.
This is less flexible but should have worked:

add_custom_command( 
     TARGET ${TEST_PROJECT_NAME}
    POST_BUILD
    COMMAND cd ${TEST_WORKING_DIR}
     COMMAND
${MYPROHECT_BUILD_DIR}/$<Configuration>/$<TARGET_FILE_NAME:${TEST_PROJECT_NAME}>
	VERBATIM
	)

note that ${MYPROHECT_BUILD_DIR} is a full path.
This generate EXACTLY the same command:
 
    cd E:/projects/myprojects/final/Debug
    ../../../../../../build/Debug/my_test

Which is still wrong.
In doubt I added a "call" command at the beginning of the second command, which
works on Windows but will not work on other platform (from search I just did).

To sum-up:

1. I would like to be able to set a working directory which would be generated
using generated expression (as for the first example) both for add_test() and
add_custom_command(). Currently I have no cross-platform way to do this (AFAIK)
which don't imply calling an external script.
2. Why does the VS generator convert a binary call to a relative path
systematically, evene if VERBATIM is defined?

I'm not sure if there are reasons for these behaviours so I'm asking here before
making tickets. If I should make tickets, does the first one is a feature and
the second one a bug? Should I enter two tickets?

Thanks for your patience.

====================================================================== 

Issue History 
Date Modified    Username       Field                    Change               
====================================================================== 
2013-04-15 10:52 Joel Lamotte   New Issue                                    
======================================================================




More information about the cmake-developers mailing list