blob: df6f5a7e69b26bebf30551e50e6d4867b6e564e4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
cmake_minimum_required(VERSION 3.14...4.2.1)
include(FetchContent)
if(NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 11)
endif()
if(NOT DEFINED CMAKE_CXX_STANDARD_REQUIRED)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
endif()
if(NOT DEFINED CMAKE_CXX_EXTENSIONS)
set(CMAKE_CXX_EXTENSIONS ON)
endif()
# Search for Google benchmark package
find_package(benchmark QUIET)
if(NOT benchmark_FOUND)
# Fetch google benchmark source code from official repository
set(BENCHMARK_ENABLE_TESTING OFF)
# Allow specifying alternative Google benchmark repository
if(NOT DEFINED GBENCHMARK_REPOSITORY)
set(GBENCHMARK_REPOSITORY https://github.com/google/benchmark.git)
endif()
if(NOT DEFINED GBENCHMARK_TAG)
set(GBENCHMARK_TAG v1.9.4)
endif()
FetchContent_Declare(benchmark
GIT_REPOSITORY ${GBENCHMARK_REPOSITORY}
GIT_TAG ${GBENCHMARK_TAG}
${ZNG_FetchContent_Declare_EXCLUDE_FROM_ALL})
ZNG_FetchContent_MakeAvailable(benchmark)
endif()
# Public API benchmarks
set(BENCH_PUBLIC_SRCS
benchmark_compress.cc
benchmark_inflate.cc
benchmark_uncompress.cc
benchmark_main.cc
)
# Internal benchmarks
set(BENCH_INTERNAL_SRCS
benchmark_adler32.cc
benchmark_adler32_copy.cc
benchmark_compare256.cc
benchmark_compare256_rle.cc
benchmark_crc32.cc
benchmark_crc32_copy.cc
benchmark_deflate.cc
benchmark_insert_string.cc
benchmark_slidehash.cc
)
add_executable(benchmark_zlib ${BENCH_PUBLIC_SRCS})
target_compile_definitions(benchmark_zlib PRIVATE -DBENCHMARK_STATIC_DEFINE)
target_include_directories(benchmark_zlib PRIVATE
${PROJECT_SOURCE_DIR}
${PROJECT_BINARY_DIR}
${benchmark_SOURCE_DIR}/benchmark/include)
target_link_libraries(benchmark_zlib benchmark::benchmark)
if(ZLIB_LIBRARY)
target_link_libraries(benchmark_zlib ${ZLIB_LIBRARY})
else()
target_sources(benchmark_zlib PRIVATE ${BENCH_INTERNAL_SRCS})
target_link_libraries(benchmark_zlib zlib-ng-static)
endif()
if(WIN32)
target_link_libraries(benchmark_zlib shlwapi)
endif()
add_test(NAME benchmark_zlib
COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} $<TARGET_FILE:benchmark_zlib> "--benchmark_min_time=0")
if(WITH_BENCHMARK_APPS)
option(BUILD_ALT_BENCH "Link against alternative zlib implementation" OFF)
# Search for libpng package
find_package(PNG QUIET)
if(NOT PNG_FOUND)
FetchContent_Declare(PNG
GIT_REPOSITORY https://github.com/glennrp/libpng.git
${ZNG_FetchContent_Declare_EXCLUDE_FROM_ALL})
ZNG_FetchContent_MakeAvailable(PNG)
set(PNG_INCLUDE_DIR ${png_SOURCE_DIR})
endif()
set(BENCH_APP_SRCS
benchmark_png_encode.cc
benchmark_png_decode.cc
benchmark_main.cc
)
add_executable(benchmark_zlib_apps ${BENCH_APP_SRCS})
if(DEFINED BUILD_ALT_BENCH)
set(ZLIB_ALT_LIB "libz.a" CACHE FILEPATH "Optional alternative zlib implementation (defaults to stock zlib)")
add_executable(benchmark_zlib_apps_alt ${BENCH_APP_SRCS})
target_link_libraries(benchmark_zlib_apps_alt libpng.a ${ZLIB_ALT_LIB} benchmark::benchmark)
target_compile_definitions(benchmark_zlib_apps_alt PRIVATE BUILD_ALT=1)
target_include_directories(benchmark_zlib_apps_alt PRIVATE
${PROJECT_SOURCE_DIR}
${PROJECT_BINARY_DIR}
${PNG_INCLUDE_DIR}
${benchmark_SOURCE_DIR}/benchmark/include)
endif()
target_include_directories(benchmark_zlib_apps PRIVATE
${PROJECT_SOURCE_DIR}
${PROJECT_BINARY_DIR}
${PNG_INCLUDE_DIR}
${benchmark_SOURCE_DIR}/benchmark/include)
# We need the static png library if we're statically linking to zlib,
# otherwise it will resolve these things in the system provided dynamic
# libraries (likely linked to stock zlib)
target_link_libraries(benchmark_zlib_apps libpng.a zlib-ng-static benchmark::benchmark)
endif()
|