Disabling in-source builds
In Chapter 1, First Steps with CMake, we talked about in-source builds, and how it is recommended to always specify the build path to be out-of-source. This not only allows for a cleaner build tree and a simpler .gitignore
file, but it also decreases the chances you'll accidentally overwrite or delete any source files.
Searching for the solution online, you may stumble on a StackOverflow thread that asks the same question: https://stackoverflow.com/q/1208681/6659218. Here, the author notices that no matter what you do, it seems like CMake will still create a CMakeFiles/
directory and a CMakeCache.txt
file. Some answers suggest using undocumented variables to make sure that the user can't write in the source directory under any circumstances:
# add this options before PROJECT keyword set(CMAKE_DISABLE_SOURCE_CHANGES ON) set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
I'd say to be cautious when using undocumented features of any software, as...