-
Notifications
You must be signed in to change notification settings - Fork 0
/
PreventInSourceBuilds.cmake
28 lines (26 loc) · 1.24 KB
/
PreventInSourceBuilds.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
include_guard(GLOBAL)
include(Missives)
# This function will prevent in-source builds
function(prevent_in_source_builds)
cmake_parse_arguments(ARGS "REMOVE_FILES" "" "" "${ARGN}")
# make sure the user doesn't play dirty with symlinks
get_filename_component(SRC_DIR "${CMAKE_SOURCE_DIR}" REALPATH)
get_filename_component(BIN_DIR "${CMAKE_BINARY_DIR}" REALPATH)
# disallow in-source builds
if("${SRC_DIR}" STREQUAL "${BIN_DIR}")
if(NOT ${PROJECT_NAME} STREQUAL "")
missive(ERROR "${PROJECT_NAME} should not be configured & built in the ${PROJECT_NAME} source directory \"${CMAKE_SOURCE_DIR}\"")
else()
missive(ERROR "Project should not be configured & built in the project source directory \"${CMAKE_SOURCE_DIR}\"")
endif()
missive(ERROR "You must run cmake in a build directory.")
missive(ERROR "If you ran this function close to the project command you only have to delete the CMakeFiles folder and CMakeCache.txt file.")
if(EXISTS "${CMMM_INSTALL_DESTINATION}")
file(REMOVE_RECURSE "${CMMM_INSTALL_DESTINATION}")
endif()
if(EXISTS "${CMMM_DESTINATION_MODULES}")
file(REMOVE_RECURSE "${CMMM_DESTINATION_MODULES}")
endif()
missive(FATAL_ERROR "Quitting configuration")
endif()
endfunction()