Skip to content

Commit f20d968

Browse files
fix: zlib internal compile
1 parent f551423 commit f20d968

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

CMakeLists.txt

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ include(cmake/third_party/CPM.cmake)
1515
# ── Compiler flags ────────────────────────────────────────────
1616
include(cmake/compile/CompilerFlag.cmake)
1717

18+
# ── Dependencies ──────────────────────────────────────────────
19+
CPMAddPackage(
20+
NAME zlib
21+
GITHUB_REPOSITORY madler/zlib
22+
GIT_TAG v1.3.1
23+
OPTIONS "CMAKE_POSITION_INDEPENDENT_CODE ON"
24+
)
25+
1826
# ── Applet configuration ─────────────────────────────────────
1927
include(cmake/Config.cmake)
2028

@@ -43,7 +51,14 @@ endforeach()
4351
add_executable(cfbox src/main.cpp ${CFBOX_APPLET_SOURCES})
4452
target_include_directories(cfbox PUBLIC include)
4553
target_include_directories(cfbox PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/include)
46-
target_link_libraries(cfbox PRIVATE cfbox_compiler_flags z)
54+
target_link_libraries(cfbox PRIVATE cfbox_compiler_flags)
55+
if(zlib_ADDED)
56+
target_link_libraries(cfbox PRIVATE zlibstatic)
57+
target_include_directories(cfbox SYSTEM PRIVATE ${zlib_SOURCE_DIR} ${zlib_BINARY_DIR})
58+
else()
59+
find_package(ZLIB REQUIRED)
60+
target_link_libraries(cfbox PRIVATE ZLIB::ZLIB)
61+
endif()
4762

4863
# ── GTest via CPM (FetchContent) ──────────────────────────────
4964
if(NOT CMAKE_CROSSCOMPILING)
@@ -65,8 +80,13 @@ if(GTest_ADDED)
6580
target_link_libraries(cfbox_tests PRIVATE
6681
cfbox_compiler_flags
6782
GTest::gtest_main
68-
z
6983
)
84+
if(zlib_ADDED)
85+
target_link_libraries(cfbox_tests PRIVATE zlibstatic)
86+
target_include_directories(cfbox_tests SYSTEM PRIVATE ${zlib_SOURCE_DIR} ${zlib_BINARY_DIR})
87+
else()
88+
target_link_libraries(cfbox_tests PRIVATE ZLIB::ZLIB)
89+
endif()
7090

7191
include(GoogleTest)
7292
gtest_discover_tests(cfbox_tests)

0 commit comments

Comments
 (0)