| 1 |
cmake_minimum_required(VERSION 3.12) |
| 2 |
|
| 3 |
include(FetchContent) |
| 4 |
|
| 5 |
enable_language(CXX) |
| 6 |
|
| 7 |
if(NOT TARGET GTest::GTest) |
| 8 |
find_package(GTest QUIET) |
| 9 |
endif() |
| 10 |
|
| 11 |
if(NOT TARGET GTest::GTest) |
| 12 |
if (WIN32) |
| 13 |
# Prevent overriding the parent project's compiler/linker settings for Windows |
| 14 |
set(gtest_force_shared_crt ON CACHE BOOL |
| 15 |
"Use shared (DLL) run-time lib even when Google Test is built as static lib." FORCE) |
| 16 |
|
| 17 |
set(gtest_disable_pthreads ON CACHE BOOL "Disable pthreads" FORCE) |
| 18 |
endif() |
| 19 |
|
| 20 |
# Allow specifying alternative Google test repository |
| 21 |
if(NOT DEFINED GTEST_REPOSITORY) |
| 22 |
set(GTEST_REPOSITORY https://github.com/google/googletest.git) |
| 23 |
endif() |
| 24 |
if(NOT DEFINED GTEST_TAG) |
| 25 |
# Use older version of Google test to support older versions of GCC |
| 26 |
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS_EQUAL 5.3) |
| 27 |
set(GTEST_TAG release-1.10.0) |
| 28 |
else() |
| 29 |
set(GTEST_TAG v1.13.0) |
| 30 |
endif() |
| 31 |
endif() |
| 32 |
|
| 33 |
# Fetch Google test source code from official repository |
| 34 |
FetchContent_Declare(googletest |
| 35 |
GIT_REPOSITORY ${GTEST_REPOSITORY} |
| 36 |
GIT_TAG ${GTEST_TAG}) |
| 37 |
|
| 38 |
FetchContent_GetProperties(googletest) |
| 39 |
if(NOT googletest_POPULATED) |
| 40 |
FetchContent_Populate(googletest) |
| 41 |
add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR} EXCLUDE_FROM_ALL) |
| 42 |
endif() |
| 43 |
add_library(GTest::GTest ALIAS gtest) |
| 44 |
endif() |
| 45 |
|
| 46 |
set(TEST_SRCS |
| 47 |
test_crypt.cc |
| 48 |
test_encoding.cc |
| 49 |
test_path.cc |
| 50 |
test_stream.cc |
| 51 |
test_stream_crypt.cc |
| 52 |
) |
| 53 |
|
| 54 |
if(NOT MZ_COMPRESS_ONLY AND NOT MZ_DECOMPRESS_ONLY) |
| 55 |
if(MZ_COMPAT) |
| 56 |
list(APPEND TEST_SRCS test_compat.cc) |
| 57 |
endif() |
| 58 |
list(APPEND TEST_SRCS test_stream_compress.cc) |
| 59 |
endif() |
| 60 |
|
| 61 |
if(MSVC) |
| 62 |
list(APPEND TEST_SRCS test_file.cc) |
| 63 |
endif() |
| 64 |
|
| 65 |
add_executable(gtest_minizip test_main.cc ${TEST_SRCS}) |
| 66 |
target_compile_definitions(gtest_minizip PRIVATE ${STDLIB_DEF} ${MINIZIP_DEF}) |
| 67 |
target_include_directories(gtest_minizip PRIVATE |
| 68 |
${CMAKE_SOURCE_DIR} |
| 69 |
${CMAKE_BINARY_DIR}) |
| 70 |
|
| 71 |
target_link_libraries(gtest_minizip MINIZIP::minizip GTest::GTest) |
| 72 |
|
| 73 |
if(MSVC) |
| 74 |
set_target_properties(gtest_minizip PROPERTIES |
| 75 |
VS_DEBUGGER_WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) |
| 76 |
endif() |
| 77 |
|
| 78 |
add_test(NAME gtest_minizip |
| 79 |
COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} $<TARGET_FILE:gtest_minizip> |
| 80 |
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) |