Block in-source builds and add clean_all target
Summary: Add detecting and blocking in-source builds A simple cmake function, which detects if the source and build dir are one and the same. This unfortunately does not catch the case when the build dir is inside the source dir, since we actually want to support that. For example, creating a 'build' directory inside the project source directory should be allowed. Add a clean_all custom target in cmake This target will clean all the files inside the build directory. It should be used with care! A new cmake module is created, since invoking cmake -E remove_directory will delete the directory and we want to keep it. This way, we also avoid using platform specific shell command, i.e `rm -rf` and we can make clean_all smarter in the future. Untrack build/.gitignore from git Reviewers: buda Reviewed By: buda Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D92
This commit is contained in:
parent
57f1b40d8d
commit
e94969000a
2
.gitignore
vendored
2
.gitignore
vendored
@ -20,7 +20,7 @@ release/memgraph_*
|
||||
release/libs/
|
||||
release/barrier/
|
||||
release/barrier_*
|
||||
build/compiled/
|
||||
build/
|
||||
cmake-build-*
|
||||
.idea
|
||||
cmake/DownloadProject/
|
||||
|
@ -40,6 +40,13 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake)
|
||||
include(functions)
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
# We want out of source builds, so that cmake generated files don't get mixed
|
||||
# with source files. This allows for easier clean up.
|
||||
disallow_in_source_build()
|
||||
add_custom_target(clean_all
|
||||
COMMAND ${CMAKE_COMMAND} -P ${PROJECT_SOURCE_DIR}/cmake/clean_all.cmake
|
||||
COMMENT "Removing all files in ${CMAKE_BINARY_DIR}")
|
||||
|
||||
# threading
|
||||
find_package(Threads REQUIRED)
|
||||
# -----------------------------------------------------------------------------
|
||||
|
2
build/.gitignore
vendored
2
build/.gitignore
vendored
@ -1,2 +0,0 @@
|
||||
/*
|
||||
!.gitignore
|
2
cmake/clean_all.cmake
Normal file
2
cmake/clean_all.cmake
Normal file
@ -0,0 +1,2 @@
|
||||
file(GLOB build_contents "${CMAKE_BINARY_DIR}/*")
|
||||
file(REMOVE_RECURSE ${build_contents})
|
@ -27,3 +27,19 @@ MACRO(SUBDIRLIST result curdir)
|
||||
ENDFOREACH()
|
||||
SET(${result} ${dirlist})
|
||||
ENDMACRO()
|
||||
|
||||
function(disallow_in_source_build)
|
||||
get_filename_component(src_dir ${CMAKE_SOURCE_DIR} REALPATH)
|
||||
get_filename_component(bin_dir ${CMAKE_BINARY_DIR} REALPATH)
|
||||
message(STATUS "SOURCE_DIR" ${src_dir})
|
||||
message(STATUS "BINARY_DIR" ${bin_dir})
|
||||
# Do we maybe want to limit out-of-source builds to be only inside a
|
||||
# directory which contains 'build' in name?
|
||||
if("${src_dir}" STREQUAL "${bin_dir}")
|
||||
# Unfortunately, we cannot remove CMakeCache.txt and CMakeFiles here
|
||||
# because they are written after cmake is done.
|
||||
message(FATAL_ERROR "In source build is not supported! "
|
||||
"Remove CMakeCache.txt and CMakeFiles and then create a separate "
|
||||
"directory, e.g. 'build' and run cmake there.")
|
||||
endif()
|
||||
endfunction()
|
||||
|
Loading…
Reference in New Issue
Block a user