Browse Source

Handle CMake cache entry in '-D <var>=<value>' format.

Yao Wei Tjong 姚伟忠 5 years ago
parent
commit
7937119e63

+ 1 - 49
script/.bash_helpers.sh

@@ -20,57 +20,9 @@
 # THE SOFTWARE.
 #
 
-# Detect markers in the build tree
-if [[ -f "$BUILD"/.fix-scm ]]; then FIX_SCM=1; fi
-
 # Define helpers
 post_cmake() {
-    if [[ $ECLIPSE ]]; then
-        # Check if xmlstarlet software package is available for fixing the generated Eclipse project setting
-        if xmlstarlet --version >/dev/null 2>&1; then HAS_XMLSTARLET=1; fi
-        if [[ $HAS_XMLSTARLET ]]; then
-            # Common fixes for all builds
-            #
-            # Remove build configuration from project name
-            # Replace deprecated GNU gmake Error Parser with newer version (6.0 -> 7.0) and add GCC Error Parser
-            #
-            xmlstarlet ed -P -L \
-                -u "/projectDescription/name/text()" -x "concat(substring-before(., '-Release'), substring-before(., '-Debug'), substring-before(., '-RelWithDebInfo'))" \
-                -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'))" \
-                "$BUILD"/.project
-
-            if [[ $FIX_SCM ]]; then
-                # Copy the Eclipse project setting files to Source tree in order to fix it so that Eclipse's SCM feature works again
-                echo -- post_cmake: Move Eclipse project setting files to $SOURCE and fix them to reenable Eclipse SCM feature
-                # Leave the original copy in the build tree
-                for f in .project .cproject; do cp "$BUILD"/$f "$SOURCE"; done
-                # Set a marker in the build tree that Eclipse project has been fixed
-                touch "$BUILD"/.fix-scm
-
-                #
-                # Replace [Source directory] linked resource to [Build] instead
-                # Modify build argument to first change directory to Build folder
-                # Remove [Subprojects]/Urho3D linked resource
-                #
-                xmlstarlet ed -P -L \
-                    -u "/projectDescription/linkedResources/link/name/text()[. = '[Source directory]']" -v "[Build]" \
-                    -u "/projectDescription/linkedResources/link/location[../name/text() = '[Build]']" -v "`cd $BUILD; pwd`" \
-                    -u "/projectDescription/buildSpec/buildCommand/arguments/dictionary/value[../key/text() = 'org.eclipse.cdt.make.core.build.arguments']" -x "concat('-C $BUILD ', .)" \
-                    -d "/projectDescription/linkedResources/link[./name = '[Subprojects]/Urho3D']" \
-                    "$SOURCE"/.project
-                #
-                # Fix source path entry to Source folder and modify its filter condition
-                # Fix output path entry to [Build] linked resource and modify its filter condition
-                #
-                xmlstarlet ed -P -L \
-                    -u "/cproject/storageModule/cconfiguration/storageModule/pathentry[@kind = 'src']/@path" -v "" \
-                    -s "/cproject/storageModule/cconfiguration/storageModule/pathentry[@kind = 'src']" -t attr -n "excluding" -v "[Build]/|[Subprojects]/|[Targets]/|Docs/AngelScriptAPI.h" \
-                    -u "/cproject/storageModule/cconfiguration/storageModule/pathentry[@kind = 'out']/@path" -v "[Build]" \
-                    -u "/cproject/storageModule/cconfiguration/storageModule/pathentry[@kind = 'out']/@excluding" -x "substring-after(., '[Source directory]/|')" \
-                    "$SOURCE"/.cproject
-            fi
-        fi
-    elif [ -e "$BUILD"/*.xcodeproj/project.pbxproj ] && perl -v >/dev/null 2>&1; then
+    if [ -e "$BUILD"/*.xcodeproj/project.pbxproj ] && perl -v >/dev/null 2>&1; then
         echo -- post_cmake: Fix generated Xcode project
         # 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)
         perl -i -pe 'BEGIN {$/=undef} s/(Debug \*\/ = {[^}]+?)SDKROOT/\1ONLY_ACTIVE_ARCH = YES; SDKROOT/s' "$BUILD"/*.xcodeproj/project.pbxproj

+ 1 - 1
script/cmake_arm.sh

@@ -21,6 +21,6 @@
 # THE SOFTWARE.
 #
 
-$(dirname $0)/cmake_generic.sh "$@" -DARM=1
+$(dirname $0)/cmake_generic.sh "$@" -D ARM=1
 
 # vi: set ts=4 sw=4 expandtab:

+ 0 - 29
script/cmake_eclipse.sh

@@ -1,29 +0,0 @@
-#!/usr/bin/env bash
-#
-# Copyright (c) 2008-2020 the Urho3D project.
-#
-# Permission is hereby granted, free of charge, to any person obtaining a copy
-# of this software and associated documentation files (the "Software"), to deal
-# in the Software without restriction, including without limitation the rights
-# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-# copies of the Software, and to permit persons to whom the Software is
-# furnished to do so, subject to the following conditions:
-#
-# The above copyright notice and this permission notice shall be included in
-# all copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-# THE SOFTWARE.
-#
-
-$(dirname $0)/cmake_generic.sh "$@" -G "Eclipse CDT4 - Unix Makefiles"
-
-# After importing the generated project into Eclipse workspace, set the [Build], [Subprojects], and [Targets] linked resources property as 'Derived'
-# to exclude the derived resources in those folders from being listed in the Open Resource and Search Result list
-
-# vi: set ts=4 sw=4 expandtab:

+ 1 - 1
script/cmake_emscripten.bat

@@ -20,4 +20,4 @@
 :: THE SOFTWARE.
 ::
 
-@"%~dp0cmake_generic.bat" %* -DWEB=1
+@"%~dp0cmake_generic.bat" %* -D WEB=1

+ 1 - 1
script/cmake_emscripten.sh

@@ -21,6 +21,6 @@
 # THE SOFTWARE.
 #
 
-$(dirname $0)/cmake_generic.sh "$@" -DWEB=1
+$(dirname $0)/cmake_generic.sh "$@" -D WEB=1
 
 # vi: set ts=4 sw=4 expandtab:

+ 20 - 12
script/cmake_generic.bat

@@ -46,18 +46,26 @@ set "BUILD_OPTS="
 set "arch="
 :loop
 if not "%~1" == "" (
-    if "%~1" == "-DANDROID" if "%~2" == "1" (echo For Android platform, use Gradle build system instead of invoking CMake build tool directly! && exit /B 1)
-    if "%~1" == "-DWEB" if "%~2" == "1" set "OPTS=-G "MinGW Makefiles" -DCMAKE_TOOLCHAIN_FILE="%TOOLCHAINS%\Emscripten.cmake""
-    if "%~1" == "-DMINGW" if "%~2" == "1" set "OPTS=-G "MinGW Makefiles""
-    if "%~1" == "-DURHO3D_64BIT" if "%~2" == "1" set "arch=-A x64"
-    if "%~1" == "-DURHO3D_64BIT" if "%~2" == "0" set "arch=-A Win32"
-    if "%~1" == "-VS" set "OPTS=-G "Visual Studio %~2" %arch% %TOOLSET%"
-    if "%~1" == "-G" set "OPTS=%OPTS% %~1 %2"
-    set "ARG1=%~1"
-    set "ARG2=%~2"
-    if "%ARG1:~0,2%" == "-D" set "BUILD_OPTS=%BUILD_OPTS% %ARG1%=%ARG2%"
-    shift
-    shift
+    if "%~1" == "-D" (
+        if "%~2" == "WEB" if "%~3" == "1" set "OPTS=-G "MinGW Makefiles" -D CMAKE_TOOLCHAIN_FILE="%TOOLCHAINS%\Emscripten.cmake""
+        if "%~2" == "MINGW" if "%~3" == "1" set "OPTS=-G "MinGW Makefiles""
+        if "%~2" == "URHO3D_64BIT" if "%~3" == "1" set "arch=-A x64"
+        if "%~2" == "URHO3D_64BIT" if "%~3" == "0" set "arch=-A Win32"
+        set "BUILD_OPTS=%BUILD_OPTS% -D %~2=%~3"
+        shift
+        shift
+        shift
+    )
+    if "%~1" == "-VS" (
+        set "OPTS=-G "Visual Studio %~2" %arch% %TOOLSET%"
+        shift
+        shift
+    )
+    if "%~1" == "-G" (
+        set "OPTS=%OPTS% -G %~2"
+        shift
+        shift
+    )
     goto loop
 )
 if exist "%BUILD%\CMakeCache.txt" set "OPTS="

+ 10 - 26
script/cmake_generic.sh

@@ -37,39 +37,23 @@ if [[ "$BUILD" == "." ]]; then BUILD=$(pwd); fi
 IFS=#
 OPTS=
 for a in $@; do
-    case $a in
-        --fix-scm)
-            FIX_SCM=1
+    case ${a#-D} in
+        RPI=1)
+            if [[ ! $(uname -m) =~ ^(arm|aarch64) ]]; then OPTS=(-D CMAKE_TOOLCHAIN_FILE=$TOOLCHAINS/RaspberryPi.cmake); fi
             ;;
-        Eclipse\ CDT4\ -\ Unix\ Makefiles)
-            ECLIPSE=1
+        ARM=1)
+            if [[ ! $(uname -m) =~ ^(arm|aarch64) ]]; then OPTS=(-D CMAKE_TOOLCHAIN_FILE=$TOOLCHAINS/Arm.cmake); fi
             ;;
-        -DIOS=1)
-            IOS=1
+        MINGW=1)
+            OPTS=(-D CMAKE_TOOLCHAIN_FILE=$TOOLCHAINS/MinGW.cmake)
             ;;
-        -DTVOS=1)
-            TVOS=1
-            ;;
-        -DANDROID=1)
-            echo For Android platform, use Gradle build system instead of invoking CMake build system directly!
-            exit 1
-            ;;
-        -DRPI=1)
-            if [[ ! $(uname -m) =~ ^arm ]]; then OPTS="-DCMAKE_TOOLCHAIN_FILE=$TOOLCHAINS/RaspberryPi.cmake"; fi
-            ;;
-        -DARM=1)
-            if [[ ! $(uname -m) =~ ^(arm|aarch64) ]]; then OPTS="-DCMAKE_TOOLCHAIN_FILE=$TOOLCHAINS/Arm.cmake"; fi
-            ;;
-        -DMINGW=1)
-            OPTS="-DCMAKE_TOOLCHAIN_FILE=$TOOLCHAINS/MinGW.cmake"
-            ;;
-        -DWEB=1)
-            OPTS="-DCMAKE_TOOLCHAIN_FILE=$TOOLCHAINS/Emscripten.cmake"
+        WEB=1)
+            OPTS=(-D CMAKE_TOOLCHAIN_FILE=$TOOLCHAINS/Emscripten.cmake)
             ;;
     esac
 done
 
 # Create project with the chosen CMake generator and toolchain
-cmake -E make_directory "$BUILD" && cmake -E chdir "$BUILD" cmake $OPTS $@ "$SOURCE" && post_cmake
+cmake -E make_directory "$BUILD" && cmake -E chdir "$BUILD" cmake ${OPTS[*]} $@ "$SOURCE" && post_cmake
 
 # vi: set ts=4 sw=4 expandtab:

+ 1 - 1
script/cmake_ios.sh

@@ -21,6 +21,6 @@
 # THE SOFTWARE.
 #
 
-$(dirname $0)/cmake_generic.sh "$@" -G Xcode -DIOS=1
+$(dirname $0)/cmake_generic.sh "$@" -G Xcode -D IOS=1
 
 # vi: set ts=4 sw=4 expandtab:

+ 1 - 1
script/cmake_mingw.bat

@@ -20,4 +20,4 @@
 :: THE SOFTWARE.
 ::
 
-@"%~dp0cmake_generic.bat" %* -DMINGW=1
+@"%~dp0cmake_generic.bat" %* -D MINGW=1

+ 1 - 1
script/cmake_mingw.sh

@@ -21,6 +21,6 @@
 # THE SOFTWARE.
 #
 
-$(dirname $0)/cmake_generic.sh "$@" -DMINGW=1
+$(dirname $0)/cmake_generic.sh "$@" -D MINGW=1
 
 # vi: set ts=4 sw=4 expandtab:

+ 1 - 1
script/cmake_rpi.sh

@@ -21,6 +21,6 @@
 # THE SOFTWARE.
 #
 
-$(dirname $0)/cmake_generic.sh "$@" -DRPI=1
+$(dirname $0)/cmake_generic.sh "$@" -D RPI=1
 
 # vi: set ts=4 sw=4 expandtab:

+ 1 - 1
script/cmake_tvos.sh

@@ -21,6 +21,6 @@
 # THE SOFTWARE.
 #
 
-$(dirname $0)/cmake_generic.sh "$@" -G Xcode -DTVOS=1
+$(dirname $0)/cmake_generic.sh "$@" -G Xcode -D TVOS=1
 
 # vi: set ts=4 sw=4 expandtab: