[CMake] Help debug crazy Windows MSVC issue

Paul Smith paul at mad-scientist.net
Sun Feb 16 22:17:43 EST 2014


On Sun, 2014-02-16 at 21:35 -0500, Paul Smith wrote:
> I'm using CMake 2.8.12.1 on Linux, MacOS, and Windows.  On Windows I'm
> using MSVC 2010 and the Visual Studio generator, but I have only
> remote access so I'm invoking my builds using devenv (not running
> Visual Studio).

Here's a simplified repro case (this is run from a Git shell, just
because I can't manage command.com; but I've run it from there with
identical results):

  $ cd cmtest

  $ cat CMakeFiles.txt
  cmake_minimum_required(VERSION 2.8.12)

  project(TEST C CXX)

  add_custom_command(OUTPUT bar.cpp
      COMMAND cmake -E copy ${CMAKE_CURRENT_SOURCE_DIR}/foo.cpp bar.cpp
      DEPENDS foo.cpp
      COMMENT "Creating bar.cpp")

  add_library(Bar STATIC base.cpp bar.cpp)

  add_library(BarDLL SHARED base.cpp bar.cpp)

  $ cat base.cpp
  int base = 0;
  int restbase()
  {
      return base;
  }

  $ cat foo.cpp
  int foo = 0;
  int restfoo()
  {
      return foo;
  }

For simplicity of cleaning I'll use a remote directory build:

  $ mkdir ../cmobj

  $ cd ../cmobj

  $ cmake ../cmtest

  $ cmake --build .

Now in the results you'll see that the "Creating bar.cpp" is printed
twice, showing that the custom command is run twice.

This doesn't happen for makefiles.

How can I structure my cmake file to avoid this double build?



More information about the CMake mailing list