-
Notifications
You must be signed in to change notification settings - Fork 5
/
CMakeLists.txt
218 lines (182 loc) · 5.93 KB
/
CMakeLists.txt
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
cmake_minimum_required(VERSION 3.16)
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.24")
cmake_policy(SET CMP0135 NEW)
endif()
project(wavelet_buffer VERSION 0.7.2)
option(WB_BUILD_TESTS "Enable unit tests" OFF)
option(WB_BUILD_EXAMPLES "Enable examples" OFF)
option(WB_BUILD_BENCHMARKS "Enable benchmarks" OFF)
# Conan
if(CONAN_EXPORTED)
message(STATUS "Conan exported")
else()
message(STATUS "Run conan")
list(APPEND CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR})
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR})
set(CMAKE_CURRENT_BINARY_DIR ${CMAKE_BINARY_DIR})
if(NOT EXISTS "${CMAKE_BINARY_DIR}/conan.cmake")
message(
STATUS
"Downloading conan.cmake from https://github.com/conan-io/cmake-conan"
)
file(
DOWNLOAD
"https://raw.githubusercontent.com/conan-io/cmake-conan/0.18.1/conan.cmake"
"${CMAKE_BINARY_DIR}/conan.cmake"
TLS_VERIFY ON
)
endif()
include(${CMAKE_BINARY_DIR}/conan.cmake)
conan_cmake_configure(REQUIRES
blaze/3.8
libjpeg-turbo/2.1.3
cimg/3.0.2
catch2/3.2.1
OPTIONS
cimg:enable_fftw=False
cimg:enable_jpeg=False # To avoid conflict with libjpeg-turbo
cimg:enable_openexr=False
cimg:enable_png=False
cimg:enable_tiff=False
cimg:enable_ffmpeg=False
cimg:enable_opencv=False
GENERATORS CMakeDeps
)
conan_cmake_autodetect(settings)
conan_cmake_install(PATH_OR_REFERENCE .
BUILD missing
REMOTE conancenter
SETTINGS ${settings}
)
endif()
find_package(blaze REQUIRED)
find_package(libjpeg-turbo REQUIRED)
find_package(cimg REQUIRED)
find_package(Catch2 REQUIRED)
# Create wb target
set(WB_TARGET_NAME ${PROJECT_NAME})
add_library(
${WB_TARGET_NAME}
sources/wavelet_buffer.cc
sources/wavelet_buffer_serializer.cc
sources/wavelet_utils.cc
sources/wavelet_buffer_view.cc
sources/padding.cc
sources/wavelet.cc
sources/img/wavelet_image.cc
sources/img/color_space.cc
sources/img/jpeg_codecs.cc
# Internal
sources/internal/sf_compressor.cc
sources/internal/matrix_compressor.cc
)
include(FetchContent)
fetchcontent_declare(
streamvbyte
URL https://github.com/lemire/streamvbyte/archive/refs/tags/v1.0.0.zip
URL_HASH MD5=3d1a01cfb704947fa6498944082aeed1
)
fetchcontent_declare(
fpzip
URL https://github.com/LLNL/fpzip/releases/download/1.3.0/fpzip-1.3.0.zip
URL_HASH MD5=933ed7628de406a24fe2de61c8c3356c
)
fetchcontent_makeavailable(streamvbyte)
fetchcontent_getproperties(fpzip)
if(NOT fpzip_POPULATED)
fetchcontent_populate(fpzip)
# Make subproject to use 'BUILD_SHARED_LIBS=ON' setting.
set(BUILD_SHARED_LIBS OFF CACHE INTERNAL "Build SHARED libraries")
add_subdirectory(${fpzip_SOURCE_DIR} ${fpzip_BINARY_DIR})
endif()
# Add alias
add_library(${WB_TARGET_NAME}::${WB_TARGET_NAME} ALIAS ${WB_TARGET_NAME})
# Set fPIC
set_target_properties(${WB_TARGET_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON)
set_target_properties(streamvbyte PROPERTIES POSITION_INDEPENDENT_CODE ON)
set_target_properties(fpzip PROPERTIES POSITION_INDEPENDENT_CODE ON)
# Turn off parallelization in blaze
target_compile_definitions(
${WB_TARGET_NAME}
PUBLIC BLAZE_USE_SHARED_MEMORY_PARALLELIZATION=0
)
# Set CImg options
target_compile_definitions(cimg::cimg INTERFACE cimg_display=0)
# Set compiler features
target_compile_features(${WB_TARGET_NAME} PUBLIC cxx_std_20)
set_target_properties(${WB_TARGET_NAME} PROPERTIES CXX_STANDARD_REQUIRED ON)
# target_compile_options(${WB_TARGET_NAME} PUBLIC -D_GLIBCXX_DEBUG)
# target_compile_options(sf_compressor PUBLIC -D_GLIBCXX_DEBUG)
# Include paths
target_include_directories(
${WB_TARGET_NAME}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
target_include_directories(
${WB_TARGET_NAME}
PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>/sources
)
# Link dependencies
target_link_libraries(${WB_TARGET_NAME} PRIVATE streamvbyte)
target_link_libraries(${WB_TARGET_NAME} PRIVATE fpzip)
target_link_libraries(${WB_TARGET_NAME} PRIVATE libjpeg-turbo::libjpeg-turbo)
target_link_libraries(${WB_TARGET_NAME} PRIVATE cimg::cimg)
target_link_libraries(${WB_TARGET_NAME} PUBLIC blaze::blaze)
# Catch2 installation
if(WB_BUILD_TESTS OR WB_BUILD_BENCHMARKS)
include(CTest)
include(Catch)
endif()
# Add tests
if(WB_BUILD_TESTS)
message(STATUS "Unit tests enabled")
add_subdirectory(tests)
endif()
# Add benchmarks
if(WB_BUILD_BENCHMARKS)
message(STATUS "Benchmarks enabled")
add_subdirectory(benchmarks)
endif()
# Add examples
if(WB_BUILD_EXAMPLES)
message(STATUS "Examples enabled")
add_subdirectory(examples)
endif()
# Install rules
include(GNUInstallDirs)
# Create package targets file
install(TARGETS ${WB_TARGET_NAME} streamvbyte EXPORT ${WB_TARGET_NAME}-target)
install(
EXPORT ${WB_TARGET_NAME}-target
FILE ${WB_TARGET_NAME}-targets.cmake
NAMESPACE ${WB_TARGET_NAME}::
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake
)
include(CMakePackageConfigHelpers)
# Create package config file
configure_package_config_file(
"${PROJECT_SOURCE_DIR}/cmake/${WB_TARGET_NAME}-config.cmake.in"
"${WB_TARGET_NAME}-config.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake
)
# Create package version file
write_basic_package_version_file(
${WB_TARGET_NAME}-config-version.cmake
COMPATIBILITY ExactVersion
)
# Install cmake files
install(
FILES
"${PROJECT_BINARY_DIR}/${WB_TARGET_NAME}-config.cmake"
"${PROJECT_BINARY_DIR}/${WB_TARGET_NAME}-config-version.cmake"
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake
)
# Install headers
install(
DIRECTORY ${PROJECT_SOURCE_DIR}/wavelet_buffer
TYPE INCLUDE
PATTERN "*.md"
EXCLUDE
)