Skip to content

Commit 84dfef7

Browse files
committed
Disallow in-source build (build-root is directory with top-level CMakeLists.txt)
1 parent 3475102 commit 84dfef7

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
cmake_minimum_required(VERSION 3.16)
2+
3+
# Require out-of-source builds
4+
file(TO_CMAKE_PATH "${CMAKE_BINARY_DIR}/CMakeLists.txt" LOC_PATH)
5+
if(EXISTS "${LOC_PATH}")
6+
message(
7+
FATAL_ERROR
8+
"You cannot build in a source directory (or any directory with a CMakeLists.txt file). "
9+
"Please make a build subdirectory.")
10+
endif()
11+
212
include(CMakeDependentOption)
313
if(POLICY CMP0135) # https://cmake.org/cmake/help/git-stage/policy/CMP0135.html
414
cmake_policy(SET CMP0135 NEW)

0 commit comments

Comments
 (0)