forked from DanBloomberg/leptonica
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
279 lines (243 loc) · 9.32 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
#
# leptonica
#
###############################################################################
#
# cmake settings
#
###############################################################################
cmake_minimum_required(VERSION 2.8.11)
cmake_policy(SET CMP0054 NEW)
# In-source builds are disabled.
if ("${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}")
message(FATAL_ERROR
"CMake generation is not possible within the source directory!"
"\n Remove the CMakeCache.txt file and try again from another folder, e.g.:"
"\n "
"\n rm CMakeCache.txt"
"\n mkdir build"
"\n cd build"
"\n cmake .."
)
endif()
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_CURRENT_SOURCE_DIR}/cmake")
set(EXECUTABLE_OUTPUT_PATH "${CMAKE_CURRENT_BINARY_DIR}/bin")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${EXECUTABLE_OUTPUT_PATH}")
# Use solution folders.
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "CMake Targets")
###############################################################################
#
# project settings
#
###############################################################################
project(leptonica C CXX)
set(VERSION_MAJOR 1)
set(VERSION_MINOR 80)
set(VERSION_PATCH 0)
set(VERSION_PLAIN ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
set(MINIMUM_WEBPMUX_VERSION 0.5.0)
option(BUILD_PROG "Build utility programs" OFF)
if (WIN32)
option(SW_BUILD "Build with sw" ON)
else()
option(SW_BUILD "Build with sw" OFF)
endif()
if(UNIX)
option(SYM_LINK "Create symlink leptonica -> lept on UNIX" OFF)
endif()
if(NOT SW_BUILD)
find_package(GIF)
find_package(JPEG)
find_package(PNG)
find_package(TIFF)
find_package(ZLIB)
find_package(PkgConfig)
if (PKG_CONFIG_FOUND)
pkg_check_modules(WEBP libwebp QUIET)
pkg_check_modules(WEBPMUX libwebpmux>=${MINIMUM_WEBPMUX_VERSION} QUIET)
pkg_check_modules(JP2K libopenjp2>=2.0 QUIET)
endif()
if(NOT WEBP)
find_path(WEBP_INCLUDE_DIR /webp/decode.h)
find_library(WEBP_LIBRARY NAMES webp)
if (WEBP_INCLUDE_DIR AND WEBP_LIBRARY)
set(WEBP 1)
set(WEBP_FOUND TRUE)
set(WEBP_LIBRARIES ${WEBP_LIBRARY})
set(WEBP_INCLUDE_DIRS ${WEBP_INCLUDE_DIR})
endif()
endif()
if(NOT WEBPMUX)
find_path(WEBPMUX_INCLUDE_DIR /webp/mux.h)
#TODO: check minimal required version
if(NOT WEBPMUX_INCLUDE_DIR)
message(STATUS "Can not find: /webp/mux.h")
endif()
if(NOT "${WEBPMUX_INCLUDE_DIR}" STREQUAL "${WEBP_INCLUDE_DIR}")
set(WEBP_INCLUDE_DIRS ${WEBP_INCLUDE_DIRS} ${WEBPMUX_INCLUDE_DIR})
endif()
find_library(WEBPMUX_LIBRARY NAMES webpmux)
if (WEBPMUX_INCLUDE_DIR AND WEBPMUX_LIBRARY)
set(WEBPMUX 1)
set(HAVE_LIBWEBP_ANIM 1)
set(WEBPMUX_FOUND TRUE)
set(WEBP_LIBRARIES ${WEBP_LIBRARIES} ${WEBPMUX_LIBRARY})
endif()
endif()
if(NOT JP2K)
find_path(JP2K_INCLUDE_DIR /openjpeg-2.3/openjpeg.h)
find_library(JP2K_LIBRARY NAMES openjp2)
if (JP2K_INCLUDE_DIR AND JP2K_LIBRARY)
set(JP2K 1)
set(JP2K_FOUND TRUE)
set(JP2K_LIBRARIES ${JP2K_LIBRARY})
set(JP2K_INCLUDE_DIRS ${JP2K_INCLUDE_DIR})
set(HAVE_LIBJP2K 1)
endif()
endif()
else() # SW_BUILD=ON
find_package(SW REQUIRED)
sw_add_package(
org.sw.demo.gif
org.sw.demo.jpeg
org.sw.demo.glennrp.png
org.sw.demo.tiff
org.sw.demo.webmproject.webp
org.sw.demo.uclouvain.openjpeg.openjp2
)
sw_execute()
add_definitions(
-DHAVE_LIBGIF=1
-DHAVE_LIBJPEG=1
-DHAVE_LIBPNG=1
-DHAVE_LIBTIFF=1
-DHAVE_LIBWEBP=1
-DHAVE_LIBWEBP_ANIM=1
-DHAVE_LIBZ=1
-DHAVE_LIBJP2K=1
-DLIBJP2K_HEADER="openjpeg.h"
)
endif()
###############################################################################
#
# compiler and linker
#
###############################################################################
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CLANG 1)
endif()
# Set a default build type if none was specified
if(NOT CMAKE_BUILD_TYPE)
message(STATUS "Setting build type to 'Release' as none was specified.")
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release")
else()
message("CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}")
endif()
include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
macro(CHECK_CCXX_COMPILER_FLAG _FLAG _RESULT)
check_c_compiler_flag(${_FLAG} C_HAS${_RESULT})
check_cxx_compiler_flag(${_FLAG} CXX_HAS${_RESULT})
endmacro()
if (MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
add_compile_options("$<$<CONFIG:Release>:/W1;/Ox>")
add_compile_options("$<$<CONFIG:Debug>:/W4;/DDEBUG>")
if (NOT CLANG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
endif()
else()
if (CMAKE_BUILD_TYPE MATCHES "[Dd][Ee][Bb][Uu][Gg]")
# Enable warnings and Optimize for Debugging
foreach(FLAG -Wall -Wextra -Werror=format-security -pedantic -Og -g3 "-fdebug-prefix-map=${CMAKE_SOURCE_DIR}=.")
string(REGEX REPLACE "[^A-Za-z0-9]" "_" flag_var "${FLAG}")
check_ccxx_compiler_flag(${FLAG} ${flag_var})
if(C_HAS${flag_var})
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${FLAG}")
endif()
if(CXX_HAS${flag_var})
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${FLAG}")
endif()
endforeach()
add_definitions(-DDEBUG)
endif()
endif()
###############################################################################
#
# configure
#
###############################################################################
set(AUTOCONFIG_SRC ${CMAKE_CURRENT_BINARY_DIR}/config_auto.h.in)
set(AUTOCONFIG ${CMAKE_CURRENT_BINARY_DIR}/src/config_auto.h)
set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} "${CMAKE_PREFIX_PATH}/include" "${CMAKE_INSTALL_PREFIX}/include")
include(Configure)
configure_file(${AUTOCONFIG_SRC} ${AUTOCONFIG} @ONLY)
set(INCLUDE_DIR "${CMAKE_INSTALL_PREFIX}/include" "${CMAKE_INSTALL_PREFIX}/include/leptonica")
###############################################################################
#
# Show summary
#
###############################################################################
message( STATUS )
message( STATUS "General configuration for Leptonica ${VERSION_PLAIN}")
message( STATUS "--------------------------------------------------------")
message( STATUS "Build type: ${CMAKE_BUILD_TYPE}")
message( STATUS "Compiler: ${CMAKE_C_COMPILER_ID}")
message( STATUS "C compiler options: ${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE_UP}} ${CMAKE_C_FLAGS}")
message( STATUS "Linker options: ${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS_${CMAKE_BUILD_TYPE_UP}}")
message( STATUS "Install directory: ${CMAKE_INSTALL_PREFIX}")
message( STATUS )
message( STATUS "Build with sw [SW_BUILD]: ${SW_BUILD}")
message( STATUS "Build utility programs [BUILD_PROG]: ${BUILD_PROG}")
if(NOT SW_BUILD)
message( STATUS "Used ZLIB library: ${ZLIB_LIBRARIES}")
message( STATUS "Used PNG library: ${PNG_LIBRARIES}")
message( STATUS "Used JPEG library: ${JPEG_LIBRARIES}")
message( STATUS "Used JP2K library: ${JP2K_LIBRARIES}")
message( STATUS "Used TIFF library: ${TIFF_LIBRARIES}")
message( STATUS "Used GIF library: ${GIF_LIBRARIES}")
message( STATUS "Used WEBP library: ${WEBP_LIBRARIES}")
endif()
message( STATUS "--------------------------------------------------------")
message( STATUS )
###############################################################################
#
# build
#
###############################################################################
add_definitions(-DHAVE_CONFIG_H)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/src)
if (BUILD_PROG)
add_subdirectory(prog)
endif()
add_subdirectory(src)
get_target_property(leptonica_NAME leptonica NAME)
get_target_property(leptonica_VERSION leptonica VERSION)
get_target_property(leptonica_OUTPUT_NAME leptonica OUTPUT_NAME)
configure_file(lept.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/lept.pc @ONLY)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/LeptonicaConfig-version.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/LeptonicaConfig-version.cmake @ONLY)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/LeptonicaConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/LeptonicaConfig.cmake @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/lept.pc DESTINATION lib/pkgconfig)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/LeptonicaConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/LeptonicaConfig-version.cmake
DESTINATION cmake)
########################################
# uninstall target
########################################
if(NOT TARGET uninstall)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
endif()
###############################################################################