.bash_helpers.sh 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #
  2. # Copyright (c) 2008-2020 the Urho3D project.
  3. #
  4. # Permission is hereby granted, free of charge, to any person obtaining a copy
  5. # of this software and associated documentation files (the "Software"), to deal
  6. # in the Software without restriction, including without limitation the rights
  7. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. # copies of the Software, and to permit persons to whom the Software is
  9. # furnished to do so, subject to the following conditions:
  10. #
  11. # The above copyright notice and this permission notice shall be included in
  12. # all copies or substantial portions of the Software.
  13. #
  14. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. # THE SOFTWARE.
  21. #
  22. # Detect markers in the build tree
  23. if [[ -f "$BUILD"/.fix-scm ]]; then FIX_SCM=1; fi
  24. # Define helpers
  25. post_cmake() {
  26. if [[ $ECLIPSE ]]; then
  27. # Check if xmlstarlet software package is available for fixing the generated Eclipse project setting
  28. if xmlstarlet --version >/dev/null 2>&1; then HAS_XMLSTARLET=1; fi
  29. if [[ $HAS_XMLSTARLET ]]; then
  30. # Common fixes for all builds
  31. #
  32. # Remove build configuration from project name
  33. # Replace deprecated GNU gmake Error Parser with newer version (6.0 -> 7.0) and add GCC Error Parser
  34. #
  35. xmlstarlet ed -P -L \
  36. -u "/projectDescription/name/text()" -x "concat(substring-before(., '-Release'), substring-before(., '-Debug'), substring-before(., '-RelWithDebInfo'))" \
  37. -u "/projectDescription/buildSpec/buildCommand/arguments/dictionary/value[../key/text() = 'org.eclipse.cdt.core.errorOutputParser']" -x "concat('org.eclipse.cdt.core.GmakeErrorParser;org.eclipse.cdt.core.GCCErrorParser;', substring-after(., 'org.eclipse.cdt.core.MakeErrorParser'))" \
  38. "$BUILD"/.project
  39. if [[ $FIX_SCM ]]; then
  40. # Copy the Eclipse project setting files to Source tree in order to fix it so that Eclipse's SCM feature works again
  41. echo -- post_cmake: Move Eclipse project setting files to $SOURCE and fix them to reenable Eclipse SCM feature
  42. # Leave the original copy in the build tree
  43. for f in .project .cproject; do cp "$BUILD"/$f "$SOURCE"; done
  44. # Set a marker in the build tree that Eclipse project has been fixed
  45. touch "$BUILD"/.fix-scm
  46. #
  47. # Replace [Source directory] linked resource to [Build] instead
  48. # Modify build argument to first change directory to Build folder
  49. # Remove [Subprojects]/Urho3D linked resource
  50. #
  51. xmlstarlet ed -P -L \
  52. -u "/projectDescription/linkedResources/link/name/text()[. = '[Source directory]']" -v "[Build]" \
  53. -u "/projectDescription/linkedResources/link/location[../name/text() = '[Build]']" -v "`cd $BUILD; pwd`" \
  54. -u "/projectDescription/buildSpec/buildCommand/arguments/dictionary/value[../key/text() = 'org.eclipse.cdt.make.core.build.arguments']" -x "concat('-C $BUILD ', .)" \
  55. -d "/projectDescription/linkedResources/link[./name = '[Subprojects]/Urho3D']" \
  56. "$SOURCE"/.project
  57. #
  58. # Fix source path entry to Source folder and modify its filter condition
  59. # Fix output path entry to [Build] linked resource and modify its filter condition
  60. #
  61. xmlstarlet ed -P -L \
  62. -u "/cproject/storageModule/cconfiguration/storageModule/pathentry[@kind = 'src']/@path" -v "" \
  63. -s "/cproject/storageModule/cconfiguration/storageModule/pathentry[@kind = 'src']" -t attr -n "excluding" -v "[Build]/|[Subprojects]/|[Targets]/|Docs/AngelScriptAPI.h" \
  64. -u "/cproject/storageModule/cconfiguration/storageModule/pathentry[@kind = 'out']/@path" -v "[Build]" \
  65. -u "/cproject/storageModule/cconfiguration/storageModule/pathentry[@kind = 'out']/@excluding" -x "substring-after(., '[Source directory]/|')" \
  66. "$SOURCE"/.cproject
  67. fi
  68. fi
  69. elif [ -e "$BUILD"/*.xcodeproj/project.pbxproj ] && perl -v >/dev/null 2>&1; then
  70. echo -- post_cmake: Fix generated Xcode project
  71. # Speed up build for Debug build configuration by building only active arch (currently this is not doable via CMake generator-expression as it only works for individual target instead of global)
  72. perl -i -pe 'BEGIN {$/=undef} s/(Debug \*\/ = {[^}]+?)SDKROOT/\1ONLY_ACTIVE_ARCH = YES; SDKROOT/s' "$BUILD"/*.xcodeproj/project.pbxproj
  73. # Speed up build for Debug build configuration by skipping dSYM file generation
  74. if [[ $IOS ]] || [[ $TVOS ]]; then
  75. perl -i -pe 'BEGIN {$/=undef} s/(Debug \*\/ = {[^}]+?)SDKROOT/\1DEBUG_INFORMATION_FORMAT = dwarf; SDKROOT/s' "$BUILD"/*.xcodeproj/project.pbxproj
  76. fi
  77. fi
  78. }
  79. # vi: set ts=4 sw=4 expandtab: