Skip to content

Commit

Permalink
fix(cmake): solve win32 linking issues with zlib
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Dellaluce <[email protected]>
  • Loading branch information
jasondellaluce authored and poiana committed Nov 15, 2023
1 parent bd9b04b commit 7cbc03a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
9 changes: 7 additions & 2 deletions cmake/modules/zlib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,18 @@ else()
install(FILES ${ZLIB_HEADERS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${LIBS_PACKAGE_NAME}/zlib"
COMPONENT "libs-deps")
else()
set(ZLIB_LIB "${ZLIB_SRC}/zlib.lib")
if(BUILD_SHARED_LIBS)
set(ZLIB_LIB_SUFFIX "${CMAKE_SHARED_LIBRARY_SUFFIX}")
else()
set(ZLIB_LIB_SUFFIX "${CMAKE_STATIC_LIBRARY_SUFFIX}")
endif()
set(ZLIB_LIB "${ZLIB_SRC}/zlib${ZLIB_LIB_SUFFIX}")
ExternalProject_Add(zlib
PREFIX "${PROJECT_BINARY_DIR}/zlib-prefix"
URL "https://github.com/madler/zlib/archive/v1.2.13.tar.gz"
URL_HASH "SHA256=1525952a0a567581792613a9723333d7f8cc20b87a81f920fb8bc7e3f2251428"
CONFIGURE_COMMAND ""
BUILD_COMMAND nmake -f win32/Makefile.msc
BUILD_COMMAND nmake -f win32/Makefile.msc LOC=-DZLIB_WINAPI
BUILD_IN_SOURCE 1
BUILD_BYPRODUCTS ${ZLIB_LIB}
INSTALL_COMMAND "")
Expand Down
5 changes: 4 additions & 1 deletion userspace/libscap/scap_zlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ limitations under the License.

#include "settings.h"

#if defined(USE_ZLIB) && !defined(UDIG) && !defined(_WIN32)
#if defined(USE_ZLIB) && !defined(UDIG)
#ifdef _WIN32
#define ZLIB_WINAPI
#endif
#include <zlib.h>
#else
#include <stdio.h>
Expand Down
4 changes: 3 additions & 1 deletion userspace/libsinsp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ if(WITH_CHISEL)
include(tinydir)
endif()

include(zlib)

if(NOT MINIMAL_BUILD)
include(zlib)
if (NOT WIN32 AND NOT EMSCRIPTEN)
include(curl)
include(cares)
Expand Down Expand Up @@ -194,6 +195,7 @@ target_link_libraries(sinsp

set(SINSP_PKGCONFIG_LIBRARIES
scap
"${ZLIB_LIB}"
"${CURL_LIBRARIES}"
"${JSONCPP_LIB}"
"${RE2_LIB}"
Expand Down
4 changes: 1 addition & 3 deletions userspace/libsinsp/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ if(NOT MINIMAL_BUILD AND NOT EMSCRIPTEN)
include(curl)
endif() # MINIMAL_BUILD

if(NOT MINIMAL_BUILD)
include(zlib)
endif()
include(zlib)

if(WIN32)
set(CMAKE_CXX_FLAGS "-D_CRT_SECURE_NO_WARNINGS -DWIN32 -DMINIMAL_BUILD /EHsc /W3 /Zi /std:c++17")
Expand Down

0 comments on commit 7cbc03a

Please sign in to comment.