Skip to content

Commit f2fafac

Browse files
authored
Merge pull request #5782 from hannes-steffenhagen-diffblue/cmake/prevent-misuse
Prevent users from misusing CMake
2 parents eb148eb + e832c07 commit f2fafac

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

CMakeLists.txt

+15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
cmake_minimum_required(VERSION 3.2)
22

3+
# If cmake generates files inside of the cbmc source directory this can lead to important files being overwritten, so we prevent that here
4+
if("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")
5+
message(FATAL_ERROR
6+
"We have detected that you were trying to invoke cmake with its output"
7+
" directory being equal to the source directory. You may have done this by"
8+
" accident by invoking cmake from the cbmc top level directory without"
9+
" specifying a build directory. Since this can lead to cmake overwriting"
10+
" files in the source tree, this is prohibited. Please perform an"
11+
" out-of-source build by either creating a separate build directory and"
12+
" invoking cmake from there, or specifying a build directory with -B.\n"
13+
"(see also: COMPILING.md)\n"
14+
"Note that running this command will have created CMakeCache.txt"
15+
" and a CMakeFiles directory; You should delete both of them.")
16+
endif()
17+
318
# Build a Release version by default (default build flags for each build type
419
# are configured below).
520
if (NOT EXISTS ${CMAKE_BINARY_DIR}/CMakeCache.txt)

0 commit comments

Comments
 (0)