# How to Explicitly specify cmake to process a different .txt file

**URL:** https://discourse.cmake.org/t/how-to-explicitly-specify-cmake-to-process-a-different-txt-file/938
**Category:** Usage
**Tags:** os:linux
**Created:** [April 4, 2020, 7:15am UTC](https://discourse.cmake.org/t/how-to-explicitly-specify-cmake-to-process-a-different-txt-file/938 "2020-04-04T07:15:29Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![rmadhuraj](https://discourse.cmake.org/user_avatar/discourse.cmake.org/rmadhuraj/32/162_2.png) [@rmadhuraj](https://discourse.cmake.org/u/rmadhuraj)
#### Post date: [April 4, 2020, 7:15am UTC](https://discourse.cmake.org/t/how-to-explicitly-specify-cmake-to-process-a-different-txt-file/938/1 "2020-04-04T07:15:29Z")

</div>

Hi,  
Is it possible to have two List.txt files , i,e, CMakeLists1.txt and CMakeLists2.txt in a single directory and while compiling is it possible to inform cmake to consider CMakeLists2.txt for further process ? If yes what is flag should be used ?

Regards  
Madhu

---

<div class="post-metadata">

### Author: ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)
#### Post date: [April 4, 2020, 12:31pm UTC](https://discourse.cmake.org/t/how-to-explicitly-specify-cmake-to-process-a-different-txt-file/938/2 "2020-04-04T12:31:11Z")

</div>

No, it is not possible. Only files named `CMakeLists.txt` are considered when command `add_subdirectory()` is evaluated.

But you can manage similar behavior with `include()` command and `CMake` command line argument:

```cmake
# file CMakeLists.txt
...
#if (INCLUDE_EXTRA_CMAKELISTS)
  include (${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists2.txt)
#endif()

```

If you want to process extra file:

```auto
cmake -DINCLUDE_EXTRA_CMAKELISTS=ON ...

```

---

<div class="post-metadata">

### Author: ![rmadhuraj](https://discourse.cmake.org/user_avatar/discourse.cmake.org/rmadhuraj/32/162_2.png) [@rmadhuraj](https://discourse.cmake.org/u/rmadhuraj)
#### Post date: [April 4, 2020, 2:22pm UTC](https://discourse.cmake.org/t/how-to-explicitly-specify-cmake-to-process-a-different-txt-file/938/3 "2020-04-04T14:22:26Z")

</div>

@marc.chevrier Thanks for that.

Suppose i have only one directory with CMakeLists.txt and CMakeLists1.txt

So in the command line can i do something like **cmake --CMakeList1.txt …** instead of the default CMakeLists.txt ?

---

<div class="post-metadata">

### Author: ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)
#### Post date: [April 4, 2020, 2:28pm UTC](https://discourse.cmake.org/t/how-to-explicitly-specify-cmake-to-process-a-different-txt-file/938/4 "2020-04-04T14:28:46Z")

</div>

Not at all. Option `-C` is to populate the cache (file `CMakeCache.txt`).

Again, there is no way to use alternate names to `CMakeLists.txt`.

---

<div class="post-metadata">

### Author: ![rmadhuraj](https://discourse.cmake.org/user_avatar/discourse.cmake.org/rmadhuraj/32/162_2.png) [@rmadhuraj](https://discourse.cmake.org/u/rmadhuraj)
#### Post date: [April 4, 2020, 2:32pm UTC](https://discourse.cmake.org/t/how-to-explicitly-specify-cmake-to-process-a-different-txt-file/938/5 "2020-04-04T14:32:28Z")

</div>

OK , i should be thinking alternate way to deal the requirement.

Thanks Marc.

---

<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: [September 27, 2020, 8:56pm UTC](https://discourse.cmake.org/t/how-to-explicitly-specify-cmake-to-process-a-different-txt-file/938/6 "2020-09-27T20:56:07Z")

</div>

In situations where I want to automatically choose the Generator (say Ninja vs. Make) or other things that I can or cannot do within CMakeLists.txt, I use `ctest -S script.cmake` scripts. An example .cmake script I use across many projects is [https://github.com/geospace-code/h5fortran/blob/master/setup.cmake](https://github.com/geospace-code/h5fortran/blob/master/setup.cmake).

- looks for new-enough Ninja first, with Make fallback
- allows user to type single command to build and test
- control compiler preference order
- run tests in parallel

These are all doable by other means, but this is a single command that new users don’t have to be concerned with the details if it works.
