Skip to content

Commit 64e2bae

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 64e2bae

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
cmake_minimum_required(VERSION 3.2)
22

3+
# If cbmc 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+
"Do not generate CMake files inside of the cbmc source directory. "
7+
"Please either create a separate build directory and invoke cbmc from there, or specify a build directory with -B.")
8+
endif()
9+
310
# Build a Release version by default (default build flags for each build type
411
# are configured below).
512
if (NOT EXISTS ${CMAKE_BINARY_DIR}/CMakeCache.txt)
@@ -8,6 +15,7 @@ if (NOT EXISTS ${CMAKE_BINARY_DIR}/CMakeCache.txt)
815
endif()
916
endif()
1017

18+
1119
# Grab the current CBMC version from config.inc
1220
# We do this so we have a matching cbmc version between the Makefile build and
1321
# the CMake build. This version info is useful for things like generating

0 commit comments

Comments
 (0)