Merge lp:~widelands-dev/widelands/number_of_cpus_as_option into lp:widelands

Proposed by GunChleoc
Status: Merged
Merged at revision: 8914
Proposed branch: lp:~widelands-dev/widelands/number_of_cpus_as_option
Merge into: lp:widelands
Diff against target: 136 lines (+76/-31)
1 file modified
compile.sh (+76/-31)
To merge this branch: bzr merge lp:~widelands-dev/widelands/number_of_cpus_as_option
Reviewer Review Type Date Requested Status
Toni Förster Approve
Review via email: mp+358492@code.launchpad.net

Commit message

Add option to compile script to let users pick how many processor cores to compile/link with.

Description of the change

Needs testing with Mac - the Darwin detaction option was producing an error message on Linux, so I changed the syntax.

To post a comment you must log in.
Revision history for this message
Toni Förster (stonerl) wrote :

Does work on macOS. Just one nitpick -> see inline

review: Approve
Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 4190. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/452672051.
Appveyor build 3986. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_number_of_cpus_as_option-3986.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'compile.sh'
--- compile.sh 2018-11-08 08:47:48 +0000
+++ compile.sh 2018-11-09 06:44:23 +0000
@@ -40,10 +40,15 @@
40 echo " "40 echo " "
41 echo "-a or --no-asan If in debug mode, switch off the AddressSanitizer."41 echo "-a or --no-asan If in debug mode, switch off the AddressSanitizer."
42 echo " Release builds are created without AddressSanitizer"42 echo " Release builds are created without AddressSanitizer"
43 echo " per default."43 echo " by default."
44 echo " "44 echo " "
45 echo "Compiler options:"45 echo "Compiler options:"
46 echo " "46 echo " "
47 echo "-j <number> or --cores <number>"
48 echo " Set the number of processor cores to use for"
49 echo " compiling and linking. Default is to leave 1 core"
50 echo " free."
51 echo " "
47 echo "-r or --release Create a release build. If this is not set,"52 echo "-r or --release Create a release build. If this is not set,"
48 echo " a debug build will be created."53 echo " a debug build will be created."
49 echo " "54 echo " "
@@ -77,33 +82,77 @@
77BUILD_TYPE="Debug"82BUILD_TYPE="Debug"
78USE_ASAN="ON"83USE_ASAN="ON"
79COMPILER="default"84COMPILER="default"
80while [ "$1" != "" ]; do85
81 if [ "$1" = "--no-website" -o "$1" = "-w" ]; then86if [ "$(uname)" = "Darwin" ]; then
82 BUILD_WEBSITE="OFF"87 CORES="$(expr $(sysctl -n hw.ncpu) - 1)"
83 elif [ "$1" = "--release" -o "$1" = "-r" ]; then88else
84 BUILD_TYPE="Release"89 CORES="$(nproc --ignore=1)"
85 USE_ASAN="OFF"90fi
86 elif [ "$1" = "--no-translations" -o "$1" = "-t" ]; then91
87 BUILD_TRANSLATIONS="OFF"92for opt in "$@"
88 elif [ "$1" = "--no-asan" -o "$1" = "-a" ]; then93do
89 USE_ASAN="OFF"94 case $opt in
90 elif [ "$1" = "--gcc" ]; then95 -a|--no-asan)
91 if [ -f /usr/bin/gcc -a /usr/bin/g++ ]; then96 USE_ASAN="OFF"
92 export CC=/usr/bin/gcc97 shift
93 export CXX=/usr/bin/g++98 ;;
94 fi99 -h|--help)
95 elif [ "$1" = "--clang" ]; then100 print_help
96 if [ -f /usr/bin/clang -a /usr/bin/clang++ ]; then101 exit 0
97 export CC=/usr/bin/clang102 shift
98 export CXX=/usr/bin/clang++103 ;;
99 fi104 -j|--cores)
100 elif [ "$1" = "--help" -o "$1" = "-h" ]; then105 MAXCORES=$((CORES + 1))
101 print_help106 if [ "$2" ]; then
102 exit 0107 if [ "$MAXCORES" -ge "$2" ]; then
103 fi108 CORES="$2"
104 shift109 else
110 echo "Maximum number of supported cores is $MAXCORES."
111 CORES="$MAXCORES"
112 fi
113 else
114 echo "Call -j/--cores with a number, e.g. '-j $MAXCORES'"
115 exit 1
116 fi
117 shift # past argument
118 shift # past value
119 ;;
120 -r|--release)
121 BUILD_TYPE="Release"
122 USE_ASAN="OFF"
123 shift
124 ;;
125 -t|--no-translations)
126 BUILD_TRANSLATIONS="OFF"
127 shift
128 ;;
129 -w|--no-website)
130 BUILD_WEBSITE="OFF"
131 shift
132 ;;
133 --gcc)
134 if [ -f /usr/bin/gcc -a /usr/bin/g++ ]; then
135 export CC=/usr/bin/gcc
136 export CXX=/usr/bin/g++
137 fi
138 shift
139 ;;
140 --clang)
141 if [ -f /usr/bin/clang -a /usr/bin/clang++ ]; then
142 export CC=/usr/bin/clang
143 export CXX=/usr/bin/clang++
144 fi
145 shift
146 ;;
147 *)
148 # unknown option
149 ;;
150 esac
105done151done
106152
153echo "Using ${CORES} core(s)."
154echo ""
155
107if [ $BUILD_WEBSITE = "ON" ]; then156if [ $BUILD_WEBSITE = "ON" ]; then
108 echo "A complete build will be created."157 echo "A complete build will be created."
109 echo "You can use -w or --no-website to omit building and"158 echo "You can use -w or --no-website to omit building and"
@@ -199,11 +248,7 @@
199 cmake .. -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DOPTION_BUILD_WEBSITE_TOOLS=$BUILD_WEBSITE -DOPTION_BUILD_TRANSLATIONS=$BUILD_TRANSLATIONS -DOPTION_ASAN=$USE_ASAN248 cmake .. -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DOPTION_BUILD_WEBSITE_TOOLS=$BUILD_WEBSITE -DOPTION_BUILD_TRANSLATIONS=$BUILD_TRANSLATIONS -DOPTION_ASAN=$USE_ASAN
200 fi249 fi
201250
202 if [ $(uname) == "Darwin" ]; then251 $buildtool -j $CORES
203 $buildtool -j "$(expr $(sysctl -n hw.ncpu) - 1)"
204 else
205 $buildtool -j "$(nproc --ignore=1)"
206 fi
207252
208 return 0253 return 0
209 }254 }

Subscribers

People subscribed via source and target branches

to status/vote changes: