xref: /third_party/node/deps/zlib/CMakeLists.txt (revision 1cb0ef41)
11cb0ef41Sopenharmony_cicmake_minimum_required(VERSION 2.4.4...3.15.0)
21cb0ef41Sopenharmony_ciset(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON)
31cb0ef41Sopenharmony_ci
41cb0ef41Sopenharmony_ciproject(zlib C)
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ciset(VERSION "1.3.0.1")
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ciset(INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Installation directory for executables")
91cb0ef41Sopenharmony_ciset(INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE PATH "Installation directory for libraries")
101cb0ef41Sopenharmony_ciset(INSTALL_INC_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "Installation directory for headers")
111cb0ef41Sopenharmony_ciset(INSTALL_MAN_DIR "${CMAKE_INSTALL_PREFIX}/share/man" CACHE PATH "Installation directory for manual pages")
121cb0ef41Sopenharmony_ciset(INSTALL_PKGCONFIG_DIR "${CMAKE_INSTALL_PREFIX}/share/pkgconfig" CACHE PATH "Installation directory for pkgconfig (.pc) files")
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_ciinclude(CheckTypeSize)
151cb0ef41Sopenharmony_ciinclude(CheckFunctionExists)
161cb0ef41Sopenharmony_ciinclude(CheckIncludeFile)
171cb0ef41Sopenharmony_ciinclude(CheckCSourceCompiles)
181cb0ef41Sopenharmony_cienable_testing()
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_cicheck_include_file(sys/types.h HAVE_SYS_TYPES_H)
211cb0ef41Sopenharmony_cicheck_include_file(stdint.h    HAVE_STDINT_H)
221cb0ef41Sopenharmony_cicheck_include_file(stddef.h    HAVE_STDDEF_H)
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_cioption(ENABLE_SIMD_OPTIMIZATIONS "Enable all SIMD optimizations" OFF)
251cb0ef41Sopenharmony_cioption(ENABLE_SIMD_AVX512 "Enable SIMD AXV512 optimizations" OFF)
261cb0ef41Sopenharmony_cioption(USE_ZLIB_RABIN_KARP_HASH "Enable bitstream compatibility with canonical zlib" OFF)
271cb0ef41Sopenharmony_cioption(BUILD_UNITTESTS "Enable standalone unit tests build" OFF)
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ciif (USE_ZLIB_RABIN_KARP_HASH)
301cb0ef41Sopenharmony_ci   add_definitions(-DUSE_ZLIB_RABIN_KARP_ROLLING_HASH)
311cb0ef41Sopenharmony_ciendif()
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_ci# TODO(cavalcantii): add support for other OSes (e.g. Android, fuchsia, osx)
341cb0ef41Sopenharmony_ci# and architectures (e.g. Arm).
351cb0ef41Sopenharmony_ciif (ENABLE_SIMD_OPTIMIZATIONS)
361cb0ef41Sopenharmony_ci   add_definitions(-DINFLATE_CHUNK_SIMD_SSE2)
371cb0ef41Sopenharmony_ci   add_definitions(-DADLER32_SIMD_SSSE3)
381cb0ef41Sopenharmony_ci   add_definitions(-DINFLATE_CHUNK_READ_64LE)
391cb0ef41Sopenharmony_ci   add_definitions(-DCRC32_SIMD_SSE42_PCLMUL)
401cb0ef41Sopenharmony_ci   if (ENABLE_SIMD_AVX512)
411cb0ef41Sopenharmony_ci    add_definitions(-DCRC32_SIMD_AVX512_PCLMUL)
421cb0ef41Sopenharmony_ci    add_compile_options(-mvpclmulqdq -msse2 -mavx512f -mpclmul)
431cb0ef41Sopenharmony_ci   else()
441cb0ef41Sopenharmony_ci    add_compile_options(-msse4.2 -mpclmul)
451cb0ef41Sopenharmony_ci   endif()
461cb0ef41Sopenharmony_ci   add_definitions(-DDEFLATE_SLIDE_HASH_SSE2)
471cb0ef41Sopenharmony_ci   # Required by CPU features detection code.
481cb0ef41Sopenharmony_ci   add_definitions(-DX86_NOT_WINDOWS)
491cb0ef41Sopenharmony_ci   # Apparently some environments (e.g. CentOS) require to explicitly link
501cb0ef41Sopenharmony_ci   # with pthread and that is required by the CPU features detection code.
511cb0ef41Sopenharmony_ci   find_package (Threads REQUIRED)
521cb0ef41Sopenharmony_ci   SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread")
531cb0ef41Sopenharmony_ci   SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
541cb0ef41Sopenharmony_ciendif()
551cb0ef41Sopenharmony_ci
561cb0ef41Sopenharmony_ci#
571cb0ef41Sopenharmony_ci# Check to see if we have large file support
581cb0ef41Sopenharmony_ci#
591cb0ef41Sopenharmony_ciset(CMAKE_REQUIRED_DEFINITIONS -D_LARGEFILE64_SOURCE=1)
601cb0ef41Sopenharmony_ci# We add these other definitions here because CheckTypeSize.cmake
611cb0ef41Sopenharmony_ci# in CMake 2.4.x does not automatically do so and we want
621cb0ef41Sopenharmony_ci# compatibility with CMake 2.4.x.
631cb0ef41Sopenharmony_ciif(HAVE_SYS_TYPES_H)
641cb0ef41Sopenharmony_ci    list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_SYS_TYPES_H)
651cb0ef41Sopenharmony_ciendif()
661cb0ef41Sopenharmony_ciif(HAVE_STDINT_H)
671cb0ef41Sopenharmony_ci    list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDINT_H)
681cb0ef41Sopenharmony_ciendif()
691cb0ef41Sopenharmony_ciif(HAVE_STDDEF_H)
701cb0ef41Sopenharmony_ci    list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDDEF_H)
711cb0ef41Sopenharmony_ciendif()
721cb0ef41Sopenharmony_cicheck_type_size(off64_t OFF64_T)
731cb0ef41Sopenharmony_ciif(HAVE_OFF64_T)
741cb0ef41Sopenharmony_ci   add_definitions(-D_LARGEFILE64_SOURCE=1)
751cb0ef41Sopenharmony_ciendif()
761cb0ef41Sopenharmony_ciset(CMAKE_REQUIRED_DEFINITIONS) # clear variable
771cb0ef41Sopenharmony_ci
781cb0ef41Sopenharmony_ci#
791cb0ef41Sopenharmony_ci# Check for fseeko
801cb0ef41Sopenharmony_ci#
811cb0ef41Sopenharmony_cicheck_function_exists(fseeko HAVE_FSEEKO)
821cb0ef41Sopenharmony_ciif(NOT HAVE_FSEEKO)
831cb0ef41Sopenharmony_ci    add_definitions(-DNO_FSEEKO)
841cb0ef41Sopenharmony_ciendif()
851cb0ef41Sopenharmony_ci
861cb0ef41Sopenharmony_ci#
871cb0ef41Sopenharmony_ci# Check for unistd.h
881cb0ef41Sopenharmony_ci#
891cb0ef41Sopenharmony_cicheck_include_file(unistd.h Z_HAVE_UNISTD_H)
901cb0ef41Sopenharmony_ci
911cb0ef41Sopenharmony_ciif(MSVC)
921cb0ef41Sopenharmony_ci    set(CMAKE_DEBUG_POSTFIX "d")
931cb0ef41Sopenharmony_ci    add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
941cb0ef41Sopenharmony_ci    add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE)
951cb0ef41Sopenharmony_ci    include_directories(${CMAKE_CURRENT_SOURCE_DIR})
961cb0ef41Sopenharmony_ciendif()
971cb0ef41Sopenharmony_ci
981cb0ef41Sopenharmony_ciif(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR)
991cb0ef41Sopenharmony_ci    # If we're doing an out of source build and the user has a zconf.h
1001cb0ef41Sopenharmony_ci    # in their source tree...
1011cb0ef41Sopenharmony_ci    if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h)
1021cb0ef41Sopenharmony_ci        message(STATUS "Renaming")
1031cb0ef41Sopenharmony_ci        message(STATUS "    ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h")
1041cb0ef41Sopenharmony_ci        message(STATUS "to 'zconf.h.included' because this file is included with zlib")
1051cb0ef41Sopenharmony_ci        message(STATUS "but CMake generates it automatically in the build directory.")
1061cb0ef41Sopenharmony_ci        file(RENAME ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h.included)
1071cb0ef41Sopenharmony_ci  endif()
1081cb0ef41Sopenharmony_ciendif()
1091cb0ef41Sopenharmony_ci
1101cb0ef41Sopenharmony_ciset(ZLIB_PC ${CMAKE_CURRENT_BINARY_DIR}/zlib.pc)
1111cb0ef41Sopenharmony_ciconfigure_file( ${CMAKE_CURRENT_SOURCE_DIR}/zlib.pc.cmakein
1121cb0ef41Sopenharmony_ci		${ZLIB_PC} @ONLY)
1131cb0ef41Sopenharmony_ciconfigure_file(	${CMAKE_CURRENT_SOURCE_DIR}/zconf.h.cmakein
1141cb0ef41Sopenharmony_ci		${CMAKE_CURRENT_BINARY_DIR}/zconf.h @ONLY)
1151cb0ef41Sopenharmony_ciinclude_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR})
1161cb0ef41Sopenharmony_ci
1171cb0ef41Sopenharmony_ci
1181cb0ef41Sopenharmony_ci#============================================================================
1191cb0ef41Sopenharmony_ci# zlib
1201cb0ef41Sopenharmony_ci#============================================================================
1211cb0ef41Sopenharmony_ci
1221cb0ef41Sopenharmony_ciset(ZLIB_PUBLIC_HDRS
1231cb0ef41Sopenharmony_ci    ${CMAKE_CURRENT_BINARY_DIR}/zconf.h
1241cb0ef41Sopenharmony_ci    zlib.h
1251cb0ef41Sopenharmony_ci)
1261cb0ef41Sopenharmony_ciset(ZLIB_PRIVATE_HDRS
1271cb0ef41Sopenharmony_ci    crc32.h
1281cb0ef41Sopenharmony_ci    deflate.h
1291cb0ef41Sopenharmony_ci    gzguts.h
1301cb0ef41Sopenharmony_ci    inffast.h
1311cb0ef41Sopenharmony_ci    inffixed.h
1321cb0ef41Sopenharmony_ci    inflate.h
1331cb0ef41Sopenharmony_ci    inftrees.h
1341cb0ef41Sopenharmony_ci    trees.h
1351cb0ef41Sopenharmony_ci    zutil.h
1361cb0ef41Sopenharmony_ci)
1371cb0ef41Sopenharmony_ciset(ZLIB_SRCS
1381cb0ef41Sopenharmony_ci    adler32.c
1391cb0ef41Sopenharmony_ci    compress.c
1401cb0ef41Sopenharmony_ci    crc32.c
1411cb0ef41Sopenharmony_ci    deflate.c
1421cb0ef41Sopenharmony_ci    gzclose.c
1431cb0ef41Sopenharmony_ci    gzlib.c
1441cb0ef41Sopenharmony_ci    gzread.c
1451cb0ef41Sopenharmony_ci    gzwrite.c
1461cb0ef41Sopenharmony_ci    inflate.c
1471cb0ef41Sopenharmony_ci    infback.c
1481cb0ef41Sopenharmony_ci    inftrees.c
1491cb0ef41Sopenharmony_ci    inffast.c
1501cb0ef41Sopenharmony_ci    trees.c
1511cb0ef41Sopenharmony_ci    uncompr.c
1521cb0ef41Sopenharmony_ci    zutil.c
1531cb0ef41Sopenharmony_ci)
1541cb0ef41Sopenharmony_ci
1551cb0ef41Sopenharmony_ci
1561cb0ef41Sopenharmony_ci#============================================================================
1571cb0ef41Sopenharmony_ci# Update list of source files if optimizations were enabled
1581cb0ef41Sopenharmony_ci#============================================================================
1591cb0ef41Sopenharmony_ciif (ENABLE_SIMD_OPTIMIZATIONS)
1601cb0ef41Sopenharmony_ci  list(REMOVE_ITEM ZLIB_SRCS inflate.c)
1611cb0ef41Sopenharmony_ci
1621cb0ef41Sopenharmony_ci  list(APPEND ZLIB_PRIVATE_HDRS ${CMAKE_CURRENT_SOURCE_DIR}/adler32_simd.h)
1631cb0ef41Sopenharmony_ci  list(APPEND ZLIB_PRIVATE_HDRS ${CMAKE_CURRENT_SOURCE_DIR}/contrib/optimizations/chunkcopy.h)
1641cb0ef41Sopenharmony_ci  list(APPEND ZLIB_PRIVATE_HDRS ${CMAKE_CURRENT_SOURCE_DIR}/contrib/optimizations/inffast_chunk.h)
1651cb0ef41Sopenharmony_ci  list(APPEND ZLIB_PRIVATE_HDRS ${CMAKE_CURRENT_SOURCE_DIR}/cpu_features.h)
1661cb0ef41Sopenharmony_ci  list(APPEND ZLIB_PRIVATE_HDRS ${CMAKE_CURRENT_SOURCE_DIR}/crc32_simd.h)
1671cb0ef41Sopenharmony_ci
1681cb0ef41Sopenharmony_ci  list(APPEND ZLIB_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/adler32_simd.c)
1691cb0ef41Sopenharmony_ci  list(APPEND ZLIB_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/contrib/optimizations/inffast_chunk.c)
1701cb0ef41Sopenharmony_ci  list(APPEND ZLIB_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/contrib/optimizations/inflate.c)
1711cb0ef41Sopenharmony_ci  list(APPEND ZLIB_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/cpu_features.c)
1721cb0ef41Sopenharmony_ci  list(APPEND ZLIB_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/crc32_simd.c)
1731cb0ef41Sopenharmony_ci  list(APPEND ZLIB_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/crc_folding.c)
1741cb0ef41Sopenharmony_ciendif()
1751cb0ef41Sopenharmony_ci
1761cb0ef41Sopenharmony_ci# parse the full version number from zlib.h and include in ZLIB_FULL_VERSION
1771cb0ef41Sopenharmony_cifile(READ ${CMAKE_CURRENT_SOURCE_DIR}/zlib.h _zlib_h_contents)
1781cb0ef41Sopenharmony_cistring(REGEX REPLACE ".*#define[ \t]+ZLIB_VERSION[ \t]+\"([-0-9A-Za-z.]+)\".*"
1791cb0ef41Sopenharmony_ci    "\\1" ZLIB_FULL_VERSION ${_zlib_h_contents})
1801cb0ef41Sopenharmony_ci
1811cb0ef41Sopenharmony_ciif(MINGW)
1821cb0ef41Sopenharmony_ci    # This gets us DLL resource information when compiling on MinGW.
1831cb0ef41Sopenharmony_ci    if(NOT CMAKE_RC_COMPILER)
1841cb0ef41Sopenharmony_ci        set(CMAKE_RC_COMPILER windres.exe)
1851cb0ef41Sopenharmony_ci    endif()
1861cb0ef41Sopenharmony_ci
1871cb0ef41Sopenharmony_ci    add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj
1881cb0ef41Sopenharmony_ci                       COMMAND ${CMAKE_RC_COMPILER}
1891cb0ef41Sopenharmony_ci                            -D GCC_WINDRES
1901cb0ef41Sopenharmony_ci                            -I ${CMAKE_CURRENT_SOURCE_DIR}
1911cb0ef41Sopenharmony_ci                            -I ${CMAKE_CURRENT_BINARY_DIR}
1921cb0ef41Sopenharmony_ci                            -o ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj
1931cb0ef41Sopenharmony_ci                            -i ${CMAKE_CURRENT_SOURCE_DIR}/win32/zlib1.rc)
1941cb0ef41Sopenharmony_ci    set(ZLIB_DLL_SRCS ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj)
1951cb0ef41Sopenharmony_ciendif(MINGW)
1961cb0ef41Sopenharmony_ci
1971cb0ef41Sopenharmony_ciadd_library(zlib SHARED ${ZLIB_SRCS} ${ZLIB_DLL_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
1981cb0ef41Sopenharmony_ciadd_library(zlibstatic STATIC ${ZLIB_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
1991cb0ef41Sopenharmony_ciset_target_properties(zlib PROPERTIES DEFINE_SYMBOL ZLIB_DLL)
2001cb0ef41Sopenharmony_ciset_target_properties(zlib PROPERTIES SOVERSION 1)
2011cb0ef41Sopenharmony_ci
2021cb0ef41Sopenharmony_ciif(NOT CYGWIN)
2031cb0ef41Sopenharmony_ci    # This property causes shared libraries on Linux to have the full version
2041cb0ef41Sopenharmony_ci    # encoded into their final filename.  We disable this on Cygwin because
2051cb0ef41Sopenharmony_ci    # it causes cygz-${ZLIB_FULL_VERSION}.dll to be created when cygz.dll
2061cb0ef41Sopenharmony_ci    # seems to be the default.
2071cb0ef41Sopenharmony_ci    #
2081cb0ef41Sopenharmony_ci    # This has no effect with MSVC, on that platform the version info for
2091cb0ef41Sopenharmony_ci    # the DLL comes from the resource file win32/zlib1.rc
2101cb0ef41Sopenharmony_ci    set_target_properties(zlib PROPERTIES VERSION ${ZLIB_FULL_VERSION})
2111cb0ef41Sopenharmony_ciendif()
2121cb0ef41Sopenharmony_ci
2131cb0ef41Sopenharmony_ciif(UNIX)
2141cb0ef41Sopenharmony_ci    # On unix-like platforms the library is almost always called libz
2151cb0ef41Sopenharmony_ci   set_target_properties(zlib zlibstatic PROPERTIES OUTPUT_NAME z)
2161cb0ef41Sopenharmony_ci   if(NOT APPLE)
2171cb0ef41Sopenharmony_ci     set_target_properties(zlib PROPERTIES LINK_FLAGS "-Wl,--version-script,\"${CMAKE_CURRENT_SOURCE_DIR}/zlib.map\"")
2181cb0ef41Sopenharmony_ci   endif()
2191cb0ef41Sopenharmony_cielseif(BUILD_SHARED_LIBS AND WIN32)
2201cb0ef41Sopenharmony_ci    # Creates zlib1.dll when building shared library version
2211cb0ef41Sopenharmony_ci    set_target_properties(zlib PROPERTIES SUFFIX "1.dll")
2221cb0ef41Sopenharmony_ciendif()
2231cb0ef41Sopenharmony_ci
2241cb0ef41Sopenharmony_ciif(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL )
2251cb0ef41Sopenharmony_ci    install(TARGETS zlib zlibstatic
2261cb0ef41Sopenharmony_ci        RUNTIME DESTINATION "${INSTALL_BIN_DIR}"
2271cb0ef41Sopenharmony_ci        ARCHIVE DESTINATION "${INSTALL_LIB_DIR}"
2281cb0ef41Sopenharmony_ci        LIBRARY DESTINATION "${INSTALL_LIB_DIR}" )
2291cb0ef41Sopenharmony_ciendif()
2301cb0ef41Sopenharmony_ciif(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL )
2311cb0ef41Sopenharmony_ci    install(FILES ${ZLIB_PUBLIC_HDRS} DESTINATION "${INSTALL_INC_DIR}")
2321cb0ef41Sopenharmony_ciendif()
2331cb0ef41Sopenharmony_ciif(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL )
2341cb0ef41Sopenharmony_ci    install(FILES zlib.3 DESTINATION "${INSTALL_MAN_DIR}/man3")
2351cb0ef41Sopenharmony_ciendif()
2361cb0ef41Sopenharmony_ciif(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL )
2371cb0ef41Sopenharmony_ci    install(FILES ${ZLIB_PC} DESTINATION "${INSTALL_PKGCONFIG_DIR}")
2381cb0ef41Sopenharmony_ciendif()
2391cb0ef41Sopenharmony_ci
2401cb0ef41Sopenharmony_ci#============================================================================
2411cb0ef41Sopenharmony_ci# Benchmarker
2421cb0ef41Sopenharmony_ci#============================================================================
2431cb0ef41Sopenharmony_cienable_language(CXX)
2441cb0ef41Sopenharmony_ciset(CMAKE_CXX_STANDARD 14) # workaround for older compilers (e.g. g++ 5.4).
2451cb0ef41Sopenharmony_ciadd_executable(zlib_bench contrib/bench/zlib_bench.cc)
2461cb0ef41Sopenharmony_citarget_link_libraries(zlib_bench zlib)
2471cb0ef41Sopenharmony_ci
2481cb0ef41Sopenharmony_ci#============================================================================
2491cb0ef41Sopenharmony_ci# Unit Tests
2501cb0ef41Sopenharmony_ci#============================================================================
2511cb0ef41Sopenharmony_ciif (BUILD_UNITTESTS)
2521cb0ef41Sopenharmony_ci    include (ExternalProject)
2531cb0ef41Sopenharmony_ci    set_directory_properties(PROPERTIES EP_PREFIX ${CMAKE_BINARY_DIR}/third_party)
2541cb0ef41Sopenharmony_ci    ExternalProject_add(
2551cb0ef41Sopenharmony_ci        googletest
2561cb0ef41Sopenharmony_ci        GIT_REPOSITORY https://github.com/google/googletest.git
2571cb0ef41Sopenharmony_ci        GIT_TAG d1467f5813f4d363cfd11aba99c4e9fe47a85e99
2581cb0ef41Sopenharmony_ci        UPDATE_COMMAND ""
2591cb0ef41Sopenharmony_ci        INSTALL_COMMAND ""
2601cb0ef41Sopenharmony_ci        LOG_DOWNLOAD ON
2611cb0ef41Sopenharmony_ci        LOG_CONFIGURE ON
2621cb0ef41Sopenharmony_ci        LOG_BUILD ON
2631cb0ef41Sopenharmony_ci    )
2641cb0ef41Sopenharmony_ci
2651cb0ef41Sopenharmony_ci    # gtest includedir
2661cb0ef41Sopenharmony_ci    ExternalProject_Get_Property(googletest source_dir)
2671cb0ef41Sopenharmony_ci    set(GTEST_INCLUDE_DIRS
2681cb0ef41Sopenharmony_ci        ${source_dir}/googletest/include
2691cb0ef41Sopenharmony_ci        ${source_dir}/googletest/include/gtest
2701cb0ef41Sopenharmony_ci    )
2711cb0ef41Sopenharmony_ci
2721cb0ef41Sopenharmony_ci    # gtest library
2731cb0ef41Sopenharmony_ci    ExternalProject_Get_Property(googletest binary_dir)
2741cb0ef41Sopenharmony_ci    set(GTEST_LIBRARY_PATH ${binary_dir}/lib/${CMAKE_FIND_LIBRARY_PREFIXES}gtest.a)
2751cb0ef41Sopenharmony_ci    set(GTEST_LIBRARY gtest)
2761cb0ef41Sopenharmony_ci    add_library(${GTEST_LIBRARY} UNKNOWN IMPORTED)
2771cb0ef41Sopenharmony_ci    set_property(TARGET ${GTEST_LIBRARY} PROPERTY IMPORTED_LOCATION ${GTEST_LIBRARY_PATH})
2781cb0ef41Sopenharmony_ci    add_dependencies(${GTEST_LIBRARY} googletest)
2791cb0ef41Sopenharmony_ci
2801cb0ef41Sopenharmony_ci    set(UTEST_SRC
2811cb0ef41Sopenharmony_ci        ${CMAKE_CURRENT_SOURCE_DIR}/contrib/tests/infcover.cc
2821cb0ef41Sopenharmony_ci        ${CMAKE_CURRENT_SOURCE_DIR}/contrib/tests/infcover.h
2831cb0ef41Sopenharmony_ci        ${CMAKE_CURRENT_SOURCE_DIR}/contrib/tests/utils_unittest.cc
2841cb0ef41Sopenharmony_ci        ${CMAKE_CURRENT_SOURCE_DIR}/contrib/tests/standalone_test_runner.cc
2851cb0ef41Sopenharmony_ci        ${CMAKE_CURRENT_SOURCE_DIR}/google/compression_utils_portable.cc
2861cb0ef41Sopenharmony_ci    )
2871cb0ef41Sopenharmony_ci
2881cb0ef41Sopenharmony_ci    add_compile_definitions(CMAKE_STANDALONE_UNITTESTS)
2891cb0ef41Sopenharmony_ci
2901cb0ef41Sopenharmony_ci    add_executable(zlib_unittests ${UTEST_SRC})
2911cb0ef41Sopenharmony_ci    target_include_directories(zlib_unittests PUBLIC ${GTEST_INCLUDE_DIRS})
2921cb0ef41Sopenharmony_ci    target_include_directories(zlib_unittests PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/google)
2931cb0ef41Sopenharmony_ci
2941cb0ef41Sopenharmony_ci    target_link_libraries(zlib_unittests ${GTEST_LIBRARY})
2951cb0ef41Sopenharmony_ci    target_link_libraries(zlib_unittests zlib)
2961cb0ef41Sopenharmony_ci    # Needed by gtest
2971cb0ef41Sopenharmony_ci    target_link_libraries(zlib_unittests pthread)
2981cb0ef41Sopenharmony_ciendif()
2991cb0ef41Sopenharmony_ci
3001cb0ef41Sopenharmony_ci#============================================================================
3011cb0ef41Sopenharmony_ci# Minigzip tool
3021cb0ef41Sopenharmony_ci#============================================================================
3031cb0ef41Sopenharmony_ciadd_executable(minizip_bin contrib/minizip/minizip.c contrib/minizip/ioapi.c
3041cb0ef41Sopenharmony_cicontrib/minizip/ioapi.h contrib/minizip/unzip.c
3051cb0ef41Sopenharmony_cicontrib/minizip/unzip.h contrib/minizip/zip.c contrib/minizip/zip.h
3061cb0ef41Sopenharmony_ci)
3071cb0ef41Sopenharmony_citarget_link_libraries(minizip_bin zlib)
308