Joachim Wuttke
2018-11-09 10:34:22 UTC
In all my projects, the top-level CMakeLists.txt contains the line
include(PreventInSourceBuilds)
to protect users (and myself) from unintentionally running CMake
in the source directory.
Would you consider adding this little module to the CMake code base?
I would then add an option so that users can override the not-in-source policy.
/Joachim
---
#.rst:
# PreventInSourceBuilds
# ---------------------
#
# Prevent in-source builds
#
# It is generally acknowledged that it is preferable to run CMake out of source,
# in a dedicated build directory. To prevent users from accidentally running
# CMake in the source directory, just include this module.
# make sure the user doesn't play dirty with symlinks
get_filename_component(srcdir "${CMAKE_SOURCE_DIR}" REALPATH)
get_filename_component(bindir "${CMAKE_BINARY_DIR}" REALPATH)
# disallow in-source builds
if("${srcdir}" STREQUAL "${bindir}")
message(FATAL_ERROR "\
CMake must not to be run in the source directory. \
Rather create a dedicated build directory and run CMake there. \
To clean up after this aborted in-source compilation:
rm -r CMakeCache.txt CMakeFiles
")
endif()
include(PreventInSourceBuilds)
to protect users (and myself) from unintentionally running CMake
in the source directory.
Would you consider adding this little module to the CMake code base?
I would then add an option so that users can override the not-in-source policy.
/Joachim
---
#.rst:
# PreventInSourceBuilds
# ---------------------
#
# Prevent in-source builds
#
# It is generally acknowledged that it is preferable to run CMake out of source,
# in a dedicated build directory. To prevent users from accidentally running
# CMake in the source directory, just include this module.
# make sure the user doesn't play dirty with symlinks
get_filename_component(srcdir "${CMAKE_SOURCE_DIR}" REALPATH)
get_filename_component(bindir "${CMAKE_BINARY_DIR}" REALPATH)
# disallow in-source builds
if("${srcdir}" STREQUAL "${bindir}")
message(FATAL_ERROR "\
CMake must not to be run in the source directory. \
Rather create a dedicated build directory and run CMake there. \
To clean up after this aborted in-source compilation:
rm -r CMakeCache.txt CMakeFiles
")
endif()