<div dir="ltr">Hi,<div><br></div><div style>I'm using CMake 2.10.2 the VS2012(VC11) generator.</div><div style>I summed-up my problem in the last paragraph.</div><div style><br></div><div style>I'm trying to do this:</div>
<div style><br></div><div style><div>add_test( </div><div><span style="white-space:pre"> </span>NAME ${TEST_PROJECT_NAME}</div><div> WORKING_DIRECTORY ${TEST_WORKING_DIR}</div><div> COMMAND ${TEST_PROJECT_NAME}</div>
<div>)</div><div><br></div><div style>In my current setup, I need ${TEST_WORKING_DIR} to be dependent on the build config name.</div><div style>${TEST_WORKING_DIR} is equivalent to: "${MYPROJECT_FINAL_DIR}/$<CONFIGURATION>/myproject"</div>
<div style>But this don't work as WORKING_DIRECTORY don't accept generator commands.</div><div style>(note: ${MYPROJECT_FINAL_DIR} is a full path)</div><div style><br></div><div style>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).</div>
<div style>There is a restriction that add_test() can't take more than one COMMAND instruction.</div><div style><br></div><div style>I then figured that I could just call the test automatically on build. I first wrote this:</div>
<div style><br></div><div style><div>add_custom_command( </div><div><span style="white-space:pre"> </span>TARGET ${TEST_PROJECT_NAME}</div><div><span style="white-space:pre"> </span>POST_BUILD</div><div><span style="white-space:pre"> </span>COMMAND cd ${TEST_WORKING_DIR}</div>
<div><span style="white-space:pre"> </span>COMMAND ${TEST_PROJECT_NAME}</div><div><span class="" style="white-space:pre">        </span>VERBATIM</div><div><span class="" style="white-space:pre">        </span>)</div><div><br></div><div style>
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.</div><div style>So the generated commands are something like</div>
<div style><br></div><div style> cd E:/projects/myprojects/final/Debug</div><div style> ../../../../../../build/Debug/my_test</div><div style><br></div><div style>Understanding this, I changed the command to find explicitly the test executable file so </div>
<div style>that the generated command would have a full path instead of a relative path.</div><div style>This is less flexible but should have worked:</div><div style><br></div><div style><div>add_custom_command( </div><div>
<span style="white-space:pre"> </span>TARGET ${TEST_PROJECT_NAME}</div><div><span style="white-space:pre"> </span>POST_BUILD</div><div><span style="white-space:pre"> </span>COMMAND cd ${TEST_WORKING_DIR}</div><div>
<span style="white-space:pre"> </span>COMMAND ${MYPROHECT_BUILD_DIR}/$<Configuration>/$<TARGET_FILE_NAME:${TEST_PROJECT_NAME}></div><div><span class="" style="white-space:pre">        </span>VERBATIM</div><div><span class="" style="white-space:pre">        </span>)</div>
<div><br></div><div>note that ${MYPROHECT_BUILD_DIR} is a full path.<br></div><div style>This generate EXACTLY the same command:</div><div style> </div><div style><div> cd E:/projects/myprojects/final/Debug</div><div> ../../../../../../build/Debug/my_test</div>
<div><br></div><div style>Which is still wrong.</div><div style>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).</div>
<div style><br></div><div style>To sum-up:</div><div style><br></div><div style>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.</div>
<div style>2. Why does the VS generator convert a binary call to a relative path systematically, evene if VERBATIM is defined?</div><div style><br></div><div style>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?</div>
<div style><br></div><div style>Thanks for your patience.</div><div style><br></div><div style>Joel Lamotte</div></div></div></div></div></div>