feat(build): add windows batch build helper
This commit is contained in:
@@ -72,12 +72,18 @@ target_link_libraries(your_target PRIVATE ikv::ikv)
|
||||
|
||||
### Script build
|
||||
|
||||
For the repo-local non-CMake build path used in CI:
|
||||
For the repo-local non-CMake build path:
|
||||
|
||||
```sh
|
||||
./demo/build.sh
|
||||
```
|
||||
|
||||
On Windows:
|
||||
|
||||
```bat
|
||||
demo\build.bat
|
||||
```
|
||||
|
||||
## Project layout
|
||||
|
||||
- `include/ikv.h`: public API
|
||||
@@ -122,4 +128,3 @@ To add a new format version:
|
||||
2. Implement the loader
|
||||
3. Register it in `src/ikv.c`
|
||||
4. Add a public version constant to `include/ikv.h` if needed
|
||||
|
||||
|
||||
77
demo/build.bat
Normal file
77
demo/build.bat
Normal file
@@ -0,0 +1,77 @@
|
||||
@echo off
|
||||
setlocal EnableExtensions
|
||||
|
||||
set "SCRIPT_DIR=%~dp0"
|
||||
for %%I in ("%SCRIPT_DIR%..") do set "ROOT_DIR=%%~fI"
|
||||
set "OUT_DIR=%SCRIPT_DIR%build"
|
||||
set "DEMO_EXE=%OUT_DIR%\ikv_demo.exe"
|
||||
set "TEST_EXE=%OUT_DIR%\ikv_tests.exe"
|
||||
|
||||
if not exist "%OUT_DIR%" mkdir "%OUT_DIR%"
|
||||
|
||||
set "CC="
|
||||
where gcc >nul 2>nul && set "CC=gcc"
|
||||
if not defined CC where clang >nul 2>nul && set "CC=clang"
|
||||
|
||||
if defined CC goto :build_with_cc
|
||||
|
||||
where cl >nul 2>nul
|
||||
if errorlevel 1 goto :no_compiler
|
||||
goto :build_with_cl
|
||||
|
||||
:build_with_cc
|
||||
"%CC%" -std=c11 -Wall -Wextra -pedantic ^
|
||||
-I"%ROOT_DIR%\include" ^
|
||||
"%SCRIPT_DIR%main.c" ^
|
||||
"%ROOT_DIR%\src\ikv.c" ^
|
||||
"%ROOT_DIR%\src\loaders\ikv1.c" ^
|
||||
"%ROOT_DIR%\src\loaders\ikv2.c" ^
|
||||
-o "%DEMO_EXE%"
|
||||
if errorlevel 1 exit /b 1
|
||||
|
||||
"%CC%" -std=c11 -Wall -Wextra -pedantic ^
|
||||
-DIKV_TESTING ^
|
||||
-I"%ROOT_DIR%\include" ^
|
||||
"%SCRIPT_DIR%unit_test.c" ^
|
||||
"%ROOT_DIR%\src\ikv.c" ^
|
||||
"%ROOT_DIR%\src\loaders\ikv1.c" ^
|
||||
"%ROOT_DIR%\src\loaders\ikv2.c" ^
|
||||
-o "%TEST_EXE%"
|
||||
if errorlevel 1 exit /b 1
|
||||
goto :after_build
|
||||
|
||||
:build_with_cl
|
||||
cl /nologo /std:c11 /W4 /I "%ROOT_DIR%\include" ^
|
||||
"%SCRIPT_DIR%main.c" ^
|
||||
"%ROOT_DIR%\src\ikv.c" ^
|
||||
"%ROOT_DIR%\src\loaders\ikv1.c" ^
|
||||
"%ROOT_DIR%\src\loaders\ikv2.c" ^
|
||||
/Fe:"%DEMO_EXE%"
|
||||
if errorlevel 1 exit /b 1
|
||||
del /q "%SCRIPT_DIR%*.obj" 2>nul
|
||||
|
||||
cl /nologo /std:c11 /W4 /DIKV_TESTING /I "%ROOT_DIR%\include" ^
|
||||
"%SCRIPT_DIR%unit_test.c" ^
|
||||
"%ROOT_DIR%\src\ikv.c" ^
|
||||
"%ROOT_DIR%\src\loaders\ikv1.c" ^
|
||||
"%ROOT_DIR%\src\loaders\ikv2.c" ^
|
||||
/Fe:"%TEST_EXE%"
|
||||
if errorlevel 1 exit /b 1
|
||||
del /q "%SCRIPT_DIR%*.obj" 2>nul
|
||||
del /q "%SCRIPT_DIR%*.ilk" 2>nul
|
||||
del /q "%SCRIPT_DIR%*.pdb" 2>nul
|
||||
|
||||
:after_build
|
||||
echo built "%DEMO_EXE%"
|
||||
echo built "%TEST_EXE%"
|
||||
|
||||
if /I "%~1"=="test" (
|
||||
"%TEST_EXE%"
|
||||
exit /b %errorlevel%
|
||||
)
|
||||
|
||||
exit /b 0
|
||||
|
||||
:no_compiler
|
||||
echo No supported C compiler found. Install gcc, clang, or run from a Visual Studio developer prompt.>&2
|
||||
exit /b 1
|
||||
Reference in New Issue
Block a user