Skip to content

Instantly share code, notes, and snippets.

@andyleejordan
Created May 11, 2017 19:19
Show Gist options
  • Save andyleejordan/391a82050118ea2862858a8a34e115c5 to your computer and use it in GitHub Desktop.
Save andyleejordan/391a82050118ea2862858a8a34e115c5 to your computer and use it in GitHub Desktop.
Visual Studio 2017 CMake Build Tools Bug

Problem

The 3.7.2 version of CMake bundled with Visual Studio 2017 (latest update) cannot on its own find the Visual Studio 2017 build tools. This is reproducing for me using Visual Studio 2017 with individual components selected. Using CMake 3.8.1 (current CMake release), the tools can be found no problem. This becomes problematic when using the Visual Studio CMake tools because the ExternalProject_Add macro (used to include third-party CMake driven projects) re-invokes CMake, at which point it fails to find the compilers. It seems that Visual Studio originally invokes CMake "specially" shomehow as it finds the tools for the top-level project, but does not retain this environment when ${CMAKE_COMMAND} is invoked from within the build.

CMake 3.7.2 on CLI

PS C:\Users\andrew\src\mesos\build> cmake --version
cmake version 3.7.2

CMake suite maintained and supported by Kitware (kitware.com/cmake).
PS C:\Users\andrew\src\mesos\build> cmake .. -G "Visual Studio 15 2017 Win64" -T "host=x64" -DENABLE_LIBEVENT=1 -DHAS_AUTHENTICATION=0
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:25 (project):
  No CMAKE_C_COMPILER could be found.



CMake Error at CMakeLists.txt:25 (project):
  No CMAKE_CXX_COMPILER could be found.



-- Configuring incomplete, errors occurred!
See also "C:/Users/andrew/src/mesos/build/CMakeFiles/CMakeOutput.log".
See also "C:/Users/andrew/src/mesos/build/CMakeFiles/CMakeError.log".

CMake 3.8.1 on CLI

PS C:\Users\andrew\src\mesos\build> cmake --version
cmake version 3.8.1

CMake suite maintained and supported by Kitware (kitware.com/cmake).
PS C:\Users\andrew\src\mesos\build> cmake .. -G "Visual Studio 15 2017 Win64" -T "host=x64" -DENABLE_LIBEVENT=1 -DHAS_AUTHENTICATION=0
-- The C compiler identification is MSVC 19.10.25019.0
-- The CXX compiler identification is MSVC 19.10.25019.0
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/VC/Tools/MSVC/14.10.25017/bin/HostX64/x64/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/VC/Tools/MSVC/14.10.25017/bin/HostX64/x64/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/VC/Tools/MSVC/14.10.25017/bin/HostX64/x64/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/VC/Tools/MSVC/14.10.25017/bin/HostX64/x64/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- cotire 1.7.9 loaded.
-- ************************************************************
-- ********* Beginning Mesos CMake configuration step *********
-- ************************************************************
-- INSTALLATION PREFIX: C:/Program Files/Mesos
-- MACHINE SPECS:
--     Hostname:
--     OS:       WINDOWS(10.0.15063)
--     Arch:     AMD64
--     BitMode:
--     BuildID:
-- ************************************************************
CMake Warning at cmake/CompilationConfigure.cmake:114 (message):
  On Windows, the required versions of:

    * ZooKeeper
    * protobuf
    * glog
    * libevent
    * curl
    * libapr
    * zlib

  do not come rebundled in the Mesos repository.  They will be downloaded
  from the Internet, even though the `REBUNDLED` flag was set.
Call Stack (most recent call first):
  cmake/MesosConfigure.cmake:51 (include)
  CMakeLists.txt:61 (include)


-- Performing Test COMPILER_SUPPORTS_CXX11
-- Performing Test COMPILER_SUPPORTS_CXX11 - Success
-- GnuWin32 patch.exe exists at: C:/Program Files (x86)/GnuWin32/bin/patch.exe
-- Looking for pthread.h
-- Looking for pthread.h - not found
-- Found Threads: TRUE
-- CXX target mesos-1.4.0 cotired.
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/andrew/src/mesos/build
PS C:\Users\andrew\src\mesos\build>

Visual Studio CMake Tools (original invocation)

The corresponding CMakeSettings.json can be found here.

