diff --git a/build/cmake/modules/InSourceBuild.cmake b/build/cmake/modules/InSourceBuild.cmake index 4bc1a213..6953771d 100644 --- a/build/cmake/modules/InSourceBuild.cmake +++ b/build/cmake/modules/InSourceBuild.cmake @@ -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()