Using CMake without a generator

Is there a way to use CMake without a generator, basically only to benefit from its multi platform features like downloading packages and so on?

We are using CMake to build projects, but also (as an option) to only download different packages and re-bundle them to a zip file (done by the configure step). In this use case (using presets) the availabe generator is not known in advance and even not needed.

I found this question, that already helps a little:

:thinking:

Yes you can use CMake in Script mode

cmake -P myscript.cmake

Options may be given like

cmake -Dmyopt=3 -P myscript.cmake

Cmake is very useful in this way. I use it a lot instead of bash or python scripts this way.

A quirrk of script mode is that because there’s no specific minimum version, cmake falls back to a 2.x compatibility, which can be surprising if you are using regex with strings, as it uses old and uncommon behavior. To avoid surprises, even though it’s not required, I put at the top of my script something like

cmake_minimum_required(VERSION 3.14)

There is even a ray tracer written in pure cmake

1 Like

Wow, that seems to be exactly what I’ve been looking for!
Thanks!