.bash_helpers.sh 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #
  2. # Copyright (c) 2008-2017 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. # Build-specific fixes
  40. if [[ $ANDROID ]]; then
  41. # For Android build, add the Android and Java nature to the project setting as it would be done by Eclipse during project import
  42. # This fix avoids the step to reimport the project everytime the Eclipse project setting is regenerated by cmake_generic.sh invocation
  43. echo -- post_cmake: Add Android and Java nature to Eclipse project setting files in $BUILD
  44. #
  45. # Add natures (Android nature must be inserted as first nature)
  46. #
  47. xmlstarlet ed -P -L \
  48. -i "/projectDescription/natures/nature[1]" -t elem -n nature -v "com.android.ide.eclipse.adt.AndroidNature" \
  49. -s "/projectDescription/natures" -t elem -n nature -v "org.eclipse.jdt.core.javanature" \
  50. "$BUILD"/.project
  51. #
  52. # Add build commands
  53. #
  54. for c in com.android.ide.eclipse.adt.ResourceManagerBuilder com.android.ide.eclipse.adt.PreCompilerBuilder org.eclipse.jdt.core.javabuilder com.android.ide.eclipse.adt.ApkBuilder; do
  55. xmlstarlet ed -P -L \
  56. -s "/projectDescription/buildSpec" -t elem -n buildCommandNew -v "" \
  57. -s "/projectDescription/buildSpec/buildCommandNew" -t elem -n name -v $c \
  58. -s "/projectDescription/buildSpec/buildCommandNew" -t elem -n arguments -v "" \
  59. -r "/projectDescription/buildSpec/buildCommandNew" -v "buildCommand" \
  60. "$BUILD"/.project
  61. done
  62. fi
  63. if [[ $FIX_SCM ]]; then
  64. # Copy the Eclipse project setting files to Source tree in order to fix it so that Eclipse's SCM feature works again
  65. echo -- post_cmake: Move Eclipse project setting files to $SOURCE and fix them to reenable Eclipse SCM feature
  66. # Leave the original copy in the build tree
  67. for f in .project .cproject; do cp "$BUILD"/$f "$SOURCE"; done
  68. # Set a marker in the build tree that Eclipse project has been fixed
  69. touch "$BUILD"/.fix-scm
  70. #
  71. # Replace [Source directory] linked resource to [Build] instead
  72. # Modify build argument to first change directory to Build folder
  73. # Remove [Subprojects]/Urho3D linked resource
  74. #
  75. xmlstarlet ed -P -L \
  76. -u "/projectDescription/linkedResources/link/name/text()[. = '[Source directory]']" -v "[Build]" \
  77. -u "/projectDescription/linkedResources/link/location[../name/text() = '[Build]']" -v "`cd $BUILD; pwd`" \
  78. -u "/projectDescription/buildSpec/buildCommand/arguments/dictionary/value[../key/text() = 'org.eclipse.cdt.make.core.build.arguments']" -x "concat('-C $BUILD ', .)" \
  79. -d "/projectDescription/linkedResources/link[./name = '[Subprojects]/Urho3D']" \
  80. "$SOURCE"/.project
  81. #
  82. # Fix source path entry to Source folder and modify its filter condition
  83. # Fix output path entry to [Build] linked resource and modify its filter condition
  84. #
  85. xmlstarlet ed -P -L \
  86. -u "/cproject/storageModule/cconfiguration/storageModule/pathentry[@kind = 'src']/@path" -v "" \
  87. -s "/cproject/storageModule/cconfiguration/storageModule/pathentry[@kind = 'src']" -t attr -n "excluding" -v "[Build]/|[Subprojects]/|[Targets]/|Docs/AngelScriptAPI.h" \
  88. -u "/cproject/storageModule/cconfiguration/storageModule/pathentry[@kind = 'out']/@path" -v "[Build]" \
  89. -u "/cproject/storageModule/cconfiguration/storageModule/pathentry[@kind = 'out']/@excluding" -x "substring-after(., '[Source directory]/|')" \
  90. "$SOURCE"/.cproject
  91. fi
  92. fi
  93. elif [ -e "$BUILD"/*.xcodeproj/project.pbxproj ] && perl -v >/dev/null 2>&1; then
  94. echo -- post_cmake: Fix generated Xcode project
  95. # Temporary workaround to fix file references being added into multiple groups warnings (CMake bug https://www.cmake.org/Bug/view.php?id=15272, stil exists in 3.1)
  96. perl -i -pe 'BEGIN {$/=undef} s/(Begin PBXGroup section.*?\/\* Sources \*\/,).*?,/\1/s' "$BUILD"/*.xcodeproj/project.pbxproj
  97. # 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)
  98. perl -i -pe 'BEGIN {$/=undef} s/(Debug \*\/ = {[^}]+?)SDKROOT/\1ONLY_ACTIVE_ARCH = YES; SDKROOT/s' "$BUILD"/*.xcodeproj/project.pbxproj
  99. # Speed up build for Debug build configuration by skipping dSYM file generation
  100. if [[ $IOS ]]; then
  101. perl -i -pe 'BEGIN {$/=undef} s/(Debug \*\/ = {[^}]+?)SDKROOT/\1DEBUG_INFORMATION_FORMAT = dwarf; SDKROOT/s' "$BUILD"/*.xcodeproj/project.pbxproj
  102. fi
  103. fi
  104. }
  105. # vi: set ts=4 sw=4 expandtab: