View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0014089CMakeCMakepublic2013-04-15 10:522014-10-06 10:33
ReporterJoël Lamotte 
Assigned ToBen Boeckel 
PrioritynormalSeverityfeatureReproducibilityalways
StatusclosedResolutionfixed 
PlatformOSOS Version
Product Version 
Target VersionFixed in VersionCMake 3.0 
Summary0014089: add_test/add_custom_command: Support generator expressions in WORKING_DIRECTORY
DescriptionI'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.
TagsNo tags attached.
Attached Files

 Relationships

  Notes
(0032840)
Brad King (manager)
2013-04-15 10:59

Generator expressions are not supported in WORKING_DIRECTORY, nor does the documentation claim support. Therefore this is a feature request.
(0032841)
Brad King (manager)
2013-04-15 11:03

In response to your questions:

(1) Since the feature doesn't exist you'll have to use a wrapper script or launcher for now.

(2) The VERBATIM option enables proper escaping arguments passed to the command but does not affect the command itself (argv[0]). If argv[0] names a target (e.g. from add_executable) then CMake converts it to the location that CMake places the target binary file. This makes it very easy to use in the common use case. You might be able to stop this with a generator expression like $<1:mycmd>.
(0035497)
Ben Boeckel (developer)
2014-03-24 18:11

This should be handled by this commit, right (which is in 3.0):

commit d331292c121269ccfceee302a0f9bbb960b9f02d
Author: Ben Boeckel <mathstuf@gmail.com>
Date: Wed Aug 7 17:07:30 2013 -0400

    cmTestGenerator: Evaluate generator expressions in test properties
    
    This is useful for cases like:
    
      add_test(NAME mytest COMMAND mydriver $<TARGET_FILE:myexe>)
      set_tests_properties(mytest PROPERTIES
        REQUIRED_FILES "$<TARGET_FILE:myexe>"
        WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/$<CONFIGURATION>"
        )
    
    In this example we require the actual test executable to exist to
    run the test in addition to the test driver at argv[0]. Also the
    $<CONFIGURATION> expression improves over \${CTEST_CONFIGURATION_TYPE}
    because the latter is not normalized for case-sensitive filesystems.
(0036958)
Robert Maynard (manager)
2014-10-06 10:33

Closing resolved issues that have not been updated in more than 4 months.

 Issue History
Date Modified Username Field Change
2013-04-15 10:52 Joël Lamotte New Issue
2013-04-15 10:59 Brad King Note Added: 0032840
2013-04-15 10:59 Brad King Severity major => feature
2013-04-15 10:59 Brad King Status new => backlog
2013-04-15 10:59 Brad King Summary add_test() WORKING_DIR don't accept generators AND/OR add_custom_command() generator makes wrong paths => add_test/add_custom_command: Support generator expressions in WORKING_DIRECTORY
2013-04-15 11:03 Brad King Note Added: 0032841
2014-03-24 18:11 Ben Boeckel Note Added: 0035497
2014-03-26 11:03 Brad King Assigned To => Ben Boeckel
2014-03-26 11:03 Brad King Status backlog => resolved
2014-03-26 11:03 Brad King Resolution open => fixed
2014-03-26 11:03 Brad King Fixed in Version => CMake 3.0
2014-10-06 10:33 Robert Maynard Note Added: 0036958
2014-10-06 10:33 Robert Maynard Status resolved => closed


Copyright © 2000 - 2018 MantisBT Team