# Does CMake have a REPL (Read-Eval-Print Loop) ?

**URL:** https://discourse.cmake.org/t/does-cmake-have-a-repl-read-eval-print-loop/6370
**Category:** Development
**Created:** [August 29, 2022, 7:14am UTC](https://discourse.cmake.org/t/does-cmake-have-a-repl-read-eval-print-loop/6370 "2022-08-29T07:14:01Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![EricGT](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/e/f1d935/32.png) [@EricGT](https://discourse.cmake.org/u/EricGT)
#### Post date: [August 29, 2022, 7:14am UTC](https://discourse.cmake.org/t/does-cmake-have-a-repl-read-eval-print-loop/6370/1 "2022-08-29T07:14:01Z")

</div>

As the title says:

> Does CMake have a [REPL](https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop) (Read-Eval-Print Loop) ?

At present I am fairly sure the answer is no but better to ask than not.

* * *

Remember I am new to CMake so if something is wrong here please point it out.

Why would one need a REPL for CMake?

One of the first things one does when creating a new CmakeLists.txt file is to use one of the find commands

- [find\_file](https://cmake.org/cmake/help/latest/command/find_file.html)
- [find\_library](https://cmake.org/cmake/help/latest/command/find_library.html)
- [find\_package](https://cmake.org/cmake/help/latest/command/find_package.html)
- [find\_path](https://cmake.org/cmake/help/latest/command/find_path.html)
- [find\_program](https://cmake.org/cmake/help/latest/command/find_program.html)

AFAIK the only way to see what a find command is searching is to use the [CMAKE\_FIND\_DEBUG\_MODE](https://cmake.org/cmake/help/latest/variable/CMAKE_FIND_DEBUG_MODE.html) or something similar but such requires running cmake as a program for the entire process. If one thinks of a build as a tree of goals with one of the branches being a find which can also be a tree of sub find goals then why not just run the find command interactively and modify the find subgoals until the find command is working as expected. This way a user can more quickly see what a find is doing, learn how a find works faster as a new user and also see spurious results that can be pruned from the search.

While this notes find as an example there are many more such reasons to have a REPL, think building up the root goal (CMakeLists.txt) from many branches and leaves of the problem state.

* * *

In researching this question am just now finding

- [cmake-file-api](https://cmake.org/cmake/help/latest/manual/cmake-file-api.7.html). Could that be a segue to creating a REPL by using the CMake API from a language with an existing REPL? I don’t see find results as objects but perhaps that could easily be added.
- [cmake\_language](https://cmake.org/cmake/help/v3.24/command/cmake_language.html)
- [Why CMake functions can’t return value?](https://discourse.cmake.org/t/why-cmake-functions-cant-return-value/1710)

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [August 29, 2022, 11:00am UTC](https://discourse.cmake.org/t/does-cmake-have-a-repl-read-eval-print-loop/6370/2 "2022-08-29T11:00:12Z")

</div>

CMake has a _lot_ of state that gets carried around. I suppose some kind of “find” REPL might be possible since the state space is small, but there will be issues around `find_package` since some packages want languages enabled to be able to query the compiler. This kind of stuff generally just requires the cache.

I suppose a tool could be proposed where setup is done and “snapshotted” and then some specific sequence of commands is run based on that snapshot. Editing any of the setup prep would obviously require making a new snapshot from the beginning (or perhaps the prior snapshot). The state is tidier than it used to be, but lifetime issues may arise when trying to rewind the state like this.

---

<div class="post-metadata">

### Author: ![Freed-Wu](https://discourse.cmake.org/user_avatar/discourse.cmake.org/freed-wu/32/3347_2.png) [@Freed-Wu](https://discourse.cmake.org/u/Freed-Wu)
#### Post date: [May 10, 2023, 2:29pm UTC](https://discourse.cmake.org/t/does-cmake-have-a-repl-read-eval-print-loop/6370/3 "2023-05-10T14:29:56Z")

</div>

Is [https://github.com/hnspn/cmake-repl](https://github.com/hnspn/cmake-repl) your need?

---

<div class="post-metadata">

### Author: ![EricGT](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/e/f1d935/32.png) [@EricGT](https://discourse.cmake.org/u/EricGT)
#### Post date: [May 11, 2023, 6:48am UTC](https://discourse.cmake.org/t/does-cmake-have-a-repl-read-eval-print-loop/6370/4 "2023-05-11T06:48:28Z")

</div>

Thanks.

It is interesting, however I am not actively developing with CMake so checking this in detail to answer the question may be years from now, if ever. If I do need a CMake REPL again I will give this a test run and update here.
