Skip to content

Commit 5220227

Browse files
authored
core: Allow compiling without JXL support (#6)
* Allow compiling without JXL support Remember to link the libraries and add the compile definitions * tests: when compiled without JXL support, expect that to fail
1 parent b099807 commit 5220227

File tree

4 files changed

+29
-7
lines changed

4 files changed

+29
-7
lines changed

CMakeLists.txt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,20 @@ pkg_check_modules(
4747
hyprutils
4848
libjpeg
4949
libwebp
50+
libmagic)
51+
52+
pkg_check_modules(
53+
JXL
5054
libjxl
5155
libjxl_cms
5256
libjxl_threads
53-
libmagic)
57+
)
58+
if(NOT JXL_FOUND)
59+
file(GLOB_RECURSE JPEGXLFILES CONFIGURE_DEPENDS "src/*JpegXL.cpp")
60+
list(REMOVE_ITEM SRCFILES ${JPEGXLFILES})
61+
else()
62+
add_compile_definitions(JXL_FOUND)
63+
endif()
5464

5565
add_library(hyprgraphics SHARED ${SRCFILES})
5666
target_include_directories(
@@ -59,7 +69,7 @@ target_include_directories(
5969
PRIVATE "./src")
6070
set_target_properties(hyprgraphics PROPERTIES VERSION ${HYPRGRAPHICS_VERSION}
6171
SOVERSION 0)
62-
target_link_libraries(hyprgraphics PkgConfig::deps)
72+
target_link_libraries(hyprgraphics PkgConfig::deps ${JXL_LIBRARIES})
6373

6474
# tests
6575
add_custom_target(tests)

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ Dep list:
1616
- hyprutils
1717
- libjpeg
1818
- libwebp
19-
- libjxl
20-
- libjxl_cms
21-
- libjxl_threads
19+
- libjxl [optional]
20+
- libjxl_cms [optional]
21+
- libjxl_threads [optional]
2222
- libmagic
2323

2424
## Building

src/image/Image.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#include <hyprgraphics/image/Image.hpp>
22
#include "formats/Bmp.hpp"
33
#include "formats/Jpeg.hpp"
4+
#ifdef JXL_FOUND
45
#include "formats/JpegXL.hpp"
6+
#endif
57
#include "formats/Webp.hpp"
68
#include <magic.h>
79
#include <format>
@@ -27,8 +29,15 @@ Hyprgraphics::CImage::CImage(const std::string& path) : filepath(path) {
2729
CAIROSURFACE = WEBP::createSurfaceFromWEBP(path);
2830
mime = "image/webp";
2931
} else if (path.find(".jxl") == len - 4 || path.find(".JXL") == len - 4) {
32+
33+
#ifdef JXL_FOUND
3034
CAIROSURFACE = JXL::createSurfaceFromJXL(path);
3135
mime = "image/jxl";
36+
#else
37+
lastError = "hyprgraphics compiled without JXL support";
38+
return;
39+
#endif
40+
3241
} else {
3342
// magic is slow, so only use it when no recognized extension is found
3443
auto handle = magic_open(MAGIC_NONE | MAGIC_COMPRESS | MAGIC_SYMLINK);

tests/image.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ int main(int argc, char** argv, char** envp) {
2525
for (auto& file : std::filesystem::directory_iterator("./resource/images/")) {
2626
if (!file.is_regular_file())
2727
continue;
28-
29-
EXPECT(tryLoadImage(file.path()), true);
28+
auto expectation = true;
29+
#ifndef JXL_FOUND
30+
if (file.path().filename() == "hyprland.jxl") expectation = false;
31+
#endif
32+
EXPECT(tryLoadImage(file.path()), expectation);
3033
}
3134

3235
return ret;

0 commit comments

Comments
 (0)