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