Is it possible to expand `include(foo.cmake)`'s content in cmake?

I would like to get the "expanded CMakeLists.txt" that replace each include(foo.cmake) with corresponding content. Don't know if it is possible.

For example, I have CMakeLists.txt with contents:

cmake_minimum_required(VERSION 3.20)
project(hello)
include(hello.cmake)
message(STATUS "***** hello_str is ${hello_str}")

and hello.cmake with contents:

set(hello_str "Hello, World")

I would get an expaned CMakeLists.txt with contents (yeah, just like C/C++'s preprocess)

cmake_minimum_required(VERSION 3.20)
project(hello)
set(hello_str "Hello, World") ##!!
message(STATUS "***** hello_str is ${hello_str}")

Is that possible? And how?


OK, due to people in the comments really didn't understand, I have to make it more clear.

In the cross-compilation stage, the commonly usage is:

mkdir build && cd build
cmake .. -DCMAKE_TOOLCHAIN_FILE=qnx-aarch64.toolchain.cmake
cmake --build .

But actually the qnx-aarch64.toolchain.cmake contains one line:

include(linux-aarch64.toolchain.cmake)

Thus, people have to have both qnx-aarch64.toolchain.cmake and linux-aarch64.toolchain.cmake, instead only one qnx-aarch64.toolchain.cmake file.

What I expected is only one qnx-aarch64.toolchain.cmake file to finish the cross-compilation.

@fabian You don't understand my question and keep telling very simple stuffs and assumes I don't know those stuffs.


Is that possible?

No. CMake 3.22 (the current at time of writing) and below do not provide this feature.