Skip to content

Commit 77ae57e

Browse files
authored
prevent cmake in-source-build friendly (#19151)
1 parent 581c201 commit 77ae57e

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ project(Cocos2d-x)
3434
set(COCOS2DX_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR})
3535
set(CMAKE_MODULE_PATH ${COCOS2DX_ROOT_PATH}/cmake/Modules/)
3636

37+
# prevent in-source-build
38+
include(PreventInSourceBuilds)
39+
AssureOutOfSourceBuilds()
40+
3741
# works before build libcocos2d
3842
include(CocosBuildSet)
3943

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

0 commit comments

Comments
 (0)