MantisBT - CMake
View Issue Details
0013608CMakeCMakepublic2012-10-25 11:262013-03-04 08:38
Derek Bruening 
David Cole 
normalminoralways
closedno change required 
Visual Studio 2008Windows
CMake 2.8.9 
CMake 2.8.10CMake 2.8.10 
0013608: execute_process() run from add_custom_command() via cmake -P fails to capture output for VS2008
in my project I have a post-build custom command:

      add_custom_command(TARGET dynamorio POST_BUILD
        COMMAND ${CMAKE_COMMAND}
        ARGS -D lib=${drout}
             -D DUMPBIN_EXECUTABLE=${DUMPBIN_EXECUTABLE}
             -P ${CMAKE_CURRENT_SOURCE_DIR}/CMake_checkdeps.cmake
             VERBATIM)

where CMake_checkdeps.cmake is:

--------------------------------
execute_process(COMMAND
  ${DUMPBIN_EXECUTABLE} /dependents "${lib}"
  RESULT_VARIABLE deps_result
  ERROR_VARIABLE deps_error
  OUTPUT_VARIABLE deps_out
  )
if (deps_result OR deps_error)
  message(FATAL_ERROR "*** ${DEPS_EXECUTABLE} failed: ***\n${deps_error}")
endif (deps_result OR deps_error)
string(REGEX MATCH "following dependencies:.*Summary" dlls "${deps_out}")
string(REGEX REPLACE "\r?\n" "" dlls "${dlls}")
string(REGEX REPLACE "following dependencies: *" "" dlls "${dlls}")
string(REGEX REPLACE " *Summary" "" dlls "${dlls}")
if (NOT dlls MATCHES "^ntdll.dll$")
  message(FATAL_ERROR "*** Error: ${lib} depends on more than ntdll.dll: ${dlls}")
endif ()
----------------------------

This all works fine with VS2010. However, with VS2008, the output of dumpbin.exe is not captured and is instead printed out to the console/shell. The deps_error and deps_out variables are both empty.

If I run this custom_command at config time, it works fine. If I run the script through cmake -P it works fine whether from cmd or a cygwin rxvrt shell:

% cmake.exe -D lib=C:/src/dr/git/build_x86_dbg/lib32/debug/dynamorio.dll -D "DUMPBIN_EXECUTABLE=C:/Program Files (x86)/Microsoft Visual Studio 9.0/VC/bin/dumpbin.exe" -P C:/src/dr/git/src/core/CMake_checkdeps.cmake

But when VS2008 runs the command, it fails due to not capturing the output.

The line in the .vcproj file is:

                        <Tool
                                Name="VCPostBuildEventTool"
CommandLine="C:\PROGRA~2\CMAKE2~1.8\bin\cmake.exe -D lib=C:/src/dr/git/build_x86_dbg/lib32/debug/dynamorio.dll -D "DUMPBIN_EXECUTABLE=C:/Program Files (x86)/Microsoft Visual Studio 9.0/VC/bin/dumpbin.exe" -P C:/src/dr/git/src/core/CMake_checkdeps.cmake&#x0D;&#x0A;if errorlevel 1 goto :VCReportError"/>

If I substitute "cl.exe /help" for "dumpbin.exe ..." the same problem is there: the output is not captured.
closed, resolved
Issue History
2012-10-25 11:26Derek BrueningNew Issue
2012-10-25 11:51Brad KingNote Added: 0031324
2012-10-25 11:53David ColeNote Added: 0031325
2012-10-25 12:32Derek BrueningNote Added: 0031326
2012-10-25 12:33Derek BrueningTag Attached: closed
2012-10-25 12:33Derek BrueningTag Attached: resolved
2012-10-25 12:35Derek BrueningNote Added: 0031327
2012-10-25 12:43David ColeAssigned To => David Cole
2012-10-25 12:43David ColeStatusnew => assigned
2012-10-25 12:43David ColeNote Added: 0031328
2012-10-25 12:43David ColeStatusassigned => resolved
2012-10-25 12:43David ColeFixed in Version => CMake 2.8.10
2012-10-25 12:43David ColeResolutionopen => no change required
2012-10-25 12:43David ColeTarget Version => CMake 2.8.10
2012-10-25 12:43David ColeDescription Updatedbug_revision_view_page.php?rev_id=873#r873
2013-03-04 08:38Robert MaynardNote Added: 0032488
2013-03-04 08:38Robert MaynardStatusresolved => closed

Notes
(0031324)
Brad King   
2012-10-25 11:51   
Add

 set(ENV{vsconsoleoutput} 1)

to prevent VS from redirecting its tool output.
(0031325)
David Cole   
2012-10-25 11:53   
Try adding this line before execute_process in your script:

  set(ENV{VS_UNICODE_OUTPUT} "")

Google for it, and read things like this:

  http://stackoverflow.com/questions/5298428/capture-build-output-within-visual-studio-2010 [^]

Not a CMake bug, I don't think... Just "silly" Microsoft tools behaviors.
(0031326)
Derek Bruening   
2012-10-25 12:32   
Your suggestion does the trick:
  set(ENV{VS_UNICODE_OUTPUT} "")

Resolving.
(0031327)
Derek Bruening   
2012-10-25 12:35   
I suppose one of you needs to resolve as the only thing in my interface is a "tag" which doesn't seem to do it.
(0031328)
David Cole   
2012-10-25 12:43   
Not really a CMake bug. See all the notes.
(0032488)
Robert Maynard   
2013-03-04 08:38   
Closing resolved issues that have not been updated in more than 4 months.