macro (ENSURE_OUT_OF_SOURCE_BUILD)
    get_filename_component(srcdir "${CMAKE_SOURCE_DIR}" REALPATH)
    get_filename_component(bindir "${CMAKE_BINARY_DIR}" REALPATH)
    
    if("${srcdir}" STREQUAL "${bindir}")
            message("**************************************************************************")
            message("* Chaste should not be configured and build in the source directory.     *")
            message("*                                                                        *")
            message("* Please run cmake in a separate build directory. For example:           *")
            message("*                                                                        *")
            message("*    mkdir ~/tmp/build")
            message("*    cd ~/tmp/build")
            message("*    cmake ${CMAKE_SOURCE_DIR}")
            message("*                                                                        *")
            message("* Note that this configuration attempt will generate the following files *")
            message("*                                                                        *")
            message("*    ${CMAKE_SOURCE_DIR}/CMakeCache.txt")
            message("*    ${CMAKE_SOURCE_DIR}/CMakeFiles/*")
            message("*                                                                        *")
            message("* These should be removed prior to the new configuration attempt.        *")
            message("* (if they are not removed, you will see this message again...)          *")
            message("**************************************************************************")
            message(FATAL_ERROR "Quitting configuration")
    endif ()
endmacro (ENSURE_OUT_OF_SOURCE_BUILD)
