# Using CMake without a generator

**URL:** https://discourse.cmake.org/t/using-cmake-without-a-generator/12728
**Category:** Usage
**Created:** [October 9, 2024, 10:42am UTC](https://discourse.cmake.org/t/using-cmake-without-a-generator/12728 "2024-10-09T10:42:05Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![RSin](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/r/57b2e6/32.png) [@RSin](https://discourse.cmake.org/u/RSin)
#### Post date: [October 9, 2024, 10:42am UTC](https://discourse.cmake.org/t/using-cmake-without-a-generator/12728/1 "2024-10-09T10:42:05Z")

</div>

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:

> [@Prevent FetchContent\_MakeAvailable to execute CMakeLists.txt](https://discourse.cmake.org/t/prevent-fetchcontent-makeavailable-to-execute-cmakelists-txt/12704):
>
> After seeing the deprecation warnings for FetchContent\_Populate I replaced it with FetchContent\_MakeAvailable but now my project is failing. I use to do this (in a nutshell) # ... FetchContent\_Declare(re-logging ...) FetchContent\_Populate(re-logging) include("${re-logging\_ROOT\_DIR}/re-logging.cmake") The issue I am facing with replacing FetchContent\_Populate with FetchContent\_MakeAvailable is that FetchContent\_MakeAvailable seems to automatically “execute” CMakeLists.txt included in re-loggin…

🤔

---

<div class="post-metadata">

### Author: ![scivision](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/a87d85/32.png) [@scivision](https://discourse.cmake.org/u/scivision)
#### Post date: [October 9, 2024, 6:57pm UTC](https://discourse.cmake.org/t/using-cmake-without-a-generator/12728/2 "2024-10-09T18:57:39Z")

</div>

Yes you can use CMake in [Script mode](https://cmake.org/cmake/help/latest/manual/cmake.1.html#run-a-script)

```sh
cmake -P myscript.cmake

```

Options may be given like

```sh
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
cmake_minimum_required(VERSION 3.14)

```

There is even a [ray tracer written in pure cmake](https://github.com/64/cmake-raytracer)

---

<div class="post-metadata">

### Author: ![RSin](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/r/57b2e6/32.png) [@RSin](https://discourse.cmake.org/u/RSin)
#### Post date: [October 10, 2024, 6:47am UTC](https://discourse.cmake.org/t/using-cmake-without-a-generator/12728/3 "2024-10-10T06:47:00Z")

</div>

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