1# 2# This function will prevent in-source builds 3function(AssureOutOfSourceBuilds) 4 # make sure the user doesn't play dirty with symlinks 5 get_filename_component(srcdir "${CMAKE_SOURCE_DIR}" REALPATH) 6 get_filename_component(bindir "${CMAKE_BINARY_DIR}" REALPATH) 7 8 # disallow in-source builds 9 if("${srcdir}" STREQUAL "${bindir}") 10 message("######################################################") 11 message("# jsoncpp should not be configured & built in the jsoncpp source directory") 12 message("# You must run cmake in a build directory.") 13 message("# For example:") 14 message("# mkdir jsoncpp-Sandbox ; cd jsoncpp-sandbox") 15 message("# git clone https://github.com/open-source-parsers/jsoncpp.git # or download & unpack the source tarball") 16 message("# mkdir jsoncpp-build") 17 message("# this will create the following directory structure") 18 message("#") 19 message("# jsoncpp-Sandbox") 20 message("# +--jsoncpp") 21 message("# +--jsoncpp-build") 22 message("#") 23 message("# Then you can proceed to configure and build") 24 message("# by using the following commands") 25 message("#") 26 message("# cd jsoncpp-build") 27 message("# cmake ../jsoncpp # or ccmake, or cmake-gui ") 28 message("# make") 29 message("#") 30 message("# NOTE: Given that you already tried to make an in-source build") 31 message("# CMake have already created several files & directories") 32 message("# in your source tree. run 'git status' to find them and") 33 message("# remove them by doing:") 34 message("#") 35 message("# cd jsoncpp-Sandbox/jsoncpp") 36 message("# git clean -n -d") 37 message("# git clean -f -d") 38 message("# git checkout --") 39 message("#") 40 message("######################################################") 41 message(FATAL_ERROR "Quitting configuration") 42 endif() 43endfunction() 44 45AssureOutOfSourceBuilds() 46