-
Notifications
You must be signed in to change notification settings - Fork 274
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
Prevent users from misusing CMake #5782
Conversation
64e2bae
to
4e8b4c7
Compare
Codecov Report
@@ Coverage Diff @@
## develop #5782 +/- ##
========================================
Coverage 69.64% 69.64%
========================================
Files 1248 1248
Lines 100920 100920
========================================
Hits 70290 70290
Misses 30630 30630
Flags with carried forward coverage won't be shown. Click here to find out more. Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for adding those changes (and @TGWDB thank you for raising this topic!) The wording could do with some tweaking as indicated by my comments below.
CMakeLists.txt
Outdated
if("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}") | ||
message(FATAL_ERROR | ||
"Do not generate CMake files inside of the cbmc source directory." | ||
" Please either create a separate build directory and invoke cbmc from there, or specify a build directory with -B." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/cbmc/cmake/ ?
CMakeLists.txt
Outdated
@@ -8,6 +16,7 @@ if (NOT EXISTS ${CMAKE_BINARY_DIR}/CMakeCache.txt) | |||
endif() | |||
endif() | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Necessary change?
CMakeLists.txt
Outdated
@@ -1,5 +1,13 @@ | |||
cmake_minimum_required(VERSION 3.2) | |||
|
|||
# If cbmc generates files inside of the cbmc source directory this can lead to important files being overwritten, so we prevent that here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does "cbmc" generate anything (at build time!)?
CMakeLists.txt
Outdated
# If cbmc 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 | ||
"Do not generate CMake files inside of the cbmc source directory." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about the wording here: you are talking to the user here, who just invoked cmake
- they didn't actually (intend to) create any files at all, and might thus be confused by this error message.
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.
4e8b4c7
to
e832c07
Compare
@tautschnig I updated the wording |
That's great, thank you very much! |
" 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" |
There was a problem hiding this comment.
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.
Looks fine for checking the single top level directory, do we care about mistakes related to subdirectories as well? |
@TGWDB I'm trying to prevent accidental misuse, it seems unlikely to me that someone would do that by accident? |
@hannes-steffenhagen-diffblue Probably not a concern then, there is always a limit to how much safety/checking we can do. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, only one question, why are there 2 spaces in some lines (for example line 10)?
But perhaps that's still easy to add by replacing the |
@tautschnig Except that this then prevents building in a subdirectory called "build" since the prefix will match. |
Err, of course true. Let's stick with the current approach for now. |
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.