Thanks! These comments have the insight that I needed!<br><br>Steve<br><br><div class="gmail_quote">On Thu, Oct 22, 2009 at 6:22 AM, Brad King <span dir="ltr"><<a href="mailto:brad.king@kitware.com">brad.king@kitware.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><div></div><div class="h5">Steven Wilson wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
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>
</blockquote>
<br></div></div>
It's converted to a path relative to the expected working directory<br>
of the custom command. This is the current binary directory by<br>
default, or can be set with the add_custom_command() call through the<br>
WORKING_DIRECTORY option. You can use file(MAKE_DIRECTORY) to prepare<br>
the directory at CMake time, or a separate custom command to make it.<br>
<br>
FYI, the LOCATION property is not necessary in CMake 2.6. You can<br>
just name the target:<br>
<br>
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bat)<div class="im"><br>
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/bar<br></div>
COMMAND foo > ${CMAKE_CURRENT_BINARY_DIR}/bar<br>
DEPENDS foo<br>
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bat<br>
)<br><font color="#888888">
<br>
-Brad<br>
</font></blockquote></div><br>