To build with a read-only source directory, the build directory must reside outside of the source directory. For instance, it can be a sibling directory:
cmake -B ../build
cmake --build ../build
Running ctest
is also supported for the read-only source directory: