-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcr.bat
More file actions
81 lines (61 loc) · 2.07 KB
/
cr.bat
File metadata and controls
81 lines (61 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
@echo off
setlocal enableextensions enabledelayedexpansion
@REM v1: w/ cmake==
@REM ===========================
@REM cd build
@REM cmake --build .
@REM rem ...
@REM Debug\hello.exe
@REM v2: w/o cmake
@REM ===========================
@REM e.g. cl main.cpp /std:c++20 /Fobuild\ /Febuild\main.exe
@REM cl main.cpp /std:c++%1 /Fobuild\ /Febuild\main.exe
@REM for cl : c++latest (for c++23)
@REM for clang++: c++23
set CPP_VERSION=c++23
echo .
echo -------------------------
echo Compilation
echo -------------------------
echo -- Using %CPP_VERSION%
@REM Print clang version and date
for /f "tokens=3" %%v in ('clang++ --version ^| find "clang version"') do (
echo -- clang++ version: %%v
curl -s "https://api.github.com/repos/llvm/llvm-project/releases/tags/llvmorg-%%v" | find "published_at"
)
@REM cl main.cpp /std:%CPP_VERSION% /Fobuild\ /Febuild\main.exe
set CMD=clang++ -std=%CPP_VERSION% -fexceptions -Wall -Wextra -Wpedantic -fcolor-diagnostics main.cpp -o build/main.exe
echo -- cmd:
echo %CMD%
%CMD%
echo .
if %ERRORLEVEL% neq 0 (
echo . & echo -- Compilation failed! Exiting...
exit /b %ERRORLEVEL%
)
echo -- Compilation succeeded
build\main.exe
@REM v3: compiles if the source file is newer than the executable
@REM ===========================
@REM This script:
@REM First checks if main.exe exists at all - if not, we need to compile
@REM If it exists, compares the timestamp of main.cpp with main.exe
@REM Only compiles if the source file is newer than the executable
@REM if not exist main.exe goto compile
@REM set SRC_FILE=main.cpp
@REM set EXE_FILE=main.exe
@REM REM Get timestamps and sizes for both files
@REM for %%i in (%SRC_FILE%) do set SRC_TIME=%%~ti & set SRC_SIZE=%%~zi
@REM for %%i in (%EXE_FILE%) do set EXE_TIME=%%~ti & set EXE_SIZE=%%~zi
@REM REM Compare both timestamp and size
@REM if "%SRC_TIME%" gtr "%EXE_TIME%" goto compile
@REM goto run
@REM :compile
@REM echo Compiling %SRC_FILE%...
@REM cl main.cpp
@REM if %ERRORLEVEL% neq 0 (
@REM echo --- Compilation failed! Exiting...
@REM exit /b %ERRORLEVEL%
@REM )
@REM :run
@REM main.exe