1> Command line: C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2017\PROFESSIONAL\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe  -G "Visual Studio 15 2017 Win64" -DCMAKE_INSTALL_PREFIX:PATH="C:\Users\andschwa\AppData\Local\CMakeBuild\bb480876-3d6e-ba35-8f97-ffc120e14f87\build\install"  -DENABLE_LIBEVENT="1"  -DHAS_AUTHENTICATION="0"  -T host=x64 -DCMAKE_CONFIGURATION_TYPES="Debug" "C:\Users\andschwa\src\mesos"
1> Working directory: C:\Users\andschwa\AppData\Local\CMakeBuild\bb480876-3d6e-ba35-8f97-ffc120e14f87\build\x64-Debug
1> -- cotire 1.7.9 loaded.
1> -- ************************************************************
1> -- ********* Beginning Mesos CMake configuration step *********
1> -- ************************************************************
1> -- INSTALLATION PREFIX: C:/Users/andschwa/AppData/Local/CMakeBuild/bb480876-3d6e-ba35-8f97-ffc120e14f87/build/install
1> -- MACHINE SPECS:
1> --     Hostname: 
1> --     OS:       WINDOWS(10.0.15063)
1> --     Arch:     AMD64
1> --     BitMode:  
1> --     BuildID:  
1> -- ************************************************************
1> CMake Warning at cmake/CompilationConfigure.cmake:114 (message):
1>   On Windows, the required versions of:
1> 
1>     * ZooKeeper
1>     * protobuf
1>     * glog
1>     * libevent
1>     * curl
1>     * libapr
1>     * zlib
1> 
1>   do not come rebundled in the Mesos repository.  They will be downloaded
1>   from the Internet, even though the `REBUNDLED` flag was set.
1> Call Stack (most recent call first):
1>   cmake/MesosConfigure.cmake:51 (include)
1>   CMakeLists.txt:61 (include)
1> 
1> 
1> -- GnuWin32 patch.exe exists at: C:/Program Files (x86)/GnuWin32/bin/patch.exe
1> -- CXX target mesos-1.4.0 cotired.
1> -- Configuring done
1> -- Generating done
1> -- Build files have been written to: C:/Users/andschwa/AppData/Local/CMakeBuild/bb480876-3d6e-ba35-8f97-ffc120e14f87/build/x64-Debug
1> Starting CMake target info extraction ...
1> CMake server connection made.
1> Extracted includes paths.
1> Extracted CMake variables.
1> Extracted source files and headers.
1> Extracted global settings.
1> Extracted code model.
1> Collating data ...
1> Target info extraction done.

Visual Studio CMake Tools (ExternalProject_Add)

  Microsoft (R) Build Engine version 15.1.1012.6693
  Copyright (C) Microsoft Corporation. All rights reserved.
  
  Build started 5/11/2017 12:15:08 PM.
  Project "C:\Users\andschwa\AppData\Local\CMakeBuild\bb480876-3d6e-ba35-8f97-ffc120e14f87\build\x64-Debug\3rdparty\http_parser-2.6.2.vcxproj" on node 1 (default targets).
  Project "C:\Users\andschwa\AppData\Local\CMakeBuild\bb480876-3d6e-ba35-8f97-ffc120e14f87\build\x64-Debug\3rdparty\http_parser-2.6.2.vcxproj" (1) is building "C:\Users\andschwa\AppData\Local\CMakeBuild\bb480876-3d6e-ba35-8f97-ffc120e14f87\build\x64-Debug\ZERO_CHECK.vcxproj" (2) on node 1 (default targets).
  InitializeBuildStatus:
    Creating "x64\Debug\ZERO_CHECK\ZERO_CHECK.tlog\unsuccessfulbuild" because "AlwaysCreate" was specified.
  CustomBuild:
    All outputs are up-to-date.
  FinalizeBuildStatus:
    Deleting file "x64\Debug\ZERO_CHECK\ZERO_CHECK.tlog\unsuccessfulbuild".
    Touching "x64\Debug\ZERO_CHECK\ZERO_CHECK.tlog\ZERO_CHECK.lastbuildstate".
  Done Building Project "C:\Users\andschwa\AppData\Local\CMakeBuild\bb480876-3d6e-ba35-8f97-ffc120e14f87\build\x64-Debug\ZERO_CHECK.vcxproj" (default targets).
  InitializeBuildStatus:
    Touching "x64\Debug\http_parser-2.6.2\http_par.AFD9A5B9.tlog\unsuccessfulbuild".
  CustomBuild:
    Building Custom Rule C:/Users/andschwa/src/mesos/3rdparty/CMakeLists.txt
    CMake does not need to re-run because C:\Users\andschwa\AppData\Local\CMakeBuild\bb480876-3d6e-ba35-8f97-ffc120e14f87\build\x64-Debug\3rdparty\CMakeFiles\generate.stamp is up-to-date.
    Creating directories for 'http_parser-2.6.2'
    Performing download step (verify and extract) for 'http_parser-2.6.2'
    CMake Warning at http_parser-2.6.2-stamp/verify-http_parser-2.6.2.cmake:15 (message):
      File will not be verified since no URL_HASH specified
    
    
    -- extracting...
         src='C:/Users/andschwa/src/mesos/3rdparty/http-parser-2.6.2.tar.gz'
         dst='C:/Users/andschwa/AppData/Local/CMakeBuild/bb480876-3d6e-ba35-8f97-ffc120e14f87/build/x64-Debug/3rdparty/http_parser-2.6.2/src/http_parser-2.6.2'
    -- extracting... [tar xfz]
    -- extracting... [analysis]
    -- extracting... [rename]
    -- extracting... [clean up]
    -- extracting... done
    Performing update step for 'http_parser-2.6.2'
    Performing patch step for 'http_parser-2.6.2'
    (Stripping trailing CRs from patch.)
    patching file http_parser.h
    Performing configure step for 'http_parser-2.6.2'
    -- The CXX compiler identification is unknown
    CMake Error at CMakeLists.txt:24 (project):
      No CMAKE_CXX_COMPILER could be found.
    
    
    
    -- Configuring incomplete, errors occurred!
    See also "C:/Users/andschwa/AppData/Local/CMakeBuild/bb480876-3d6e-ba35-8f97-ffc120e14f87/build/x64-Debug/3rdparty/http_parser-2.6.2/src/http_parser-2.6.2-build/CMakeFiles/CMakeOutput.log".
    See also "C:/Users/andschwa/AppData/Local/CMakeBuild/bb480876-3d6e-ba35-8f97-ffc120e14f87/build/x64-Debug/3rdparty/http_parser-2.6.2/src/http_parser-2.6.2-build/CMakeFiles/CMakeError.log".
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(171,5): error MSB6006: "cmd.exe" exited with code 1. 
  Done Building Project "C:\Users\andschwa\AppData\Local\CMakeBuild\bb480876-3d6e-ba35-8f97-ffc120e14f87\build\x64-Debug\3rdparty\http_parser-2.6.2.vcxproj" (default targets) -- FAILED.
  
  Build FAILED.
  
  "C:\Users\andschwa\AppData\Local\CMakeBuild\bb480876-3d6e-ba35-8f97-ffc120e14f87\build\x64-Debug\3rdparty\http_parser-2.6.2.vcxproj" (default target) (1) ->
  (CustomBuild target) -> 
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(171,5): error MSB6006: "cmd.exe" exited with code 1. 
  
      0 Warning(s)
      1 Error(s)
  
  Time Elapsed 00:00:01.49

