Skip to content

Commit 662ce4f

Browse files
committed
It builds just fine! :-o
1 parent 23935c8 commit 662ce4f

File tree

6 files changed

+495
-0
lines changed

6 files changed

+495
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
SFML-master/
2+
13
## Ignore Visual Studio temporary files, build results, and
24
## files generated by popular Visual Studio add-ons.
35
##

README.md

+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
### ABOUT
2+
3+
This small, frugal, self-containing (apart from a working MSVC shell, of
4+
course) build scaffolding creates "true" static builds of SFML for MSVC,
5+
as opposed to the shipped prebuilt lib versions that still depend on the
6+
MSVC (redistributable) runtime library DLLs, that may or may not be present
7+
on a target Windows instance.
8+
9+
IOW, the official SFML binaries have been compiled with `-MD` (and `-MDd`
10+
for DEBUG), whereas this setup builds with `-MT` (and `-MTd`) by default.
11+
(You can still build for the DLL version of the CRT with `build CRT=dll`.)
12+
13+
Note that it's not possible to mix differently compiled object code, so
14+
if you want to ensure that your app (or even just a simple static lib) that
15+
uses SFML doesn't "secretly" depend on any of the MSVC runtime DLLs, then
16+
recompiling SFML from source is your only option.
17+
18+
The generated static libs with the also static CRT dependency will have
19+
an extra `-s` suffix (in addition to the official one), e.g.
20+
`sfml-window-s-s.lib` or `sfml-window-s-s-d.lib`. (This scheme follows the
21+
original implicit general logic of "-s for static, nothing for DLL"...)
22+
23+
NOTE: The external `OpenAL.dll` library will still be linked dynamically
24+
(no way around that, AFAIK), but at least you can just easily ship that
25+
along with your executable (unlike the MSVC Redist. package).
26+
27+
------------------------------------------------------------------------------
28+
29+
### BEWARE!
30+
31+
This is an experimental proof-of-concept prototype tool for my own personal
32+
use, to quickly test integrating "SFML/MT" with some other projects.
33+
34+
The scripts and the makefile have been ripped out of some other existing
35+
configurations, _where this build setup was already pretty experimental to
36+
begin with!_ :) (I've been test-driving the surprisingly usable built-in make
37+
tool of [BusyBox-w32](https://github.com/rmyorston/busybox-w32/).)
38+
39+
So, this stuff here is full of weird remnants and junk -- OTOH, it still
40+
worked so well (thanks to the beautifully clean SFML repo, and its general
41+
build-friendly qualities, with all the external dependencies prepackaged*
42+
etc.) that I've just proceeded to baseline it as "the" build tool for this
43+
particular purpose of mine, in the context of my own projects.
44+
45+
Your mileage may vary.
46+
47+
\* <sub>FTR: I actually forgot that SFML comes with batteries included, and I
48+
initially downloaded & compiled everything from scratch, individually,
49+
fixing issues here and there etc., only to realize after-the-fact that
50+
I worked so hard for absolutely nothing... (I have a mild case of ADD,
51+
and didn't even realize that the repo already has an `extlibs` dir! :) )</sub>
52+
53+
------------------------------------------------------------------------------
54+
55+
### BUILD STEPS
56+
57+
#### 1. Download and unpack the SFML source repo
58+
59+
https://github.com/SFML/SFML/archive/refs/heads/master.zip
60+
61+
(Note that this is the latest pre-3.0 branch, very much in flux, but
62+
still very usable and robust, albeit breaking the API occasionally.)
63+
64+
The unpacked repo (should be `SFML-master` -- adjust the build script
65+
if it isn't) is expeted to be in the same dir as the `build` script.
66+
67+
#### 2. One small fix...
68+
69+
There's one thing I had to fix there: disable FLAC's assert.h in
70+
`extlibs\headers\FLAC`. It kept failing with `assert` being an undefined
71+
identifier, probably due to the `INCLUDE` path (ordering) set up by the
72+
scripts, and I couldn't quickly find the reason; but strangely enough,
73+
just taking that header down fixed it... :-o
74+
75+
#### 3. CRUCIAL: Remove the unused platform sources!
76+
77+
This experimental makefile can't skip directories, and would just want
78+
to compile all the C/C++ files it can find in the source tree. So,
79+
80+
ALL THE IRRELEVANT PLATFORM-SPECIFIC SOURCES MUST BE MOVED OUT
81+
OF THE WAY MANUALLY!
82+
83+
84+
Fortunately, this is very easy, too: just remove all but the `Win32` subdirs
85+
under `src`, namely from:
86+
87+
- Window
88+
- Main
89+
- Network
90+
- System
91+
92+
(or wherever else you may find any).
93+
94+
#### 4. Run `build`
95+
96+
You can specify `CRT=dll` to build the original ("half") static libs, and
97+
`DEBUG=1` for a debug version. E.g.:
98+
99+
build
100+
101+
would build the fully static libs in release mode (-DNDEBUG -O2), while
102+
103+
build CRT=dll DEBUG=1
104+
105+
would build for the DLL version of th MSVC runtime, with debug info and
106+
disabled optimizations.
107+
108+
The generated .lib files are in the `lib` dir, created inside the repo, so
109+
that now it has a compatible layout with the official pre-built packages.
110+
(Except the `bin` dir, as this build tool does not build DLLs. It probably
111+
could, but I just didn't bother adding that without a good reason.)
112+
113+
Note: each of the four supported build combinations are built in separate
114+
parallel "VPATH" trees, so you can incrementally rebuild them, if you wish,
115+
without interference.
116+
117+
#### 5. There's no `build clean`
118+
119+
Just delete the `.build.tmp` dir (or only its build-mode specific subtree
120+
that you want to fully rebuild).

build.cmd

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
::
2+
:: Build with BusyBox-w32 & MSVC
3+
::
4+
@echo off
5+
6+
set SZ_PRJDIR=SFML-master
7+
8+
call %~dp0tooling\_setenv.cmd
9+
::
10+
:: We've now been CD'd into PRJ_DIR!
11+
::
12+
busybox make -f ../tooling/bbMakefile.msvc %*

tooling/_setenv.cmd

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
@echo off
2+
rem This is expected to be called from a (temporary) process context, where
3+
rem the env. vars won't persist, and won't clash with anything important!
4+
5+
set SZ_APP_NAME=SFML-MT
6+
7+
rem !! These could crash horrendously, if e.g. a pre-existing value has & in it, etc...
8+
rem !! Try with set "...=..."!
9+
10+
if "%SZ_PRJDIR%"=="" set SZ_PRJDIR=%~dp0..
11+
12+
set SZ_SRC_SUBDIR=src
13+
set SZ_OUT_SUBDIR=.build.out
14+
set SZ_LIB_SUBDIR=lib
15+
set SZ_IFC_SUBDIR=ifc
16+
set SZ_TEST_SUBDIR=test
17+
set SZ_RUN_SUBDIR=%SZ_TEST_SUBDIR%
18+
set SZ_ASSET_SUBDIR=asset
19+
set SZ_RELEASE_SUBDIR=release
20+
21+
set SZ_SRC_DIR=%SZ_PRJDIR%/%SZ_SRC_SUBDIR%
22+
set SZ_OUT_DIR=%SZ_PRJDIR%/%SZ_OUT_SUBDIR%
23+
set SZ_LIB_DIR=%SZ_PRJDIR%/%SZ_LIB_SUBDIR%
24+
set SZ_TEST_DIR=%SZ_PRJDIR%/%SZ_TEST_SUBDIR%
25+
set SZ_RUN_DIR=%SZ_TEST_DIR%
26+
set SZ_ASSET_DIR=%SZ_PRJDIR%/%SZ_ASSET_SUBDIR%
27+
set SZ_TMP_DIR=%SZ_PRJDIR%/tmp
28+
set SZ_RELEASE_DIR=%SZ_TMP_DIR%/%SZ_RELEASE_SUBDIR%
29+
30+
rem CD to prj root for the rest of the process:
31+
cd "%SZ_PRJDIR%"
32+
if errorlevel 1 (
33+
echo - ERROR: Failed to enter the project dir ^(%SZ_PRJDIR%^)^!
34+
exit 1
35+
) else (
36+
rem Normalize the prj. dir ^(well, stil backslashes, awkwardly differing from the rest...^)
37+
set SZ_PRJDIR=%CD%
38+
)
39+
40+
rem if not exist "%SZ_OUT_DIR%" md "%SZ_OUT_DIR%"
41+
42+
43+
:: Extern...
44+
set ext_inc=extlibs/headers
45+
set ext_inc=%ext_inc%;extlibs/headers/glad/include;extlibs/headers/stb_image;extlibs/headers/freetype2;extlibs/headers/vulkan
46+
set ext_inc=%ext_inc%;extlibs/headers/AL;extlibs/headers/ogg;extlibs/headers/FLAC;extlibs/headers/minimp3
47+
48+
set PATH=%SZ_PRJDIR%/../tooling;%SZ_SFML_LIBROOT%/bin;%PATH%
49+
set LIB=%SZ_SFML_LIBROOT%/lib;%LIB%
50+
set INCLUDE=%ext_inc%;%SZ_PRJDIR%/include;%SZ_PRJDIR%;%INCLUDE%

0 commit comments

Comments
 (0)