cmake_generic.bat 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. @echo off
  23. :: Determine source tree and build tree
  24. set "SOURCE=%~dp0"
  25. set "SOURCE=%SOURCE:~0,-1%"
  26. set "BUILD="
  27. if "%~1" == "" goto :continue
  28. set "ARG1=%~1"
  29. if "%ARG1:~0,1%" equ "-" goto :continue
  30. set "BUILD=%~1"
  31. shift
  32. :continue
  33. if "%BUILD%" == "" if exist "%cd%\CMakeCache.txt" (set "BUILD=%cd%") else (echo Usage: %~nx0 \path\to\build-tree [build-options] && exit /B 1)
  34. :: Detect CMake toolchains directory if it is not provided explicitly
  35. if "%TOOLCHAINS%" == "" set "TOOLCHAINS=%SOURCE%\CMake\Toolchains"
  36. if not exist "%TOOLCHAINS%" if exist "%URHO3D_HOME%\share\CMake\Toolchains" set "TOOLCHAINS=%URHO3D_HOME%\share\CMake\Toolchains"
  37. :: BEWARE that the TOOLCHAINS variable leaks to caller's environment!
  38. :: Default to native generator and toolchain if none is specified explicitly
  39. set "OPTS="
  40. set "BUILD_OPTS="
  41. set "arch="
  42. :loop
  43. if not "%~1" == "" (
  44. if "%~1" == "-DANDROID" if "%~2" == "1" set "OPTS=-G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE="%TOOLCHAINS%\Android.cmake""
  45. if "%~1" == "-DWEB" if "%~2" == "1" set "OPTS=-G "MinGW Makefiles" -DCMAKE_TOOLCHAIN_FILE="%TOOLCHAINS%\Emscripten.cmake""
  46. if "%~1" == "-DMINGW" if "%~2" == "1" set "OPTS=-G "MinGW Makefiles""
  47. if "%~1" == "-DURHO3D_64BIT" if "%~2" == "1" set "arch= Win64"
  48. if "%~1" == "-DURHO3D_64BIT" if "%~2" == "0" set "arch="
  49. if "%~1" == "-VS" set "OPTS=-G "Visual Studio %~2%arch%""
  50. if "%~1" == "-G" set "OPTS=%OPTS% %~1 %2"
  51. set "ARG1=%~1"
  52. set "ARG2=%~2"
  53. if "%ARG1:~0,2%" == "-D" set "BUILD_OPTS=%BUILD_OPTS% %ARG1%=%ARG2%"
  54. shift
  55. shift
  56. goto loop
  57. )
  58. if exist "%BUILD%\CMakeCache.txt" set "OPTS="
  59. :: Create project with the chosen CMake generator and toolchain
  60. cmake -E make_directory "%BUILD%" && cmake -E chdir "%BUILD%" cmake %OPTS% %BUILD_OPTS% "%SOURCE%"