Skip to content

Commit 4e8b4c7

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 4e8b4c7

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
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+
" (see also: COMPILING.md)")
9+
endif()
10+
311
# Build a Release version by default (default build flags for each build type
412
# are configured below).
513
if (NOT EXISTS ${CMAKE_BINARY_DIR}/CMakeCache.txt)
@@ -8,6 +16,7 @@ if (NOT EXISTS ${CMAKE_BINARY_DIR}/CMakeCache.txt)
816
endif()
917
endif()
1018

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

0 commit comments

Comments
 (0)