memgraph/cmake/functions.cmake
Teon Banek e94969000a 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
2017-03-07 10:00:47 +01:00

46 lines
1.7 KiB
CMake

# prints all included directories
function(list_includes)
get_property(dirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
PROPERTY INCLUDE_DIRECTORIES)
foreach(dir ${dirs})
message(STATUS "dir='${dir}'")
endforeach()
endfunction(list_includes)
# get file names from list of file paths
function(get_file_names file_paths file_names)
set(file_names "")
foreach(file_path ${file_paths})
get_filename_component (file_name ${file_path} NAME_WE)
list(APPEND file_names ${file_name})
endforeach()
set(file_names "${file_names}" PARENT_SCOPE)
endfunction()
MACRO(SUBDIRLIST result curdir)
FILE(GLOB children RELATIVE ${curdir} ${curdir}/*)
SET(dirlist "")
FOREACH(child ${children})
IF(IS_DIRECTORY ${curdir}/${child})
LIST(APPEND dirlist ${child})
ENDIF()
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()