xref: /aosp_15_r20/external/lz4/build/visual/generate_solution.cmd (revision 27162e4e17433d5aa7cb38e7b6a433a09405fc7f)
1:: Requires 1 parameter == GENERATOR
2@echo off
3setlocal
4
5:: Set path
6set "BUILD_BASE_DIR=%~dp0"  :: Use the directory where the script is located
7set "CMAKELIST_DIR=..\..\cmake"
8
9if "%~1"=="" (
10    echo No generator specified as first parameter
11    exit /b 1
12)
13set "GENERATOR=%~1"
14
15:: Check if a user-defined CMAKE_PATH is set and prioritize it
16if defined CMAKE_PATH (
17    set "CMAKE_EXECUTABLE=%CMAKE_PATH%\cmake.exe"
18    echo Using user-defined cmake at %CMAKE_PATH%
19) else (
20    :: Attempt to find cmake in the system PATH
21    where cmake >nul 2>&1
22    if %ERRORLEVEL% neq 0 (
23        :: Use the default standard cmake installation directory if not found in PATH
24        set "CMAKE_PATH=C:\Program Files\CMake\bin"
25        echo CMake not in system PATH => using default CMAKE_PATH=%CMAKE_PATH%
26        set "CMAKE_EXECUTABLE=%CMAKE_PATH%\cmake.exe"
27    ) else (
28        set "CMAKE_EXECUTABLE=cmake"
29        echo CMake found in system PATH.
30    )
31)
32
33:: Set the build directory to a subdirectory named after the generator
34set "BUILD_DIR=%BUILD_BASE_DIR%\%GENERATOR%"
35
36:: Create the build directory if it doesn't exist
37if not exist "%BUILD_DIR%" mkdir "%BUILD_DIR%"
38
39:: Run CMake to configure the project and generate the solution
40pushd "%BUILD_DIR%"
41"%CMAKE_EXECUTABLE%" -G "%GENERATOR%" "%CMAKELIST_DIR%"
42if %ERRORLEVEL% neq 0 goto :error
43
44:: If successful, end script
45echo Build configuration successful for %GENERATOR%.
46goto :end
47
48:error
49echo Failed to configure build for %GENERATOR%.
50exit /b 1
51
52:end
53popd
54endlocal
55@echo on
56