Skip to content

Commit

Permalink
Made a few improvements/corrections to the InSourceBuild CMake module.
Browse files Browse the repository at this point in the history
  • Loading branch information
mdadams committed Nov 28, 2023
1 parent a798ba0 commit 9c73145
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions build/cmake/modules/InSourceBuild.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,29 @@ function(prevent_in_source_build)
file(REAL_PATH "${CMAKE_SOURCE_DIR}" source_dir)
file(REAL_PATH "${CMAKE_BINARY_DIR}" binary_dir)
cmake_path(IS_PREFIX source_dir "${binary_dir}" result)
cmake_path(GET binary_dir FILENAME binary_dir_base)

# If an in-source build is in progress, and the build directory is not
# chosen in a very specific way, then stop the build.
if(result AND (NOT (binary_dir_base MATCHES "tmp*")))
message(FATAL_ERROR
"The use of an in-source build has been detected "
"(i.e., the binary directory specified to CMake is located "
"in or under the source directory). "
"This can potentially trash the source tree. "
"In fact, if you are seeing this message, you may have already "
"partially trashed the source tree. "
"The use of an in-source build is not officially supported and "
"is therefore disallowed by default. "
"If you like to live dangerously and would like to override "
"this default behavior, this can be accomplished via the "
"CMake option ALLOW_IN_SOURCE_BUILD."
)
if(result)
cmake_path(GET binary_dir FILENAME binary_dir_base)
if(NOT (binary_dir_base MATCHES "^tmp"))
message(FATAL_ERROR
"The use of an in-source build has been detected "
"(i.e., the binary directory specified to CMake is located "
"in or under the source directory). "
"This can potentially trash the source tree. "
"In fact, if you are seeing this message, you may have already "
"partially trashed the source tree. "
"The use of an in-source build is not officially supported and "
"is therefore disallowed by default. "
"If you like to live dangerously and would like to override "
"this default behavior, this can be accomplished via the "
"CMake option ALLOW_IN_SOURCE_BUILD.\n"
"CMake source directory: ${CMAKE_SOURCE_DIR}\n"
"CMake binary directory: ${CMAKE_BINARY_DIR}\n"
"CMake binary directory base: ${binary_dir_base}\n"
)
endif()
endif()

endfunction()
Expand Down

0 comments on commit 9c73145

Please sign in to comment.