Build failed.
@andyleejordan
Copy link
Author

Hm, that doesn't seem to be doing it. FWIW the only non-bundled version of CMake I have on this machine is 3.8.1; ExternaProject_Add is spawning the bundled 3.7.2 (not 3.7.2 proper, as it's not installed).

$env:PATH = "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin;${env:PATH}"

~\src\mesos |-/ get-command -all cmake | %{ & $_.Source --version }
cmake version 3.7.20170106-gd3236-dirty-MSVC_2

CMake suite maintained and supported by Kitware (kitware.com/cmake).
cmake version 3.8.1

CMake suite maintained and supported by Kitware (kitware.com/cmake).

devenv

So, having started VS with it's bundle CMake at the front of the path, my projects still fail like:

    Performing configure step for 'protobuf-3.0.0-beta-2'
    -- The C compiler identification is unknown
    -- The CXX compiler identification is unknown
    CMake Error at CMakeLists.txt:5 (project):
      No CMAKE_C_COMPILER could be found.
    
    
    
    CMake Error at CMakeLists.txt:5 (project):
      No CMAKE_CXX_COMPILER could be found.

That said, I have worked around this instead by setting the ExternalProject_Add property CMAKE_COMMAND to C:\Program Files\CMake\bin\cmake.exe (CMake 3.8.1):

diff --git i/3rdparty/CMakeLists.txt w/3rdparty/CMakeLists.txt
index cb118f6c4..bc67f6df2 100755
--- i/3rdparty/CMakeLists.txt
+++ w/3rdparty/CMakeLists.txt
@@ -43,6 +43,7 @@ set(LIBEV_URL       ${FETCH_URL}/libev-${LIBEV_VERSION}.tar.gz)
 set(LIBEVENT_URL ${3RDPARTY_DEPENDENCIES}/libevent-release-${LIBEVENT_VERSION}.tar.gz)

 if (WIN32)
+  set(CMAKE_PROPER_COMMAND "C:/Program Files/CMake/bin/cmake.exe")
   # NOTE: These dependencies are only rebundled on Windows because they
   # are available as installable packages on Linux; so they live
   # exclusively in the 3rdparty repo.
@@ -207,6 +208,7 @@ ExternalProject_Add(
 ExternalProject_Add(
   ${HTTP_PARSER_TARGET}
   PREFIX            ${HTTP_PARSER_CMAKE_ROOT}
+  CMAKE_COMMAND     ${CMAKE_PROPER_COMMAND}
   UPDATE_COMMAND    ${HTTP_PARSER_UPDATE_CMD}
   PATCH_COMMAND     ${HTTP_PARSER_PATCH_CMD}
   INSTALL_COMMAND   ${CMAKE_NOOP}
@@ -227,6 +229,7 @@ elseif (ENABLE_LIBEVENT)
   ExternalProject_Add(
     ${LIBEVENT_TARGET}
     PREFIX          ${LIBEVENT_CMAKE_ROOT}
+    CMAKE_COMMAND   ${CMAKE_PROPER_COMMAND}
     CMAKE_ARGS      ${LIBEVENT_CMAKE_ARGS}
     INSTALL_COMMAND ${LIBEVENT_INSTALL_CMD}
     URL             ${LIBEVENT_URL}
@@ -305,7 +308,7 @@ if (NOT WIN32)
   set(PROTOBUF_BUILD_CMD   make)
   set(PROTOBUF_INSTALL_CMD make install)
 elseif (WIN32)
-  set(PROTOBUF_CONFIG_CMD  cmake -G ${CMAKE_GENERATOR} ../protobuf-${PROTOBUF_VERSION}/cmake -DBUILD_SHARED_LIBS=OFF -Dprotobuf_MSVC_STATIC_RUNTIME=ON -Dprotobuf_BUILD_TESTS=OFF)
+  set(PROTOBUF_CONFIG_CMD  ${CMAKE_PROPER_COMMAND} -G ${CMAKE_GENERATOR} ../protobuf-${PROTOBUF_VERSION}/cmake -DBUILD_SHARED_LIBS=OFF -Dprotobuf_MSVC_STATIC_RUNTIME=ON -Dprotobuf_BUILD_TESTS=OFF)
   set(PROTOBUF_BUILD_CMD   msbuild protobuf.sln)
   set(PROTOBUF_INSTALL_CMD ${CMAKE_NOOP})
 endif (NOT WIN32)
@@ -329,6 +332,7 @@ ExternalProject_Add(
 ExternalProject_Add(
   ${PROTOBUF_TARGET}
   PREFIX            ${PROTOBUF_CMAKE_ROOT}
+  CMAKE_COMMAND     ${CMAKE_PROPER_COMMAND}
   CMAKE_ARGS        -DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS} -DCMAKE_CXX_FLAGS_DEBUG="/MTd"
   PATCH_COMMAND     ${PROTOBUF_PATCH_CMD}
   CONFIGURE_COMMAND ${PROTOBUF_CONFIG_CMD}
@@ -395,6 +399,7 @@ elseif (WIN32)
     # already. The `--binary` option will instead fail to apply the patch.
     PATCH_COMMAND     ${PATCHEXE_LOCATION} -p1 < ${MESOS_3RDPARTY_SRC}/zookeeper-${ZOOKEEPER_VERSION}.patch
     SOURCE_SUBDIR     src/c
+    CMAKE_COMMAND     ${CMAKE_PROPER_COMMAND}
     CMAKE_ARGS        -DWANT_CPPUNIT=0
     INSTALL_COMMAND   ${CMAKE_NOOP}
     URL               ${ZOOKEEPER_URL}

When set to 3.8.1:

set(CMAKE_PROPER_COMMAND "C:/Program Files/CMake/bin/cmake.exe")

it works. When set to the bundled CMake 3.7.2 (path tested above):

set(CMAKE_PROPER_COMMAND "C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/bin/cmake.exe")

it fails by not finding the compilers.

Just to double check that bundled path:

~\src\mesos |-/ & "C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/bin/cmake.exe" --version
cmake version 3.7.20170106-gd3236-dirty-MSVC_2

I have to force it to use the 3.8.1 version, the bundled one isn't working.

P.S. I am excited to hear VS will bundle 3.8.1 soon!

@greazer
Copy link

greazer commented May 11, 2017

Ah, ok. Yep, I concur. Note that I am not the expert on CMake on my team, and the person who is is currently OOF. So, I can check with him about why 3.7.2.* wouldn't work, but 3.8.1 would once he is back. Perhaps there was some other indirect fix that went into 3.8.1 that affects this scenario. Sorry for the trouble!

@atulkumarpccs
Copy link

https://blogs.msdn.microsoft.com/vcblog/2016/11/16/cmake-support-in-visual-studio-the-visual-studio-2017-rc-update/

I am doing all the above steps still Cmake tab is not visible any solution i am using licence version Microsoft Visual Studio Professional 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment