Here’s part of the powershell version of a build script I have used, where I had fewer build variants, so I didn’t even bother to make a `build` function, I just copy paste the `out=... ; if { ... }` block and change the value of `$out` and which compiler and options are called. Note that you can accomplish this with far fewer variables if you don’t want quite as many build variants as this script supports — it was written as an illustration of how flexible you can make things, rather than how simple things can be, so it supports clang, clang-cl, cl, zig cc, with variants for asan, freestanding, for architectures x86, x64, aarch64:
$ml = @("-nologo","-c","-Zd","-WX","-W3")
...
$clstd = @("-volatile:iso","-permissive-")
$clangcl = @("-nologo","-diagnostics:column","-Z7","-Zo","-FC") + $clstd
$cl = $clangcl + @("-WL","-Gm-","-utf-8")
# -Wall > -W4 but includes very silly things like "function not inlined" for snprintf
$clwx = @("-WX","-W4","-wd4100","-wd4127")
...
$clfree = @("-D","EXAMPLE_FREESTANDING","-Zl","-GS-","-sdl-","-Gs9999999")
$clfreedebug = $clwx + $clodebug + $cldd + $clfree + $clnortti + $clhash + $cllink + $link + $linkfree
...
$out = "./x86_64-windows-free-cl-debug"
if ("all" -in $targets -or (split-path -path $out -leaf) -in $targets) {
new-item -itemtype directory -force $out | out-null
try {
push-location $out
$buildcount++
write-host (split-path -path $out -leaf)
ml64 @ml $src/example-x64.asm
cl "-Fm./example.map" "-Tc$src/example.c" ./example-x64.obj @cl @clfreedebug
} finally { pop-location ; }
}
If you have an issue, you can easily change compiler options. It will always work and won’t suddenly break if you install a second set of compilers for another project, whereas CMake will have to choose which one and might pick wrong. Likewise, there is no potential for an upgrade to CMake to decide to use different compiler options that interfere with the freestanding stuff. You lose CMake’s abstractions, but like I said, that may be a good thing, depending on what your requirements are, assuming you have detailed knowledge of the compiler (which I’d rather accumulate than detailed knowledge of CMake, and I would know, I have both).