BuildMacOS.sh 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. #!/bin/bash
  2. #
  3. # This script can download and compile dependencies, compile SuperSlicer
  4. # and optional build a .tgz and an appimage.
  5. #
  6. # Original script from SuperSlicer by supermerill https://github.com/supermerill/SuperSlicer
  7. #
  8. # Change log:
  9. #
  10. # 20 Nov 2023, wschadow, branding and minor changes
  11. # 01 Jan 2024, wschadow, added build options
  12. # 08 august 2024, various people, many updates, allow arm native build.
  13. #
  14. export ROOT=`pwd`
  15. export NCORES=`sysctl -n hw.ncpu`
  16. export CMAKE_INSTALLED=`which cmake`
  17. export ARCH=$(uname -m)
  18. OS_FOUND=$( command -v uname)
  19. case $( "${OS_FOUND}" | tr '[:upper:]' '[:lower:]') in
  20. linux*)
  21. TARGET_OS="linux"
  22. ;;
  23. msys*|cygwin*|mingw*)
  24. # or possible 'bash on windows'
  25. TARGET_OS='windows'
  26. ;;
  27. nt|win*)
  28. TARGET_OS='windows'
  29. ;;
  30. darwin)
  31. TARGET_OS='macos'
  32. ;;
  33. *)
  34. TARGET_OS='unknown'
  35. ;;
  36. esac
  37. # check operating system
  38. echo
  39. if [ $TARGET_OS == "macos" ]; then
  40. if [ $(uname -m) == "x86_64" ]; then
  41. echo -e "$(output setaf 2)macOS x86_64 found$(output sgr0)\n"
  42. Processor="x86_64"
  43. elif [[ $(uname -m) == "i386" || $(uname -m) == "i686" || $(uname -m) == "arm64" ]]; then
  44. echo "$(output setaf 2)macOS arm64 found$(output sgr0)\n"
  45. Processor="arm64"
  46. else
  47. echo "$(output setaf 1)Unsupported OS: macOS $(uname -m)"
  48. exit -1
  49. fi
  50. else
  51. echo -e "$(output setaf 1)This script doesn't support your Operating system!"
  52. echo -e "Please use a macOS.$(output sgr0)\n"
  53. exit -1
  54. fi
  55. # Check if CMake is installed
  56. if [[ -z "$CMAKE_INSTALLED" ]]
  57. then
  58. echo "Can't find CMake. Either is not installed or not in the PATH. Aborting!"
  59. exit -1
  60. fi
  61. while getopts ":idaxbhcstwr" opt; do
  62. case ${opt} in
  63. i )
  64. BUILD_IMAGE="1"
  65. ;;
  66. d )
  67. BUILD_DEPS="1"
  68. ;;
  69. a )
  70. BUILD_ARCH="arm64"
  71. BUILD_IMG="-a"
  72. ;;
  73. x )
  74. BUILD_ARCH="x86_64"
  75. BUILD_IMG="-x"
  76. ;;
  77. b )
  78. BUILD_DEBUG="1"
  79. ;;
  80. s )
  81. BUILD_SLIC3R="1"
  82. ;;
  83. t)
  84. BUILD_TESTS="1"
  85. ;;
  86. c)
  87. BUILD_XCODE="1"
  88. ;;
  89. w )
  90. BUILD_WIPE="1"
  91. ;;
  92. r )
  93. BUILD_CLEANDEPEND="1"
  94. ;;
  95. h ) echo "Usage: ./BuildMacOS.sh [-h][-w][-d][-r][-a][-x][-b][-c][-s][-t][-i]"
  96. echo " -h: this message"
  97. echo " -w: wipe build directories before building"
  98. echo " -d: build dependencies"
  99. echo " -r: clean dependencies building files (reduce disk usage)"
  100. echo " -a: build for arm64 (Apple Silicon)"
  101. echo " -x: build for x86_64 (Intel)"
  102. echo " -b: build with debug symbols"
  103. echo " -c: build for XCode"
  104. echo " -s: build Slic3r/SuperSlicer"
  105. echo " -t: build tests (in combination with -s)"
  106. echo " -i: generate DMG image (optional)\n"
  107. exit 0
  108. ;;
  109. esac
  110. done
  111. if [ $OPTIND -eq 1 ]
  112. then
  113. echo "Usage: ./BuildLinux.sh [-h][-w][-d][-r][-a][-x][-b][-c][-s][-t][-i]"
  114. echo " -h: this message"
  115. echo " -w: wipe build directories before building"
  116. echo " -d: build dependencies"
  117. echo " -r: clean dependencies building files (reduce disk usage)"
  118. echo " -a: build for arm64 (Apple Silicon)"
  119. echo " -x: build for x86_64 (Intel)"
  120. echo " -b: build with debug symbols"
  121. echo " -c: build for XCode"
  122. echo " -s: build Slic3r/SuperSlicer"
  123. echo " -t: build tests (in combination with -s)"
  124. echo -e " -i: Generate DMG image (optional)\n"
  125. exit 0
  126. fi
  127. echo "Build architecture: ${BUILD_ARCH}"
  128. echo "\n/Applications:\n"
  129. ls /Applications
  130. echo "\n/Applications/Xcode_13.2.1.app:\n"
  131. ls /Applications/Xcode_13.2.1.app
  132. echo "\n/Applications/Xcode_13.2.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs:\n"
  133. ls /Applications/Xcode_13.2.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs
  134. echo "\n/Applications/Xcode_13.2.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/lib:\n"
  135. ls /Applications/Xcode_13.2.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/lib
  136. # Iconv: /Applications/Xcode_13.2.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/lib/libiconv.tbd
  137. echo "\nbrew --prefix libiconv:\n"
  138. brew --prefix libiconv
  139. echo "\nbrew --prefix zstd:\n"
  140. brew --prefix zstd
  141. export LIBRARY_PATH=$LIBRARY_PATH:$(brew --prefix zstd)/lib/
  142. # not enough to fix the issue on cross-compiling
  143. #if [[ -n "$BUILD_ARCH" ]]
  144. #then
  145. # export LIBRARY_PATH=$LIBRARY_PATH:$(brew --prefix libiconv)/lib/
  146. #fi
  147. echo -n "[1/9] Updating submodules..."
  148. {
  149. # update submodule profiles
  150. pushd resources/profiles
  151. git submodule update --init
  152. popd
  153. } #> $ROOT/build/Build.log # Capture all command output
  154. echo "done"
  155. echo -n "[2/9] Changing date in version..."
  156. {
  157. # change date in version
  158. sed "s/+UNKNOWN/_$(date '+%F')/" version.inc > version.date.inc
  159. mv version.date.inc version.inc
  160. } #&> $ROOT/build/Build.log # Capture all command output
  161. echo "done"
  162. if [[ -n "$BUILD_DEPS" ]]
  163. then
  164. if [[ -n $BUILD_WIPE ]]
  165. then
  166. echo -e "\n wiping deps/build directory ...\n"
  167. rm -fr deps/build
  168. echo -e " ... done\n"
  169. fi
  170. # mkdir in deps
  171. if [ ! -d "deps/build" ]
  172. then
  173. mkdir deps/build
  174. fi
  175. echo -e " \n[3/9] Configuring dependencies ... \n"
  176. BUILD_ARGS=""
  177. if [[ -n "$BUILD_ARCH" ]]
  178. then
  179. BUILD_ARGS="${BUILD_ARGS} -DCMAKE_OSX_ARCHITECTURES:STRING=${BUILD_ARCH}"
  180. fi
  181. if [[ -n "$BUILD_DEBUG" ]]
  182. then
  183. BUILD_ARGS="${BUILD_ARGS} -DCMAKE_BUILD_TYPE=Debug"
  184. fi
  185. # cmake deps
  186. echo "Cmake command: cmake .. -DCMAKE_OSX_DEPLOYMENT_TARGET=\"10.14\" ${BUILD_ARCH} "
  187. pushd deps/build > /dev/null
  188. cmake .. -DCMAKE_OSX_DEPLOYMENT_TARGET="10.14" $BUILD_ARGS
  189. echo -e "\n ... done\n"
  190. echo -e "[4/9] Building dependencies ...\n"
  191. # make deps
  192. make -j$NCORES
  193. echo -e "\n ... done\n"
  194. echo -e "[5/9] Renaming wxscintilla library ...\n"
  195. # rename wxscintilla
  196. pushd destdir/usr/local/lib > /dev/null
  197. cp libwxscintilla-3.2.a libwx_osx_cocoau_scintilla-3.2.a
  198. popd > /dev/null
  199. popd > /dev/null
  200. echo -e "\n ... done\n"
  201. fi
  202. if [[ -n "$BUILD_CLEANDEPEND" ]]
  203. then
  204. echo -e "[6/9] Cleaning dependencies...\n"
  205. pushd deps/build
  206. pwd
  207. rm -fr dep_*
  208. popd > /dev/null
  209. echo -e "\n ... done\n"
  210. fi
  211. if [[ -n "$BUILD_SLIC3R" ]]
  212. then
  213. echo -e "[5/9] Configuring Slicer ...\n"
  214. if [[ -n $BUILD_WIPE ]]
  215. then
  216. echo -e "\n wiping build directory...\n"
  217. rm -fr build
  218. echo -e " ... done\n"
  219. fi
  220. # mkdir build
  221. if [ ! -d "build" ]
  222. then
  223. mkdir build
  224. fi
  225. BUILD_ARGS=""
  226. if [[ -n "$BUILD_ARCH" ]]
  227. then
  228. BUILD_ARGS="${BUILD_ARGS} -DCMAKE_OSX_ARCHITECTURES=${BUILD_ARCH}"
  229. fi
  230. if [[ -n "$BUILD_DEBUG" ]]
  231. then
  232. BUILD_ARGS="-DCMAKE_BUILD_TYPE=Debug ${BUILD_ARGS}"
  233. fi
  234. if [[ -n "$BUILD_XCODE" ]]
  235. then
  236. BUILD_ARGS="-GXcode ${BUILD_ARGS}"
  237. fi
  238. if [[ -n "$BUILD_TESTS" ]]
  239. then
  240. BUILD_ARGS="${BUILD_ARGS} -DCMAKE_BUILD_TESTS=1"
  241. else
  242. BUILD_ARGS="${BUILD_ARGS} -DCMAKE_BUILD_TESTS=0"
  243. fi
  244. # cmake
  245. pushd build > /dev/null
  246. cmake .. -DCMAKE_PREFIX_PATH="$PWD/../deps/build/destdir/usr/local" -DCMAKE_OSX_DEPLOYMENT_TARGET="10.14" -DSLIC3R_STATIC=1 ${BUILD_ARGS}
  247. echo -e "\n ... done"
  248. # make Slic3r
  249. if [[ -z "$BUILD_XCODE" ]]
  250. then
  251. echo -e "\n[6/9] Building Slicer ...\n"
  252. make -j$NCORES
  253. echo -e "\n ... done"
  254. fi
  255. echo -e "\n[7/9] Generating language files ...\n"
  256. #make .mo
  257. make gettext_po_to_mo
  258. popd > /dev/null
  259. echo -e "\n ... done"
  260. # Give proper permissions to script
  261. chmod 755 $ROOT/build/src/BuildMacOSImage.sh
  262. pushd build > /dev/null
  263. $ROOT/build/src/BuildMacOSImage.sh -p $BUILD_IMG
  264. popd > /dev/null
  265. echo "ls ROOT"
  266. ls $ROOT
  267. echo "ls ROOT/build"
  268. ls $ROOT/build
  269. echo "ls -al ROOT/build/src"
  270. ls -al $ROOT/build/src
  271. fi
  272. if [[ -n "$BUILD_IMAGE" ]]
  273. then
  274. # Give proper permissions to script
  275. chmod 755 $ROOT/build/src/BuildMacOSImage.sh
  276. pushd build > /dev/null
  277. $ROOT/build/src/BuildMacOSImage.sh -i $BUILD_IMG
  278. popd > /dev/null
  279. fi