Home > Software engineering >  The remote system does not have CMake 3.8 or greater
The remote system does not have CMake 3.8 or greater

Time:05-19

  1. Introduction to the problem

I'm trying to create a MacOS app that prints a "Hello World" in C using Visual Studio 2022 (latest release 17.2.0) on Windows and the CMake template so I can connect remotely (using SSH) to the MacOS, I've been following this official Microsoft tutorial

  1. Problem ocurred

The problem is that when I get to the installation step of CMake in MacOS I can't get it to recognize the version of MacOS installed since when I open the project in Windows I get this following message in the console:

1> Copying files to the remote machine.
1> Starting copying files to remote machine.
1> Finished copying files (elapsed time 00h:00m:00s:650ms).
1> CMake generation started for configuration: 'macos-debug'.
1> Found cmake executable at /Users/maria/.vs/cmake/bin/cmake.
1> The remote system does not have CMake 3.8 or greater. An infobar to automatically deploy CMake to the remote system will be displayed if you are building on a supported architecture. See https://aka.ms/linuxcmakeconfig for more info.

It also shows the following message above:

Supported CMake version is not present on 'remote address'. Install  latest CMake binaries from CMake.org? Yes No

And when I press "yes", it says that I actually have cmake installed on the remote MacOS:

1> Copying files to the remote machine.
1> Starting copying files to remote machine.
1> Finished copying files (elapsed time 00h:00m:00s:650ms).
1> CMake generation started for configuration: 'macos-debug'.
1> Found cmake executable at /Users/maria/.vs/cmake/bin/cmake.
1> The remote system does not have CMake 3.8 or greater. An infobar to automatically deploy CMake to the remote system will be displayed if you are building on a supported architecture. See https://aka.ms/linuxcmakeconfig for more info.
CMake binary deployment to the remote machine started. CMake generation will continue automatically after deployment finishes.

CMake binary deployment to the remote machine failed: Installation directory '/Users/maria/.vs/cmake' already exists.
  1. Solution attemps

I have tried to install CMake using brew (latest version available 3.23.1) and making sure that cmake was accessible directly from the MacOS terminal (included in PATH), I also tried doing the procedure following the official guide by installing the image .dmg by copying the "CMake.app" to "/Applications" and adding it to the path using the following command:

export PATH=/Applications/CMake.app/Contents/bin:$PATH

And I even tried to install older versions of CMake (like 3.8.0 or 3.8.1) but the same thing still happened. The expected result is the same as the Microsoft guide shown here:

1> Copying files to the remote machine.
1> Starting copying files to remote machine.
1> Finished copying files (elapsed time 00h:00m:00s:650ms).
1> CMake generation started for configuration: 'macos-debug'.
1> Found cmake executable at /Applications/CMake.app/Contents/bin/cmake.
1> /Applications/CMake.app/Contents/bin/cmake -G "Ninja"  DCMAKE_BUILD_TYPE_STRING="Debug" -DCMAKE_INSTALL_PREFIX
1> [CMake] -- Configuring done
1> [CMake] -- Generating done
1> [CMake] -- Build files have been written to: /Users/cti/.vs/CMakeProject90/out/build/macos-debug
1> Extracted CMake variables.
1> Extracted source files and headers.
1> Extracted code model.
1> Extracted includes paths.
1> CMake generation finished.

Does anyone know why this is happening or what could be the solution to this problem?

CodePudding user response:

I have finally solved the problem, I had to copy the files located within the CMake application: /Applications/CMake.app/Contents/bin/cmake to the location where Visual Studio was trying to find them, which in my case was: /Users/maria/.vs/cmake/bin/cmake

The version was not a problem since I tried it with the latest CMake version (3.23.1) and it worked. Finally I found a problem related to the lack of indication of the locations of the compilers for C and C for CMake and the location of Ninja, I simply specified it inside CMakePresets.json and I had no major problems:

    {
        "name": "macos-debug",
        "displayName": "macOS Debug",
        "generator": "Ninja",
        "binaryDir": "${sourceDir}/out/build/${presetName}",
        "installDir": "${sourceDir}/out/install/${presetName}",
        "cacheVariables": {
          "CMAKE_BUILD_TYPE": "Debug",
          "CMAKE_C_COMPILER": "/usr/bin/gcc",
          "CMAKE_CXX_COMPILER": "/usr/bin/g  ",
          "CMAKE_MAKE_PROGRAM": "/usr/local/bin/ninja"
        },
        "condition": {
            "type": "equals",
            "lhs": "${hostSystemName}",
            "rhs": "Darwin"
        },
        "vendor": {
            "microsoft.com/VisualStudioRemoteSettings/CMake/1.0": {
                "sourceDir": "$env{HOME}/.vs/$ms{projectDirName}"
            }
        }
    }

I hope someone will find this a helpful solution when developing on MacOS with Visual Studio (on Windows)

CodePudding user response:

This seems to be a Visual Studio bug. You can keep track of it here.

Workaround

It looks like Visual Studio always looks for CMake under local folder of currently connected via SSH user (i.e. ~/.vs/cmake/bin/cmake), no matter how you installed it. In order to get it round (and in case you alredy have CMake installed). Then, when Visual Studio suggests to install it:

Supported CMake version is not present on ‘192.168.1.180’. Install latest CMake binaries from CMake.org?

If you agree to do that, it actually rolls out it locally in the said folder. The binaries Visual Studio uses are broken and throws an error if you try to use it on the Mac machine locally:

$: ~/.vs/cmake/bin/cmake
zsh: exec format error: /Users/User/.vs/cmake/bin/cmake

That's why Visual Studio keeps struggling to find the working CMake binary. You can get it round by creating a symbolic link to the folder with working CMake binaries in place of the folder Visual Studio looks for them in:

$: rm -rf ~/.vs/cmake/bin
$: ln -s /Applications/CMake.app/Contents/bin ~/.vs/cmake/bin

At this point Visual Studio will be able to locate the CMake, but won't be able to locate the default compilers and generators:

1> /Users/User/.vs/cmake/bin/cmake -G "Ninja"   -DCMAKE_BUILD_TYPE:STRING="Debug" -DCMAKE_INSTALL_PREFIX:PATH="/Users/User/.vs/CrossPlatform/out/install/macos-debug"  /Users/User/.vs/CrossPlatform/CMakeLists.txt;
1> [CMake] CMake Error: CMake was unable to find a build program corresponding to "Ninja".  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a different build tool.
1> [CMake] CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
1> [CMake] CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage

The simplest way to fix that is just by running this command on the Mac machine. It will generate the cache Visual Studio can use then, however be advised that whenever this cache is invalidated for whatever reason (e.g. when switching between configurations), you will have to re-generate it again the same way. Another option is to specify all missing parameters explicitly (either via CMakeLists.txt or as command line arguments under cacheVariables property of CMakePresets.json)

  • Related