Skip to content

Commit e832c07

Browse files
author
Hannes Steffenhagen
committed
Prevent users from misusing CMake
When CMake is invoked from the source directory it will overwrite files in there. In general CMake expects to be used for out-of-source builds. Previously it was still possible to get this wrong by accident, this just adds a check to prevent this from happening and tells people what to do instead.
1 parent 5efb6ad commit e832c07

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)