Skip to content

Commit bbdbe7f

Browse files
committed
FIX: an attempt to properly link stb library with CMake
1 parent 20df01a commit bbdbe7f

9 files changed

Lines changed: 27 additions & 4 deletions

File tree

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ option(AGS_USE_LOCAL_SDL2 "Use a locally installed SDL2" ${AGS_USE_LOCAL_ALL_LIB
2020
option(AGS_USE_LOCAL_SDL2_SOUND "Use a locally installed SDL2 Sound" ${AGS_USE_LOCAL_ALL_LIBRARIES})
2121
option(AGS_USE_LOCAL_GLM "Use a locally installed GLM" ${AGS_USE_LOCAL_ALL_LIBRARIES})
2222
option(AGS_USE_LOCAL_MINIZ "Use a locally installed Miniz" ${AGS_USE_LOCAL_ALL_LIBRARIES})
23+
option(AGS_USE_LOCAL_STB "Use a locally installed STB" ${AGS_USE_LOCAL_ALL_LIBRARIES})
2324
option(AGS_USE_LOCAL_TINYXML2 "Use a locally installed TinyXML2" ${AGS_USE_LOCAL_ALL_LIBRARIES})
2425
option(AGS_USE_LOCAL_OGG "Use a locally installed OGG" ${AGS_USE_LOCAL_ALL_LIBRARIES})
2526
option(AGS_USE_LOCAL_THEORA "Use a locally installed Theora" ${AGS_USE_LOCAL_ALL_LIBRARIES})
@@ -338,6 +339,11 @@ else()
338339
find_package(miniz REQUIRED)
339340
add_library(MiniZ::MiniZ ALIAS miniz::miniz)
340341
endif()
342+
if (NOT AGS_USE_LOCAL_STB)
343+
add_subdirectory(libsrc/stb EXCLUDE_FROM_ALL)
344+
else()
345+
find_package(stb REQUIRED)
346+
endif()
341347

342348
add_subdirectory(Common/libsrc/aastr-0.1.1 EXCLUDE_FROM_ALL)
343349

Common/gfx/image_png.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,14 @@
1818
//
1919
//=============================================================================
2020
#include <allegro.h>
21-
2221
// TODO: may create a separate header for including stb_image.h
2322
// with these predeclared flags
24-
#define STB_IMAGE_IMPLEMENTATION
25-
#define STB_IMAGE_STATIC
2623
#define STBI_NO_STDIO
2724
#define STBI_NO_LINEAR
2825
#define STBI_NO_HDR
2926
#define STBI_ONLY_PNG
3027
#define STBI_NO_FAILURE_STRINGS
3128
#include <stb_image.h>
32-
3329
#include <miniz.h>
3430
#include "gfx/bitmapdata.h"
3531
#include "util/stream.h"

Solutions/Common.Lib/Common.Lib.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,7 @@
781781
<ClCompile Include="..\..\libsrc\allegro\src\vtable8.c" />
782782
<ClCompile Include="..\..\libsrc\allegro\src\win\gdi.c" />
783783
<ClCompile Include="..\..\libsrc\allegro\src\win\wfile.c" />
784+
<ClCompile Include="..\..\libsrc\stb\stb.c" />
784785
</ItemGroup>
785786
<ItemGroup>
786787
<ClInclude Include="..\..\Common\ac\audiocliptype.h" />

Solutions/Common.Lib/Common.Lib.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,9 @@
539539
<ClCompile Include="..\..\Common\gfx\image_png.cpp">
540540
<Filter>Source Files\gfx</Filter>
541541
</ClCompile>
542+
<ClCompile Include="..\..\libsrc\stb\stb.c">
543+
<Filter>Library Sources\stb</Filter>
544+
</ClCompile>
542545
</ItemGroup>
543546
<ItemGroup>
544547
<ClInclude Include="..\..\Common\ac\audiocliptype.h">

Solutions/Tools.App/spritepak.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
<ClCompile Include="..\..\Common\util\string_utils.cpp" />
4242
<ClCompile Include="..\..\libsrc\allegro\src\color.c" />
4343
<ClCompile Include="..\..\libsrc\miniz\miniz.c" />
44+
<ClCompile Include="..\..\libsrc\stb\stb.c" />
4445
<ClCompile Include="..\..\Tools\spritepak\main.cpp" />
4546
<ClCompile Include="..\..\Tools\spritepak\commands.cpp" />
4647
</ItemGroup>

Solutions/Tools.App/spritepak.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@
9494
<ClCompile Include="..\..\Common\gfx\image_png.cpp">
9595
<Filter>Common</Filter>
9696
</ClCompile>
97+
<ClCompile Include="..\..\libsrc\stb\stb.c">
98+
<Filter>stb</Filter>
99+
</ClCompile>
97100
</ItemGroup>
98101
<ItemGroup>
99102
<ClInclude Include="..\..\Tools\spritepak\commands.h">

Tools/spritepak/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,15 @@ MINIMAL_ALLEGRO_OBJS = \
5151
MINIZ_OBJS = \
5252
../../libsrc/miniz/miniz.c
5353

54+
STB_OBJS = \
55+
../../libsrc/stb/stb_image.c
56+
5457
OBJS := main.cpp \
5558
commands.cpp \
5659
$(COMMON_OBJS) \
5760
$(MINIMAL_ALLEGRO_OBJS) \
5861
$(MINIZ_OBJS)
62+
$(STB_OBJS)
5963
OBJS := $(OBJS:.cpp=.o)
6064
OBJS := $(OBJS:.c=.o)
6165

libsrc/stb/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ target_include_directories(stb PUBLIC . )
99

1010
target_sources(stb
1111
PRIVATE
12+
stb_image.c
1213
stb_image.h
1314
)
1415

libsrc/stb/stb_image.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
#define STBI_NO_STDIO
3+
#define STBI_NO_LINEAR
4+
#define STBI_NO_HDR
5+
#define STBI_ONLY_PNG
6+
#define STBI_NO_FAILURE_STRINGS
7+
#define STB_IMAGE_IMPLEMENTATION
8+
#include <stb_image.h>

0 commit comments

Comments
 (0)