Skip to content

Commit a0aa752

Browse files
committed
refactor: centralize STB implementation and add Emscripten support
Description: - Centralized STB implementations: Moved #define STB_IMAGE_IMPLEMENTATION and related defines from individual command files to a new src/core/stb_impl.cpp to prevent multiple definition errors and improve compilation times. - Added Emscripten (WASM) support: - Forced single-threaded execution in spratlayout, spratpack, and spratunpack when compiled with __EMSCRIPTEN__. - Refactored spratlayout packing loops into reusable worker functions (run_guided_worker, run_shelf_worker) to support both synchronous and multi-threaded execution paths. - CMake improvements: - Integrated command entry points and stb_impl.cpp into the spratcore static library. - Enhanced LibArchive discovery to prefer targets and handle include directories more robustly. - Made test building conditional on the BUILD_TESTING option.
1 parent d475bf0 commit a0aa752

6 files changed

Lines changed: 192 additions & 151 deletions

File tree

CMakeLists.txt

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,16 @@ add_library(spratcore STATIC
123123
src/core/layout_parser.cpp
124124
src/core/output_pattern.cpp
125125
src/core/i18n.cpp
126+
src/core/stb_impl.cpp
127+
src/commands/spratlayout_command.cpp
128+
src/commands/spratpack_command.cpp
129+
src/commands/spratconvert_command.cpp
130+
src/commands/spratframes_command.cpp
131+
src/commands/spratunpack_command.cpp
126132
)
133+
target_include_directories(spratcore PUBLIC src)
134+
target_include_directories(spratcore SYSTEM PRIVATE ${STB_DIR})
135+
target_include_directories(spratcore PRIVATE ${LIBARCHIVE_INCLUDE_DIRS})
127136

128137
option(SPRAT_ENABLE_NLS "Enable gettext-based translations when available" ON)
129138
option(SPRAT_REQUIRE_GETTEXT "Fail configure if gettext support is requested but unavailable" OFF)
@@ -172,7 +181,13 @@ target_compile_definitions(spratcore PUBLIC SPRAT_LOCALE_DIR="${CMAKE_INSTALL_FU
172181
# Binaries
173182
# For Windows cross-compilation, PkgConfig often leaks host paths.
174183
# We prefer find_package or explicit paths.
175-
if(WIN32 OR CMAKE_SYSTEM_NAME STREQUAL "Windows")
184+
if(TARGET LibArchive::LibArchive)
185+
set(LIBARCHIVE_LIBRARIES LibArchive::LibArchive)
186+
set(LIBARCHIVE_FOUND TRUE)
187+
if(NOT LIBARCHIVE_INCLUDE_DIRS)
188+
get_target_property(LIBARCHIVE_INCLUDE_DIRS LibArchive::LibArchive INTERFACE_INCLUDE_DIRECTORIES)
189+
endif()
190+
elseif(WIN32 OR CMAKE_SYSTEM_NAME STREQUAL "Windows" OR EMSCRIPTEN)
176191
find_package(LibArchive QUIET)
177192
if(LibArchive_FOUND)
178193
set(LIBARCHIVE_LIBRARIES LibArchive::LibArchive)
@@ -329,5 +344,7 @@ install(DIRECTORY transforms/
329344
install(FILES man/sprat-cli.1
330345
DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
331346

332-
enable_testing()
333-
add_subdirectory(tests)
347+
if(BUILD_TESTING)
348+
enable_testing()
349+
add_subdirectory(tests)
350+
endif()

src/commands/spratframes_command.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ namespace fs = std::filesystem;
4040
#include "core/cli_parse.h"
4141
#include "core/i18n.h"
4242

43-
#define STB_IMAGE_IMPLEMENTATION
4443
#include <stb_image.h>
4544

4645
// Configuration

0 commit comments

Comments
 (0)