1@echo off
2set PACKAGE_DIR="%CD%"
3
4REM clean if requested
5if "%1" == "clean" (
6      call clean-build.bat
7      if exist CMakeCache.txt del CMakeCache.txt
8)
9
10REM check for required programs on PATH
11for %%F in (ant cmake) do (
12      where /q %%F
13      if ERRORLEVEL 1 (
14            echo '%%F' not found on PATH; exiting
15            exit /b 1
16      )
17)
18
19setlocal
20
21REM Remove system Rtools from PATH
22call set PATH=%PATH:C:\Rtools\bin=%
23call set PATH=%PATH:C:\Rtools\gcc-4.6.3\bin=%
24
25REM Remove Git from PATH (otherwise cmake complains about 'sh.exe')
26call set PATH=%PATH:C:\Program Files (x86)\Git\bin=%
27call set PATH=%PATH:C:\Program Files\Git\bin=%
28
29REM Establish build dir
30set BUILD_DIR=build
31if "%CMAKE_BUILD_TYPE%" == "" set CMAKE_BUILD_TYPE=RelWithDebInfo
32if "%CMAKE_BUILD_TYPE%" == "Debug" set BUILD_DIR=build-debug
33
34REM perform 64-bit build
35cd "%PACKAGE_DIR%"
36if not exist "%BUILD_DIR%" mkdir "%BUILD_DIR%"
37cd "%BUILD_DIR%"
38
39REM Package these files into a shorter path to workaround windows max path of 260
40set PKG_TEMP_DIR=c:\temp\ide-build
41if exist "%PKG_TEMP_DIR%/_CPack_Packages" rmdir /s /q "%PKG_TEMP_DIR%\_CPack_Packages"
42
43REM Configure and build the project. (Note that Windows / MSVC builds require
44REM that we specify the build type both at configure time and at build time)
45set VS_TOOLS="%ProgramFiles(x86)%\Microsoft Visual Studio\2017\BuildTools\Common7\Tools"
46if not exist %VS_TOOLS% set VS_TOOLS="%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Community\Common7\Tools"
47if not exist %VS_TOOLS% echo "Could not find VsDevCmd.bat. Please ensure Microsoft Visual Studio 2017 Build tools are installed." && exit /b 1
48
49pushd %VS_TOOLS%
50call VsDevCmd.bat -clean_env -no_logo || goto :error
51call VsDevCmd.bat -arch=amd64 -startdir=none -host_arch=amd64 -winsdk=10.0.17134.0 -no_logo || goto :error
52popd
53
54cmake -G "Ninja" ^
55      -DRSTUDIO_TARGET=Desktop ^
56      -DCMAKE_BUILD_TYPE=%CMAKE_BUILD_TYPE% ^
57      -DRSTUDIO_PACKAGE_BUILD=1 ^
58      -DCMAKE_C_COMPILER=cl ^
59      -DCMAKE_CXX_COMPILER=cl ^
60      ..\..\.. || goto :error
61cmake --build . --config %CMAKE_BUILD_TYPE% -- %MAKEFLAGS% || goto :error
62
63cd ..
64
65REM perform 32-bit build and install it into the 64-bit tree
66call make-install-win32.bat "%PACKAGE_DIR%\%BUILD_DIR%\src\cpp\session" %1 || goto :error
67
68REM create packages
69cd "%BUILD_DIR%"
70if not "%1" == "quick" cpack -C "%CMAKE_BUILD_TYPE%" -G NSIS
71if "%CMAKE_BUILD_TYPE%" == "RelWithDebInfo" cpack -C "%CMAKE_BUILD_TYPE%" -G ZIP
72cd ..
73
74echo "Before moving files in %PKG_TEMP_DIR%:"
75dir "%PKG_TEMP_DIR%"
76move "%PKG_TEMP_DIR%\*.exe" "%PACKAGE_DIR%\%BUILD_DIR%"
77move "%PKG_TEMP_DIR%\*.zip" "%PACKAGE_DIR%\%BUILD_DIR%"
78echo "After moving files to %PACKAGE_DIR%\%BUILD_DIR%:"
79dir "%PACKAGE_DIR%\%BUILD_DIR%"
80
81REM emit NSIS error output if present
82if exist "%PKG_TEMP_DIR%\_CPack_Packages\win64\NSIS\NSISOutput.log" type "%PKG_TEMP_DIR%\_CPack_Packages\win64\NSIS\NSISOutput.log"
83
84REM reset modified environment variables (PATH)
85endlocal
86goto :EOF
87
88:error
89echo Failed to build RStudio! Error: %ERRORLEVEL%
90exit /b %ERRORLEVEL%
91