cmake_generic.bat 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. @echo off
  23. :: Determine source tree and build tree
  24. setlocal
  25. set "SOURCE=%~dp0"
  26. set "SOURCE=%SOURCE:~0,-1%\.."
  27. set "SOURCE=%cd%"
  28. set "BUILD="
  29. if "%~1" == "" goto :continue
  30. set "ARG1=%~1"
  31. if "%ARG1:~0,1%" equ "-" goto :continue
  32. set "BUILD=%~1"
  33. shift
  34. :continue
  35. if "%BUILD%" == "" if exist "%cd%\CMakeCache.txt" (set "BUILD=%cd%") else (echo Usage: %~nx0 \path\to\build-tree [build-options] && exit /B 1)
  36. :: Detect CMake toolchains directory if it is not provided explicitly
  37. if "%TOOLCHAINS%" == "" set "TOOLCHAINS=%SOURCE%\CMake\Toolchains"
  38. if not exist "%TOOLCHAINS%" if exist "%URHO3D_HOME%\share\CMake\Toolchains" set "TOOLCHAINS=%URHO3D_HOME%\share\CMake\Toolchains"
  39. :: Default to native generator and toolchain if none is specified explicitly
  40. set "OPTS="
  41. set "BUILD_OPTS="
  42. set "arch="
  43. :loop
  44. if not "%~1" == "" (
  45. if "%~1" == "-D" (
  46. if "%~2" == "WEB" if "%~3" == "1" set "OPTS=-G "MinGW Makefiles" -D CMAKE_TOOLCHAIN_FILE="%TOOLCHAINS%\Emscripten.cmake""
  47. if "%~2" == "MINGW" if "%~3" == "1" set "OPTS=-G "MinGW Makefiles""
  48. if "%~2" == "URHO3D_64BIT" if "%~3" == "1" set "arch=-A x64"
  49. if "%~2" == "URHO3D_64BIT" if "%~3" == "0" set "arch=-A Win32"
  50. set "BUILD_OPTS=%BUILD_OPTS% -D %~2=%~3"
  51. shift
  52. shift
  53. shift
  54. )
  55. if "%~1" == "-VS" (
  56. set "OPTS=-G "Visual Studio %~2" %arch% %TOOLSET%"
  57. shift
  58. shift
  59. )
  60. if "%~1" == "-G" (
  61. set "OPTS=%OPTS% -G %~2"
  62. shift
  63. shift
  64. )
  65. goto loop
  66. )
  67. if exist "%BUILD%\CMakeCache.txt" set "OPTS="
  68. :: Create project with the chosen CMake generator and toolchain
  69. cmake -E make_directory "%BUILD%" && cmake -E chdir "%BUILD%" cmake %OPTS% %BUILD_OPTS% "%SOURCE%"