Consider the following simple C++ file foo.cpp:<br><br>#include <iostream><br><br>int main()<br>{<br> std::cout << "bar" << std::endl;<br> return 0;<br>}<br><br><br>Now consider the following CMakeLists.txt file for foo.cpp:<br>
<br><br>cmake_minimum_required(VERSION 2.6)<br><br>project(Bug)<br><br>set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)<br><br><br>add_executable(foo foo.cpp)<br><br>get_target_property(FOO_LOCATION foo LOCATION)<br>
<br>message("${FOO_LOCATION}")<br><br>add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/bar<br> COMMAND ${CMAKE_COMMAND} -E make_directory bat<br> COMMAND chdir bat<br> COMMAND ${FOO_LOCATION} > ${CMAKE_CURRENT_BINARY_DIR}/bar<br>
DEPENDS foo<br>)<br><br><br>add_custom_target(Bar DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/bar)<br><br><br>When you configure this project using the Windows Visual Studio 9 generator, the generation step correctly displays(ie from the message() command) the value C:\path\to\build\directory\bin\$(OutDir)\foo.exe for the variable FOO_LOCATION.<br>
The problem comes in the add_custom_command step. The generator writes the following line into the .vcproj file:<br><br>bin\$(OutDir)\foo.exe > C:\path\to\build\directory\bar<br><br>What I'm pointing out is that the generator puts a path to foo.exe that is not the full path name and this behavior causes the add_custom_command build step to fail because the custom command includes a chdir command so the current working directory has changed and bin\$(OutDir)\foo.exe is not longer available.<br>
<br>Now, if you instead modify the add_custom_command the line to read:<br><br>COMMAND "..\${FOO_LOCATION}|" > ${CMAKE_CURRENT_BINARY_DIR}/bar<br><br>the generator instead puts the following in the project files:<br>
<br>..\C:\path\to\build\directory\bin\$(OutDir)\foo.exe<br><br>?!?<br><br>The correct path now appears, but it is wrong because of the ..\ prepended to the value.<br><br>What is going on? Why doesn't the value of FOO_LOCATION always and everywhere stay C:\path\to\build\directory\bin\$(OutDir)\foo.exe?<br>
<br>Thanks in advance,<br><br>Steve<br><br><br>