[CMake] Visual Studio reports errors based on output of custom commands

Hugo Heden hugoheden at gmail.com
Thu Jan 29 10:22:49 EST 2009


Good day all,

(Not sure if most people already know this, but I thought it might be
useful to record this "somewhere on the Internet" for future
reference)

Visual Studio sometimes reports errors from custom commands (or custom
targets) even though they exit with zero, if they output certain
strings. An example output string that would trigger an error is
"hejsan: error : ".

The string at least contains a colon, after that the string "error"
(without the quotes) and after that another colon. This effect can be
recreated by creating a custom command (within a Visual Studio
project) that just prints that string. Also, the following little
cmake-project can be used to illustrate this effect. Notice the
difference between target1 and target2 below.

This is not ideal for us. Sometimes our code prints stuff like that,
even though there is no real error. Example: Test code that *checks*
that a certain asserts *fires* at some condition (a *negative* test).
The assert may very well print a string that Visual Studio triggers
on.

I am not sure whether this is to be considered a cmake issue at all?

Best regards
Hugo Heden


------------------------------------------------------------

CMAKE_MINIMUM_REQUIRED( VERSION 2.6 )

PROJECT( small_cmake_proj )

ADD_CUSTOM_TARGET(
  target1
  ALL
  COMMAND echo "hoppsan: error: tjosan"
  VERBATIM
  )

ADD_CUSTOM_TARGET(
  target2
  ALL
  COMMAND echo "hoppsan: horror: tjosan"
  VERBATIM
  )

------------------------------------------------------------

Build this, for example using a "Visual Studio 2008 Command Prompt":

------------------------------------------------------------

> cmake ..\src -G "Visual Studio 9 2008"
....

> devenv small_cmake_proj.sln /Build Debug /project ALL_BUILD.vcproj

 Microsoft (R) Visual Studio Version 9.0.21022.8.
 Copyright (C) Microsoft Corp. All rights reserved.
 ------ Build started: Project: target1, Configuration: Debug Win32 ------
 "hoppsan: error: tjosan"
 Build log was saved at
"file://c:\devel\test\small_cmake_proj\build\target1.dir\Debug\BuildLog.htm"
 target1 - 1 error(s), 0 warning(s)
 ------ Build started: Project: target2, Configuration: Debug Win32 ------
 "hoppsan: horror: tjosan"
 Build log was saved at
"file://c:\devel\test\small_cmake_proj\build\target2.dir\Debug\BuildLog.htm"
 target2 - 0 error(s), 0 warning(s)
 ========== Build: 1 succeeded, 1 failed, 2 up-to-date, 0 skipped ==========


More information about the CMake mailing list