Is there a guide on how to configure CMake with MinGW/MSYS and git on Windows?

Hi all,

I am a maintainer of a library (OpenXLSX) and have recently augmented the CMake configuration to auto-pull dependencies via find_package or FetchContent from their source repositories, instead of including a copy of the dependencies with our own library.

I have been asking one of our Windows users to test a new configuration for me, and it seems to be non-trivial to get git working for FetchContent.

On their configuration, CMake complains about not finding git.

As this is a generic “getting started” problem:

Is there a comprehensive guide on installing CMake on Windows so that integration with git is working & commands like FetchContent can be used?

I have no access to a Windows test system, so I can’t trial & error a solution for this.

Any help is appreciated so I can instruct our users on how to prepare their CMake for building OpenXLSX.

Cheers!

Do you mean building under MinGW/MSYS or working under windows with git for windows?

See Using CMake in MSYS2 - MSYS2

With you phrasing this as an “or” question - are you saying that CMake on Windows runs without MinGW?

My question, reduced to the simplest form is:

“How do Windows users install CMake so that it can build projects whose CMake configuration invokes FetchContent commands?”

with the implication being that - as per the observed errors - FetchContent uses git in the background, and CMake in the install that my user reported a test from, does not “find” git.

That depends on what they want todo?

What is your build system and what os target system?

And what is the toolchain you want to use?

The key is to use a consistent MinGW environment, not MSYS or Git Bash.

Install via MSYS2:

  • mingw-w64-x86_64-cmake

  • mingw-w64-x86_64-toolchain

  • git

Then run everything from the MinGW64 shell:

cmake -G Ninja ..
cmake --build .

FetchContent works out of the box as long as Git is available in PATH.

Avoid mixing MSYS, MinGW, and Git Bash—they use different environments and will break detection.

Your last bullet list sounds like what I am looking for, and reasonably to the point.
Regarding your prior comment: I don’t understand the question about the build system - it’s CMake, hence me posting here :slight_smile: The target system for Windows users is the system on which the build is taking place, i.e. also Windows.

For the toolchain: I would assume both work, gcc/g++ or MSVC, but I have no experience with MSVC (nor do I intend to ever touch it), so let’s focus on g++ for starters.

I will see if one of our users can test the installation sequence you proposed:

  • install MSYS2
  • via MSYS2, install
    • mingw-w64-x86_64-cmake
    • mingw-w64-x86_64-toolchain
    • git
  • run cmake from the mingw64 shell (without ninja, which I assume you wrote as an example)