forked from aous72/OpenJPH
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
294 lines (245 loc) · 12.7 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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
cmake_minimum_required(VERSION 3.11.0)
project (openjph DESCRIPTION "Open source implementation of JPH" LANGUAGES CXX)
################################################################################################
# Building OpenJPH
################################################################################################
############################################################
# Parse version file
# credit: https://stackoverflow.com/a/47084079
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/src/core/common/ojph_version.h" VERFILE)
if (NOT VERFILE)
message(FATAL_ERROR "Failed to parse ojph_version.h!")
endif()
string(REGEX MATCH "OPENJPH_VERSION_MAJOR ([0-9]*)" _ ${VERFILE})
set(OPENJPH_VERSION_MAJOR ${CMAKE_MATCH_1})
string(REGEX MATCH "OPENJPH_VERSION_MINOR ([0-9]*)" _ ${VERFILE})
set(OPENJPH_VERSION_MINOR ${CMAKE_MATCH_1})
string(REGEX MATCH "OPENJPH_VERSION_PATCH ([a-z0-9]*)" _ ${VERFILE})
set(OPENJPH_VERSION_PATCH ${CMAKE_MATCH_1})
set(OPENJPH_VERSION "${OPENJPH_VERSION_MAJOR}.${OPENJPH_VERSION_MINOR}.${OPENJPH_VERSION_PATCH}")
############################################################
option(OJPH_DISABLE_INTEL_SIMD "Disables the use of SIMD instructions and associated files" OFF)
option(OJPH_ENABLE_INTEL_AVX512 "enables the use of AVX512 SIMD instructions and associated files" ON)
option(BUILD_SHARED_LIBS "Shared Libraries" ON)
option(OJPH_ENABLE_TIFF_SUPPORT "Enables input and output support for TIFF files" ON)
option(OJPH_BUILD_TESTS "Enables building test code" OFF)
option(OJPH_BUILD_EXECUTABLES "Enables building command line executables" ON)
# This is related to how the timestamp is set for URL downloaded files.
# Set DOWNLOAD_EXTRACT_TIMESTAMP
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.24.0")
if(POLICY CMP0065)
cmake_policy(SET CMP0135 NEW)
endif()
endif()
set(CMAKE_CXX_FLAGS_ASAN
"-fsanitize=address -fno-optimize-sibling-calls -fsanitize-address-use-after-scope -fno-omit-frame-pointer -g -O1"
CACHE STRING "Flags used by the C++ compiler during AddressSanitizer builds."
FORCE)
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
message( STATUS "To use AddressSanitizer, use \"cmake .. -DCMAKE_BUILD_TYPE=asan\"" )
endif()
message(STATUS "Building ${CMAKE_BUILD_TYPE}")
set(CMAKE_CXX_STANDARD 14)
if (MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /D \"_CRT_SECURE_NO_WARNINGS\"")
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions -Wall -Wextra -Wconversion -Wunused-parameter")
endif()
if (OJPH_DISABLE_INTEL_SIMD)
if (MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D \"OJPH_DISABLE_INTEL_SIMD\"")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DOJPH_DISABLE_INTEL_SIMD")
endif()
endif()
if (OJPH_ENABLE_INTEL_AVX512)
if (MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D \"OJPH_ENABLE_INTEL_AVX512\"")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DOJPH_ENABLE_INTEL_AVX512")
endif()
endif()
if (BUILD_SHARED_LIBS AND MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D \"OJPH_BUILD_SHARED_LIBRARY\"")
endif()
if (OJPH_CODE_COVERAGE AND NOT MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
endif()
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/../bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/../bin)
include_directories(src/core/common)
include_directories(src/apps/common)
file(GLOB CODESTREAM "src/core/codestream/*.cpp" "src/core/codestream/*.h")
file(GLOB CODESTREAM_SSE "src/core/codestream/*_sse.cpp")
file(GLOB CODESTREAM_SSE2 "src/core/codestream/*_sse2.cpp")
file(GLOB CODESTREAM_AVX "src/core/codestream/*_avx.cpp")
file(GLOB CODESTREAM_AVX2 "src/core/codestream/*_avx2.cpp")
file(GLOB CODESTREAM_WASM "src/core/codestream/*_wasm.cpp")
file(GLOB CODING "src/core/coding/*.cpp" "src/core/coding/*.h")
file(GLOB CODING_SSSE3 "src/core/coding/*_ssse3.cpp")
file(GLOB CODING_WASM "src/core/coding/*_wasm.cpp")
file(GLOB CODING_AVX512 "src/core/coding/*_avx512.cpp")
file(GLOB COMMON "src/core/common/*.h")
file(GLOB OTHERS "src/core/others/*.cpp")
file(GLOB TRANSFORM "src/core/transform/*.cpp" "src/core/transform/*.h")
file(GLOB TRANSFORM_SSE "src/core/transform/*_sse.cpp")
file(GLOB TRANSFORM_SSE2 "src/core/transform/*_sse2.cpp")
file(GLOB TRANSFORM_AVX "src/core/transform/*_avx.cpp")
file(GLOB TRANSFORM_AVX2 "src/core/transform/*_avx2.cpp")
file(GLOB TRANSFORM_WASM "src/core/transform/*_wasm.cpp")
list(REMOVE_ITEM CODESTREAM ${CODESTREAM_SSE} ${CODESTREAM_SSE2} ${CODESTREAM_AVX} ${CODESTREAM_AVX2} ${CODESTREAM_WASM})
list(REMOVE_ITEM CODING ${CODING_SSSE3} ${CODING_WASM} ${CODING_AVX512})
list(REMOVE_ITEM TRANSFORM ${TRANSFORM_SSE} ${TRANSFORM_SSE2} ${TRANSFORM_AVX} ${TRANSFORM_AVX2} ${TRANSFORM_WASM})
list(APPEND SOURCES ${CODESTREAM} ${CODING} ${COMMON} ${OTHERS} ${TRANSFORM})
source_group("codestream" FILES ${CODESTREAM})
source_group("coding" FILES ${CODING})
source_group("common" FILES ${COMMON})
source_group("others" FILES ${OTHERS})
source_group("transform" FILES ${TRANSFORM})
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/src/pkg-config.pc.cmake"
"${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${PROJECT_NAME}.pc"
)
if(EMSCRIPTEN)
set(OJPH_DISABLE_INTEL_SIMD ON)
set(BUILD_SHARED_LIBS OFF)
set(OJPH_ENABLE_TIFF_SUPPORT OFF)
add_compile_options(-std=c++11 -O3 -fexceptions -DOJPH_DISABLE_INTEL_SIMD)
add_library(openjph ${SOURCES})
add_library(openjphsimd ${SOURCES} ${CODESTREAM_WASM} ${CODING_WASM} ${TRANSFORM_WASM})
target_include_directories(openjph PUBLIC src/core/common)
target_include_directories(openjphsimd PUBLIC src/core/common)
target_compile_options(openjphsimd PRIVATE -DOJPH_ENABLE_WASM_SIMD -msimd128)
source_group("codestream" FILES ${CODESTREAM_WASM})
source_group("coding" FILES ${CODING_WASM})
source_group("transform" FILES ${TRANSFORM_WASM})
elseif(NOT OJPH_DISABLE_INTEL_SIMD)
add_library(openjph ${SOURCES} ${CODESTREAM_SSE} ${CODESTREAM_SSE2} ${CODESTREAM_AVX} ${CODESTREAM_AVX2} ${CODING_SSSE3} ${TRANSFORM_SSE} ${TRANSFORM_SSE2} ${TRANSFORM_AVX} ${TRANSFORM_AVX2})
source_group("codestream" FILES ${CODESTREAM_SSE} ${CODESTREAM_SSE2} ${CODESTREAM_AVX} ${CODESTREAM_AVX2})
source_group("coding" FILES ${CODING_SSSE3})
source_group("transform" FILES ${TRANSFORM_SSE} ${TRANSFORM_SSE2} ${TRANSFORM_AVX} ${TRANSFORM_AVX2})
if (OJPH_ENABLE_INTEL_AVX512)
target_sources(openjph PRIVATE ${CODING_AVX512})
source_group("coding" FILES ${CODING_AVX512})
endif()
else()
add_library(openjph ${SOURCES})
endif()
target_include_directories(openjph PUBLIC src/core/common)
target_compile_definitions(openjph PUBLIC _FILE_OFFSET_BITS=64)
if (OPENJPH_VERSION)
if (WIN32)
set_target_properties(openjph
PROPERTIES
OUTPUT_NAME "openjph.${OPENJPH_VERSION_MAJOR}.${OPENJPH_VERSION_MINOR}")
else()
set_target_properties(openjph
PROPERTIES
SOVERSION "${OPENJPH_VERSION_MAJOR}.${OPENJPH_VERSION_MINOR}"
VERSION "${OPENJPH_VERSION}")
endif()
else()
message(FATAL_ERROR "OPENJPH_VERSION is not set")
endif()
if (MSVC)
set_source_files_properties(src/core/codestream/ojph_codestream_avx.cpp PROPERTIES COMPILE_FLAGS "/arch:AVX")
set_source_files_properties(src/core/codestream/ojph_codestream_avx2.cpp PROPERTIES COMPILE_FLAGS "/arch:AVX2")
set_source_files_properties(src/core/coding/ojph_block_encoder_avx512.cpp PROPERTIES COMPILE_FLAGS "/arch:AVX512")
set_source_files_properties(src/core/transform/ojph_colour_avx.cpp PROPERTIES COMPILE_FLAGS "/arch:AVX")
set_source_files_properties(src/core/transform/ojph_colour_avx2.cpp PROPERTIES COMPILE_FLAGS "/arch:AVX2")
set_source_files_properties(src/core/transform/ojph_transform_avx.cpp PROPERTIES COMPILE_FLAGS "/arch:AVX")
set_source_files_properties(src/core/transform/ojph_transform_avx2.cpp PROPERTIES COMPILE_FLAGS "/arch:AVX2")
else()
set_source_files_properties(src/core/codestream/ojph_codestream_avx.cpp PROPERTIES COMPILE_FLAGS -mavx)
set_source_files_properties(src/core/codestream/ojph_codestream_avx2.cpp PROPERTIES COMPILE_FLAGS -mavx2)
set_source_files_properties(src/core/coding/ojph_block_decoder_ssse3.cpp PROPERTIES COMPILE_FLAGS -mssse3)
set_source_files_properties(src/core/coding/ojph_block_encoder_avx512.cpp PROPERTIES COMPILE_FLAGS -mavx512cd)
set_source_files_properties(src/core/transform/ojph_colour_avx.cpp PROPERTIES COMPILE_FLAGS -mavx)
set_source_files_properties(src/core/transform/ojph_colour_avx2.cpp PROPERTIES COMPILE_FLAGS -mavx2)
set_source_files_properties(src/core/transform/ojph_transform_avx.cpp PROPERTIES COMPILE_FLAGS -mavx)
set_source_files_properties(src/core/transform/ojph_transform_avx2.cpp PROPERTIES COMPILE_FLAGS -mavx2)
endif()
############################################################
if( OJPH_ENABLE_TIFF_SUPPORT )
if( WIN32 )
set(TIFF_INCLUDE_DIR "C:\\Program Files\\tiff\\include" CACHE PATH "the directory containing the TIFF headers")
set(TIFF_LIBRARY_DEBUG "C:\\Program Files\\tiff\\lib\\tiffd.lib" CACHE FILEPATH "the path to the TIFF library for debug configurations")
set(TIFF_LIBRARY_RELEASE "C:\\Program Files\\tiff\\lib\\tiff.lib" CACHE FILEPATH "the path to the TIFF library for release configurations")
set(TIFFXX_LIBRARY_DEBUG "C:\\Program Files\\tiff\\lib\\tiffxxd.lib" CACHE FILEPATH "the path to the TIFFXX library for debug configurations")
set(TIFFXX_LIBRARY_RELEASE "C:\\Program Files\\tiff\\lib\\tiffxx.lib" CACHE FILEPATH "the path to the TIFFXX library for release configurations")
message( STATUS "WIN32 detected: Setting CMakeCache TIFF values as follows, use CMake-gui Advanced to modify them" )
message( STATUS " TIFF_INCLUDE_DIR : \"${TIFF_INCLUDE_DIR}\" " )
message( STATUS " TIFF_LIBRARY_DEBUG : \"${TIFF_LIBRARY_DEBUG}\" " )
message( STATUS " TIFF_LIBRARY_RELEASE : \"${TIFF_LIBRARY_RELEASE}\" " )
message( STATUS " TIFFXX_LIBRARY_DEBUG : \"${TIFFXX_LIBRARY_DEBUG}\" " )
message( STATUS " TIFFXX_LIBRARY_RELEASE : \"${TIFFXX_LIBRARY_RELEASE}\" " )
endif( WIN32 )
FIND_PACKAGE( TIFF )
if( TIFF_FOUND )
set(USE_TIFF TRUE CACHE BOOL "Add TIFF support")
include_directories( ${TIFF_INCLUDE_DIR} )
if (MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D \"OJPH_ENABLE_TIFF_SUPPORT\"")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DOJPH_ENABLE_TIFF_SUPPORT")
endif()
#include_directories(${CMAKE_BINARY_DIR}/libtiff) # for tiffconf.h on windows
endif( TIFF_FOUND )
endif()
############################################################
set(OJPH_EXPAND src/apps/ojph_expand/ojph_expand.cpp src/apps/others/ojph_img_io.cpp)
set(OJPH_COMPRESS src/apps/ojph_compress/ojph_compress.cpp src/apps/others/ojph_img_io.cpp)
set(OJPH_IMG_IO_SSE41 src/apps/others/ojph_img_io_sse41.cpp)
set(OJPH_IMG_IO_AVX2 src/apps/others/ojph_img_io_avx2.cpp)
if(NOT OJPH_DISABLE_INTEL_SIMD)
list(APPEND OJPH_EXPAND ${OJPH_IMG_IO_SSE41})
list(APPEND OJPH_EXPAND ${OJPH_IMG_IO_AVX2})
list(APPEND OJPH_COMPRESS ${OJPH_IMG_IO_SSE41})
list(APPEND OJPH_COMPRESS ${OJPH_IMG_IO_AVX2})
endif()
if(OJPH_BUILD_EXECUTABLES)
add_executable(ojph_expand ${OJPH_EXPAND})
add_executable(ojph_compress ${OJPH_COMPRESS})
endif()
if (MSVC)
set_source_files_properties(src/apps/others/ojph_img_io_avx2.cpp PROPERTIES COMPILE_FLAGS "/arch:AVX2")
else()
set_source_files_properties(src/apps/others/ojph_img_io_sse41.cpp PROPERTIES COMPILE_FLAGS -msse4.1)
set_source_files_properties(src/apps/others/ojph_img_io_avx2.cpp PROPERTIES COMPILE_FLAGS -mavx2)
endif()
if(OJPH_BUILD_EXECUTABLES)
if( USE_TIFF )
target_link_libraries(ojph_expand PUBLIC openjph ${TIFF_LIBRARIES})
target_link_libraries(ojph_compress PUBLIC openjph ${TIFF_LIBRARIES})
else()
target_link_libraries(ojph_expand PUBLIC openjph)
target_link_libraries(ojph_compress PUBLIC openjph)
endif()
endif()
################################################################################################
# Install
################################################################################################
if(OJPH_BUILD_EXECUTABLES)
install(TARGETS ojph_expand
DESTINATION bin)
install(TARGETS ojph_compress
DESTINATION bin)
endif()
include(GNUInstallDirs)
install(TARGETS openjph LIBRARY
DESTINATION ${CMAKE_INSTALL_LIBDIR})
install (DIRECTORY src/core/common/
DESTINATION include/openjph
FILES_MATCHING
PATTERN "*.h")
install(FILES "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${PROJECT_NAME}.pc"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
################################################################################################
# Testing (OJPH_BUILD_TESTS)
################################################################################################
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND OJPH_BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif()