# ICEDUST_CREATE_ROOT_DICTIONARIES
# --------------------------------
#
# Macro to check if the build directory is outside of our sources
# e.g.: Throw a fatal error if cmake is invoked from within the source code directory tree
#
# IMPORTANT: it only pseudo forces "out-of-source" builds as we just check if our
# build directory is not inside the source-tree. If one specifies where build files 
# are written to one can circumvent this macro!
#
# Usage
# ^^^^^
#
#---ICEDUST_ensure_out_of_source_build()
#
#
# manager COMET Software Group
# author andreas.jansen@tu-dresden.de

macro (ICEDUST_ensure_out_of_source_build)
    string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}" in_source)
    string(REGEX MATCH "${CMAKE_SOURCE_DIR}/" in_source_subdir "${CMAKE_BINARY_DIR}")
    
    if (in_source OR in_source_subdir)
        message(FATAL_ERROR "
            ERROR: ICEDUST requires an out-of-source build.
            A separate >build< directory (otuside of 'ICEDUST_packages' is required.
            Please create one and run cmake from the build directory again.
            Also note that cmake may have just added files to your source code directory.
            We suggest getting a new copy of the source code.
            Otherwise, delete `CMakeCache.txt' and the directory `CMakeFiles'!
            ")
    endif ()
endmacro (ICEDUST_ensure_out_of_source_build)