cmake_generic.bat 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. :: Copyright (c) 2008-2023 the Urho3D project
  2. :: License: MIT
  3. @echo off
  4. :: Determine source tree and build tree
  5. setlocal
  6. set "SOURCE=%~dp0"
  7. set "SOURCE=%SOURCE:~0,-1%\.."
  8. set "SOURCE=%cd%"
  9. set "BUILD="
  10. if "%~1" == "" goto :continue
  11. set "ARG1=%~1"
  12. if "%ARG1:~0,1%" equ "-" goto :continue
  13. set "BUILD=%~1"
  14. shift
  15. :continue
  16. if "%BUILD%" == "" if exist "%cd%\CMakeCache.txt" (set "BUILD=%cd%") else (echo Usage: %~nx0 \path\to\build-tree [build-options] && exit /B 1)
  17. :: Detect CMake toolchains directory if it is not provided explicitly
  18. if "%TOOLCHAINS%" == "" set "TOOLCHAINS=%SOURCE%\CMake\Toolchains"
  19. if not exist "%TOOLCHAINS%" if exist "%URHO3D_HOME%\share\CMake\Toolchains" set "TOOLCHAINS=%URHO3D_HOME%\share\CMake\Toolchains"
  20. :: Default to native generator and toolchain if none is specified explicitly
  21. set "OPTS="
  22. set "BUILD_OPTS="
  23. set "arch="
  24. :loop
  25. if not "%~1" == "" (
  26. if "%~1" == "-D" (
  27. if "%~2" == "WEB" if "%~3" == "1" (
  28. set "TOOLCHAINS=%EMSCRIPTEN_ROOT_PATH%\tools\cmake\Modules\Platform"
  29. set "OPTS=-G "MinGW Makefiles" -D CMAKE_TOOLCHAIN_FILE="%TOOLCHAINS%\Emscripten.cmake""
  30. )
  31. if "%~2" == "MINGW" if "%~3" == "1" set "OPTS=-G "MinGW Makefiles""
  32. if "%~2" == "URHO3D_64BIT" if "%~3" == "1" set "arch=-A x64"
  33. if "%~2" == "URHO3D_64BIT" if "%~3" == "0" set "arch=-A Win32"
  34. set "BUILD_OPTS=%BUILD_OPTS% -D %~2=%~3"
  35. shift
  36. shift
  37. shift
  38. )
  39. if "%~1" == "-VS" (
  40. set "OPTS=-G "Visual Studio %~2" %arch% %TOOLSET%"
  41. shift
  42. shift
  43. )
  44. if "%~1" == "-G" (
  45. set "OPTS=%OPTS% -G %~2"
  46. shift
  47. shift
  48. )
  49. goto loop
  50. )
  51. if exist "%BUILD%\CMakeCache.txt" set "OPTS="
  52. :: Create project with the chosen CMake generator and toolchain
  53. cmake -E make_directory "%BUILD%" && cmake -E chdir "%BUILD%" cmake %OPTS% %BUILD_OPTS% "%SOURCE%"