-
Notifications
You must be signed in to change notification settings - Fork 0
/
get-main-cmake.sh
executable file
·56 lines (46 loc) · 1.85 KB
/
get-main-cmake.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
# This script checks all the folders between the current folder (pwd) and the folder containing
# All of the cmake-scripts (not including the cmake-scripts folder),
# To find the first CMakeLists.txt.
thisScriptFolder="$(dirname "${BASH_SOURCE[0]}")"
source "$thisScriptFolder/get-platform.sh" --silent
source "$thisScriptFolder/path-utility.sh"
# EX: "PixelEngine/cmake-scripts"
relativePath="$(getRelativePath "$(pwd)" "$thisScriptFolder")"
cmakeFolder=""
cmakeFile=""
cmakeToScriptsFolder=""
foundCMakeLists=false
function checkForCMake() {
local currentPath="$1"
local possibleCMakeFile="$currentPath/CMakeLists.txt"
if [ -f "$possibleCMakeFile" ]; then
foundCMakeLists=true
cmakeFile="$possibleCMakeFile"
cmakeFolder="$(dirname $cmakeFile)"
fi
}
# NOTE: relativePath does NOT have a trailing slash (/), so we'll never check the cmake-scripts folder (good!).
checkForCMake "."
if [ $foundCMakeLists = true ]; then
cmakeToScriptsFolder="$relativePath"
else
relativePathLength=${#relativePath}
for ((i=0; i<$relativePathLength; i++)); do
currentChar="${relativePath:$i:1}"
# NOTE: printf "-" will trick printf, thinking you're trying to pass an option, and then it'll error out.
# To make sure this line only treats $currentChar as a string literal, we use %s like so:
# printf "%s " "$currentChar"
if [[ "$currentChar" = "/" ]]; then
nextFolder="${relativePath:0:$i}"
checkForCMake "$nextFolder"
if [ $foundCMakeLists = true ]; then
cmakeToScriptsFolder="${relativePath:($i + 1):($relativePathLength - 1)}"
break
fi
fi
done
fi
if [ $foundCMakeLists != true ]; then
echo "Failed to find CMakeLists.txt in current directory or any subdirectories down to the $thisScriptFolder folder."
fi