Skip to content

Prevent users from misusing CMake #5782

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
cmake_minimum_required(VERSION 3.2)

# If cmake generates files inside of the cbmc source directory this can lead to important files being overwritten, so we prevent that here
if("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")
message(FATAL_ERROR
"We have detected that you were trying to invoke cmake with its output"
" directory being equal to the source directory. You may have done this by"
" accident by invoking cmake from the cbmc top level directory without"
" specifying a build directory. Since this can lead to cmake overwriting"
" files in the source tree, this is prohibited. Please perform an"
" out-of-source build by either creating a separate build directory and"
" invoking cmake from there, or specifying a build directory with -B.\n"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add 'flag' or 'option' after -B?

..., or specifying a build directory using -B option.

"(see also: COMPILING.md)\n"
"Note that running this command will have created CMakeCache.txt"
" and a CMakeFiles directory; You should delete both of them.")
endif()

# Build a Release version by default (default build flags for each build type
# are configured below).
if (NOT EXISTS ${CMAKE_BINARY_DIR}/CMakeCache.txt)
Expand Down