#
# Prevent the user from performing an in source build
#

# Make sure the user doesn't play dirty with symlinks
get_filename_component(srcdir "${CMAKE_SOURCE_DIR}" REALPATH)
get_filename_component(bindir "${CMAKE_BINARY_DIR}" REALPATH)

if("${srcdir}" STREQUAL "${bindir}")
    message("")
	message("===================================================================")
	message("~~~~~~~~~~~~~~ In-source builds are not permitted ~~~~~~~~~~~~~~~~~")
	message("===================================================================")
	message("")
	message("This library has been configured to prevent building within the")
	message("source tree. You must build within a seperate directory to keep")
	message("configurations seperate and not pollute the source tree.")
	message("")
	message("For Example:")
	message("> mkdir <program>-sandbox")
	message("> cd <program>-sandbox")
	message("> git clone <program> OR Download and unpack source tarball")
	message("> mkdir <program>-build")
	message("")
	message("This will create the following directory structure.")
	message(" <program>-sandbox")
	message("  +-- <program>")
	message("  +-- <program>-build")
	message("")
	message("Now proceed to configure and build by using the following commands.")
	message("")
	message("> cd <program>-build")
	message("> cmake ../<program>")
	message("> make")
	message("")
	message("--- IMPORTANT ---")
	message("Given that you already tried to make an in-source build CMake has")
	message("already created several files and directories in your source tree.")
	message("You must run 'git status' to find them and remove them by doing.")
	message("")
	message("> cd <program>-sandbox/<program>")
    message("> git clean -n -d")
    message("> git clean -f -d")
    message("> git checkout --")
	message("")
	message("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^")
	message("              PLEASE READ ABOVE MESSAGE & INSTRUCTIONS")
	message("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^")
	message("")    
	message(FATAL_ERROR)
endif()

