VCTargetsPath error while using VS 10 2010 generator

Hello!

I am absolutely new to CMake (in fact I am still figuring out its purpose, not usually to languages that are complex to compile, programmed most of my stuff on Python and Rust), so please bear with me if the question is too obvious:

I am trying to use CMake in FyTest, in order to have a Fortran unit testing framework. The command I am running on the root of the folder (I am using the cmd prompt as the interface) of the repository clone is simply:

cmake -G "Visual Studio 10 2010" .

And I get the following error:

  Failed to run MSBuild command:

    C:/Windows/Microsoft.NET/Framework/v4.0.30319/MSBuild.exe

  to get the value of VCTargetsPath:

    Microsoft (R) Build Engine version 4.8.4084.0
    [Microsoft .NET Framework, version 4.0.30319.42000]
    Copyright (C) Microsoft Corporation. All rights reserved.

    Build started 12/07/2022 08:30:02.
    Project "C:\Users\<REDACTED>\Desktop\fytest\CMakeFiles\3.22.5\VCTargetsPath.vcxproj" on node 1 (default targets).
    C:\Users\<REDACTED>\Desktop\fytest\CMakeFiles\3.22.5\VCTargetsPath.vcxproj(14,2): error MSB4019: The imported project "C:\Microsoft.Cpp.Default.props" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
    Done Building Project "C:\Users\<REDACTED>\Desktop\fytest\CMakeFiles\3.22.5\VCTargetsPath.vcxproj" (default targets) -- FAILED.

    Build FAILED.

    "C:\Users\<REDACTED>\Desktop\fytest\CMakeFiles\3.22.5\VCTargetsPath.vcxproj" (default target) (1) ->
      C:\Users\<REDACTED>\Desktop\fytest\CMakeFiles\3.22.5\VCTargetsPath.vcxproj(14,2): error MSB4019: The imported project "C:\Microsoft.Cpp.Default.props" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.

        0 Warning(s)
        1 Error(s)

    Time Elapsed 00:00:00.19


  Exit code: 1



-- Configuring incomplete, errors occurred!
See also "C:/Users/<REDACTED>/Desktop/fytest/CMakeFiles/CMakeOutput.log".

In fact, this computer doesn’t have a C++ compiler, which I recognize is what CMake is complaining about not finding, but the computer I am using belongs to a company, and I am not allowed to install a C++ compiler on my own. Furthermore, as it can be seen from the line where the error occurs:

project(FyTest VERSION 0.1 LANGUAGES Fortran)

This project is built entirely in Fortran, so it shouldn’t require a C++ compiler.

So my questions are: Can I “turn off” this requirement for a C++ compiler? Is this something that CMake demands, or should it be okay with just the Fortran compiler? Or is this MSBuild fault?

Did you omit some of the output? I don’t see anything in there that is complaining about a missing C++ compiler. Did you specify a custom toolset with -T on the command line (I see some mention of VCTargetsPath in the CMAKE_GENERATOR_TOOLSET documentation).

Isn’t The imported project "C:\Microsoft.Cpp.Default.props" was not found something related to a C++ compiler?

Anyway, no, I don’t specified a custom toolset. In fact, I am not even much aware of that is. I was just trying to generate something for Visual Studio 10 (yes, I know it is deprecated, but it is what I have access too).

Should I specify a custom toolset? What is that?

If you’re not specifying a custom toolset already, then that eliminates the possibility I was wondering about (and I don’t think you should need to set one anyway).

It’s not clear what your problem might be. I suggest reducing your project down to the most minimal project that still reproduces your problem. For example, do you still see the same error if your CMakeLists.txt file contains just the following:

cmake_minimum_required(VERSION 3.18)
project(FyTest LANGUAGES Fortran)

I’ve picked a fairly arbitrary version for the number after VERSION. If you’re using something older than CMake 3.18, adjust accordingly.

I’d also see if you couldn’t use the Ninja generator in this instance. The VS generator may have some assumptions laying around (that should be fixed).

Saddly, although I may install Ninja through pip without admin privileges, it is also being buggy on me. As the remainer of the team uses VS (kind of as a legacy, and by using the Microsoft software directly, not by using CMake to generate the project), I decided to not go this route, as it was not solving the problem and it would take convincing the company to accept yet another tool/software, which I am trying to keep to a minimum.

I tried your suggestion and it gives basically the same output. Check it out:

-- Building for: Visual Studio 10 2010
CMake Error at CMakeLists.txt:2 (project):
  Failed to run MSBuild command:

    C:/Windows/Microsoft.NET/Framework/v4.0.30319/MSBuild.exe

  to get the value of VCTargetsPath:

    Microsoft (R) Build Engine version 4.8.4084.0
    [Microsoft .NET Framework, version 4.0.30319.42000]
    Copyright (C) Microsoft Corporation. All rights reserved.

    Build started 19/07/2022 08:09:03.
    Project "C:\Users\<REDACTED>\Desktop\just_a_test\CMakeFiles\3.22.5\VCTargetsPath.vcxproj" on node 1 (default targets).
    C:\Users\<REDACTED>\Desktop\just_a_test\CMakeFiles\3.22.5\VCTargetsPath.vcxproj(14,2): error MSB4019: The imported project "C:\Microsoft.Cpp.Default.props" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
    Done Building Project "C:\Users\<REDACTED>\Desktop\just_a_test\CMakeFiles\3.22.5\VCTargetsPath.vcxproj" (default targets) -- FAILED.

    Build FAILED.

    "C:\Users\<REDACTED>\Desktop\just_a_test\CMakeFiles\3.22.5\VCTargetsPath.vcxproj" (default target) (1) ->
      C:\Users\<REDACTED>\Desktop\just_a_test\CMakeFiles\3.22.5\VCTargetsPath.vcxproj(14,2): error MSB4019: The imported project "C:\Microsoft.Cpp.Default.props" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.

        0 Warning(s)
        1 Error(s)

    Time Elapsed 00:00:00.08


  Exit code: 1



-- Configuring incomplete, errors occurred!
See also "C:/Users/<REDACTED>/Desktop/just_a_test/CMakeFiles/CMakeOutput.log"

Hmmm I don’t have any further ideas. You’re using a really old Visual Studio version, but I think that should still be supported. Maybe not for the support you’re looking for though. I’m not a Fortran user, so I am not familiar with any minimum requirements for that. I’ll have to defer to others for further suggestions of what to explore next.

1 Like

Thank you for your help. Yes, I understand that the version of Visual Studio is really old, but like I said, it is a company computer, I can only install certain softwares, etc. I would like to install a newer version of Visual Studio, but I don’t know if that is a corporate battle I am willing to fight at this moment…

Upon further investigation, specially from the log files, I discovered that CMake fails to compile a Fortran code that it uses to determine in which system it is running. I think this is happening because the code uses Fortran PreProcessor (FPP) and my compiler by default doesn’t run with FPP, and I have not instructed CMake how to run the compiler with that option set (ifort /fpp)… I don’t know how to do that either. So the compiler fails and CMake just assumes some system (presumabely the wrong one) and then messes thing up