PreventInSourceBuilds.cmake 1.9 KB

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