-
Notifications
You must be signed in to change notification settings - Fork 50
/
CMakeLists.txt
394 lines (328 loc) · 11.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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
# (c)2015-2024, Cris Luengo, Wouter Caarls
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# CMakeLists file for DIPlib 3
cmake_minimum_required(VERSION 3.12...3.28)
project(DIPlib)
# The version number and latest copyright year. Update these values here, they're used all throughout the project.
set(PROJECT_VERSION_MAJOR "3")
set(PROJECT_VERSION_MINOR "5")
set(PROJECT_VERSION_PATCH "1")
set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
set(DIP_COPYRIGHT_YEAR "2024")
# Debug or Release?
if(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
# Static or shared?
set(DIP_SHARED_LIBRARY ON CACHE BOOL "Build a shared library (off for static library)")
set(BUILD_SHARED_LIBS ${DIP_SHARED_LIBRARY})
# Installation path
set(CMAKE_INSTALL_PREFIX "${CMAKE_BUILD_TYPE}" CACHE PATH "Installation directory")
set(DOCUMENTATION_OUTPUT share/doc/DIPlib)
set(DIPIMAGE_INSTALL_PATH share/DIPimage)
set(RUNTIME_DESTINATION bin)
if(WIN32)
set(LIBRARY_DESTINATION bin)
else()
set(LIBRARY_DESTINATION lib)
endif()
set(ARCHIVE_DESTINATION lib)
set(DIP_DESTINATIONS
RUNTIME DESTINATION ${RUNTIME_DESTINATION}
LIBRARY DESTINATION ${LIBRARY_DESTINATION}
ARCHIVE DESTINATION ${ARCHIVE_DESTINATION})
# RPATH
#set(CMAKE_MACOSX_RPATH 1) # This is the default
#set(CMAKE_SKIP_BUILD_RPATH 0)
set(CMAKE_BUILD_WITH_INSTALL_RPATH 1) # Prevent relinking when installing
#set(CMAKE_INSTALL_RPATH_USE_LINK_PATH 1)
# Extend CMake module path
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/tools")
# OpenMP
find_package(OpenMP)
if(OpenMP_CXX_FOUND OR OPENMP_FOUND) # OPENMP_FOUND for CMake <= 3.8
set(DIP_ENABLE_MULTITHREADING ON CACHE BOOL "Enable multithreading support")
endif()
include(${CMAKE_CURRENT_LIST_DIR}/tools/compiler_flags.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/tools/update_deps_file.cmake)
### DIPlib library
add_subdirectory(src)
### DIPjavaio
find_package(Java COMPONENTS Development)
unset(DIP_JAVAIO_INTERFACES)
if(JAVA_FOUND)
# Set JAVA_HOME so that the JNI found is from the same JDK as the Java package
get_filename_component(JAVA_HOME "${Java_JAVAC_EXECUTABLE}" DIRECTORY) # strip off /javac
get_filename_component(JAVA_HOME "${JAVA_HOME}" DIRECTORY) # strip off /bin
find_package(JNI)
if(JNI_FOUND)
set(DIP_BUILD_JAVAIO ON CACHE BOOL "Build the javaio module")
include(UseJava)
list(APPEND DIP_JAVAIO_INTERFACES "Bio-Formats")
endif()
set(DIP_JAVA_VERSION "1.8" CACHE STRING "Java version to target when building DIPviewer Java bindings and DIPjavaio.")
# MATLAB R2013b--R2017a use Java SDK 1.7, R2017b-- use SDK 1.8.
set(CMAKE_JAVA_COMPILE_FLAGS -target ${DIP_JAVA_VERSION} -source ${DIP_JAVA_VERSION})
endif()
if(DIP_BUILD_JAVAIO)
add_subdirectory(javaio)
endif()
### DIPviewer
# OpenGL, FreeGLUT, GLFW
set(OpenGL_GL_PREFERENCE LEGACY)
find_package(OpenGL)
if(APPLE)
set(DIP_FIND_FREEGLUT OFF CACHE BOOL "Try to find FreeGLUT library")
else()
set(DIP_FIND_FREEGLUT ON CACHE BOOL "Try to find FreeGLUT library")
endif()
set(DIP_FIND_GLFW ON CACHE BOOL "Try to find GLFW library")
if (DIP_FIND_FREEGLUT)
find_package(FreeGLUT)
endif()
if(FREEGLUT_FOUND)
list(APPEND DIP_VIEWER_MANAGERS "FreeGLUT")
set(FREEGLUT_STATIC OFF CACHE BOOL "Link to static FreeGLUT library")
endif()
if (DIP_FIND_GLFW)
find_package(GLFW)
endif()
if(GLFW_FOUND)
list(APPEND DIP_VIEWER_MANAGERS "GLFW")
endif()
if(OPENGL_FOUND AND (FREEGLUT_FOUND OR GLFW_FOUND))
set(DIP_BUILD_DIPVIEWER ON CACHE BOOL "Build the viewer module")
else()
set(DIP_BUILD_DIPVIEWER OFF CACHE BOOL "Build the viewer module")
endif()
if(DIP_BUILD_DIPVIEWER)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
add_subdirectory(viewer)
endif()
### PyDIP module for Python
if(DEFINED PYTHON_EXECUTABLE AND NOT DEFINED Python_EXECUTABLE)
message(WARNING "PYTHON_EXECUTABLE is deprecated, use Python_EXECUTABLE instead.")
set(Python_EXECUTABLE "${PYTHON_EXECUTABLE}")
endif()
find_package(Python 3.6 COMPONENTS Interpreter Development.Module)
if(Python_Development.Module_FOUND)
set(DIP_BUILD_PYDIP ON CACHE BOOL "Build the PyDIP Python module")
endif()
if(DIP_BUILD_PYDIP)
set(DIPlib_VERSION ${PROJECT_VERSION})
add_subdirectory(pydip)
endif()
### DIPimage toolbox for MATLAB
if(DIP_SHARED_LIBRARY)
# We will not build DIPimage without a shared DIPlib -- technically possible, but not desireable.
# (This would also require solving linker warnings because of Doctest.)
#set(MATLAB_ADDITIONAL_VERSIONS "R2018b=9.5") # You might need to add a line like this if your version of MATLAB is not recognized
find_package(Matlab COMPONENTS MAIN_PROGRAM) # NOTE! Here we use the local copy of the FindMatlab.cmake script
if(Matlab_FOUND)
set(DIP_BUILD_DIPIMAGE ON CACHE BOOL "Build the DIPimage toolbox")
endif()
endif()
if(DIP_BUILD_DIPIMAGE)
add_subdirectory(dipimage)
endif()
### Documentation
add_subdirectory(doc)
### Examples
add_subdirectory(examples EXCLUDE_FROM_ALL)
### CMake import scripts
if(DIP_SHARED_LIBRARY)
include(CMakePackageConfigHelpers)
set(ConfigPackageLocation lib/cmake/DIPlib)
export(EXPORT DIPlibTargets
FILE "${CMAKE_CURRENT_BINARY_DIR}/DIPlibTargets.cmake"
NAMESPACE DIPlib::)
install(EXPORT DIPlibTargets
FILE DIPlibTargets.cmake
NAMESPACE DIPlib::
DESTINATION ${ConfigPackageLocation})
configure_package_config_file(
tools/DIPlibConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/DIPlibConfig.cmake"
INSTALL_DESTINATION ${ConfigPackageLocation})
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/DIPlibConfigVersion.cmake"
VERSION ${DIPlib_VERSION}
COMPATIBILITY SameMajorVersion)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/DIPlibConfigVersion.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/DIPlibConfig.cmake"
DESTINATION ${ConfigPackageLocation})
endif()
### Status report
message("")
message("--------------------------------------")
message(" DIPlib CONFIGURATION REPORT")
message("")
message(" * PROJECT_VERSION: ${PROJECT_VERSION}")
message(" * DIP_COPYRIGHT_YEAR: ${DIP_COPYRIGHT_YEAR}")
message(" * C++ compiler: ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}")
if(NOT "${CMAKE_BUILD_TYPE}" STREQUAL "")
string(TOUPPER ${CMAKE_BUILD_TYPE} UPPERCASE_BUILD_TYPE)
message(" * C++ compiler flags: ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${UPPERCASE_BUILD_TYPE}}")
message(" * Build type: ${CMAKE_BUILD_TYPE}")
endif()
if(DIP_SHARED_LIBRARY)
message(" * Building shared library")
else()
message(" * Building static library")
endif()
message(" * Library installed to: ${CMAKE_INSTALL_PREFIX}/${LIBRARY_DESTINATION}")
message(" * Binaries installed to: ${CMAKE_INSTALL_PREFIX}/${RUNTIME_DESTINATION}")
if (WIN32)
message(" * Import library installed to: ${CMAKE_INSTALL_PREFIX}/${ARCHIVE_DESTINATION}")
endif()
message(" * Header files installed to: ${CMAKE_INSTALL_PREFIX}/include")
if(DOXPP_FOUND)
message(" * Documentation installed to: ${CMAKE_INSTALL_PREFIX}/${DOCUMENTATION_OUTPUT}")
else()
message(" * dox++ program not configured, no documentation can be generated")
endif()
if(DIP_ENABLE_MULTITHREADING)
message(" * Using OpenMP for multithreading")
else()
message(" * Multithreading disabled")
endif()
if(DIP_ENABLE_STACK_TRACE)
message(" * Stack trace recording enabled")
else()
message(" * Stack trace recording disabled")
endif()
if(DIP_ENABLE_ASSERT)
message(" * Asserts enabled")
else()
message(" * Asserts disabled")
endif()
if(DIP_ENABLE_UNICODE)
message(" * Unicode support enabled")
else()
message(" * Unicode support disabled")
endif()
if(HAS_128_INT)
message(" * Using 128-bit PRNG")
else()
message(" * Using 64-bit PRNG")
endif()
if(DIP_ENABLE_ICS)
if(DIP_ENABLE_ZLIB)
set(features ", with zlib")
else()
set(features ", without zlib")
endif()
message(" * ICS file IO enabled${features}")
else()
message(" * ICS file IO disabled")
endif()
if(DIP_ENABLE_TIFF)
set(features "")
if(DIP_ENABLE_ZLIB)
set(features "${features}, with zlib")
else()
set(features "${features}, without zlib")
endif()
if(DIP_ENABLE_JPEG)
set(features "${features}, with JPEG")
else()
set(features "${features}, without JPEG")
endif()
message(" * TIFF file IO enabled${features}")
else()
message(" * TIFF file IO disabled")
endif()
if(DIP_ENABLE_JPEG)
message(" * JPEG file IO enabled")
else()
message(" * JPEG file IO disabled")
endif()
if(DIP_ENABLE_PNG)
message(" * PNG file IO enabled")
else()
message(" * PNG file IO disabled")
endif()
if(DIP_ENABLE_FFTW)
message(" * Using FFTW3 (GPL)")
else()
message(" * Using PocketFFT")
endif()
if(DIP_ENABLE_FREETYPE)
message(" * Using FreeType")
else()
message(" * Not using FreeType")
endif()
if(DIP_ENABLE_DOCTEST)
message(" * Unit test code included")
else()
message(" * Unit test code excluded")
endif()
if(DIP_BUILD_DIPVIEWER)
message(" * DIPviewer module added to 'all' with window managers: ${DIP_VIEWER_MANAGERS}")
if (FREEGLUT_STATIC)
message(" * Using static FreeGLUT library")
endif()
else()
message(" * DIPviewer module not configured")
endif()
if(DIP_BUILD_JAVAIO)
message(" * DIPjavaio module added to 'all' target with interfaces: ${DIP_JAVAIO_INTERFACES}")
message(" * DIPjavaio compiled using Java version ${Java_VERSION_STRING} and targeting ${DIP_JAVA_VERSION}")
else()
message(" * DIPJavaio module not configured")
endif()
if(DIP_BUILD_PYDIP)
message(" * PyDIP module added to 'all' target")
message(" * PyDIP compiled for Python version ${Python_VERSION}")
if(DIP_PYDIP_WHEEL_INCLUDE_LIBS)
message(" * PyDIP includes libraries in binary wheel")
else()
message(" * PyDIP does not include libraries in binary wheel")
endif()
else()
message(" * PyDIP module not configured")
endif()
if(DIP_BUILD_DIPIMAGE)
message(" * DIPimage toolbox added to 'all' target")
matlab_get_release_name_from_version(${Matlab_VERSION_STRING} Matlab_RELEASE_NAME)
message(" * DIPimage toolbox compiled for MATLAB ${Matlab_RELEASE_NAME}")
if(DIP_BUILD_DIPVIEWER_JAVA)
message(" * DIPviewer Java bindings added to 'all' target, compiled using Java version ${Java_VERSION_STRING} and targeting ${DIP_JAVA_VERSION}")
else()
message(" * DIPviewer Java bindings not configured")
endif()
message(" * DIPimage toolbox installed to: ${CMAKE_INSTALL_PREFIX}/${DIPIMAGE_INSTALL_PATH}")
if(DOXPP_FOUND)
message(" * DIPimage User Manual installed to: ${CMAKE_INSTALL_PREFIX}/${DOCUMENTATION_OUTPUT}/html/dipimage_user_manual.html")
else()
message(" * DIPimage User Manual cannot be created (dox++ program not configured)")
endif()
else()
message(" * DIPimage toolbox not configured")
endif()
if(CMAKE_GENERATOR MATCHES "Unix Makefiles")
message("")
if(DIP_ENABLE_DOCTEST)
message("Next, type 'make; make check; make install'")
else()
message("Next, type 'make; make install'")
endif()
if(DOXPP_FOUND)
message("Type 'make apidoc' to build the documentation")
endif()
endif()
message("")
message("--------------------------------------")
message("")