-
Notifications
You must be signed in to change notification settings - Fork 12
/
CMakeLists.txt
403 lines (326 loc) · 16.3 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
395
396
397
398
399
400
401
402
403
set(PLUGIN_NAME ITKImageProcessing)
set(${PLUGIN_NAME}_VERSION "1.0")
set(${PLUGIN_NAME}_VERSION_MAJOR "2")
set(${PLUGIN_NAME}_VERSION_MINOR "0")
get_filename_component(${PLUGIN_NAME}_SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}" ABSOLUTE)
set(ITKImageProcessing_BINARY_DIR "${PROJECT_BINARY_DIR}/Plugins/${PLUGIN_NAME}")
option(ITKImageProcessing_LeanAndMean "Only compile the Reader and Writers, All other filters are disabled" OFF)
# --------------------------------------------------------------------
# Look for ITK as it is required.
if(NOT SIMPL_USE_ITK)
set(PluginNumFilters "-100")
set(DREAM3D_ENABLE_${PLUGIN_NAME} "OFF")
message(STATUS "${PLUGIN_NAME}: SIMPL_USE_ITK=OFF, ${PLUGIN_NAME} is disabled.")
return()
endif()
# --------------------------------------------------------------------
# Look for Qt 5 as we need it for the plugin GUI to be generated
if(NOT Qt5Core_FOUND)
message(FATAL_ERROR "Qt 5 is Needed for plugin ${PLUGIN_NAME}Plugin.")
endif()
set(CMP_TOP_HEADER_FILE "")
set(VERSION_HEADER_FILE_NAME "${PLUGIN_NAME}Version.h")
set(VERSION_SOURCE_FILE_NAME "${PLUGIN_NAME}Version.cpp")
cmpRevisionString( GENERATED_HEADER_FILE_PATH "${VERSION_HEADER_FILE_NAME}"
GENERATED_SOURCE_FILE_PATH "${VERSION_SOURCE_FILE_NAME}"
NAMESPACE "${PLUGIN_NAME}"
PROJECT_NAME "${PLUGIN_NAME}"
EXPORT_MACRO "")
set(${PLUGIN_NAME}_Project_SRCS "")
include(${SIMPLProj_SOURCE_DIR}/Source/SIMPLib/SIMPLibMacros.cmake)
# --------------------------------------------------------------------
# find ITK so that we can figure out the version of ITK the user has selected
# Does not register IO factories. It will be done by each plugin that needs it.
set(ITK_NO_IO_FACTORY_REGISTER_MANAGER TRUE)
find_package(ITK REQUIRED)
#message(STATUS "ITK_VERSION_MAJOR: ${ITK_VERSION_MAJOR}")
option(ITKImageProcessing_ENABLE_ITK_MONTAGE "Enable ITK Montage module" ON)
option(ITKImageProcessing_ENABLE_ITK_TOTAL_VARIATION "Enable ITK TotalVariation module" ON)
## YOU MUST INCLUDE THIS FILE TO USE ITK !!!
## Then do not forget to add "${ITK_LIBRARIES}" to the target_link_libraries below
# --------------------------------------------------------------------
# ITK Include
set(ADDITIONAL_ITK_MODULES
ITKImageNoise
ITKIOBioRad
ITKIOBMP
ITKIOGE
ITKIOGIPL
ITKIOImageBase
ITKIOIPL
ITKIOJPEG
ITKIOMeta
ITKIOMRC
ITKIONIFTI
ITKIONRRD
ITKIOPNG
ITKIOStimulate
ITKIOTIFF
ITKIOVTK
ITKSmoothing
ITKTestKernel
)
get_property(ITK_VERSION_MAJOR GLOBAL PROPERTY ITK_VERSION_MAJOR)
if(ITK_VERSION_MAJOR EQUAL 4)
#message(STATUS "Using ITK v4")
# Put ITK 4 Specific Modules in here
elseif(ITK_VERSION_MAJOR EQUAL 5)
#message(STATUS "Using ITK v5")
# Put ITK 5 Specific Modyles in here
set(ADDITIONAL_ITK_MODULES ${ADDITIONAL_ITK_MODULES}
ITKImageFeature
ITKTransform
)
if(ITKImageProcessing_ENABLE_ITK_MONTAGE)
list(APPEND ADDITIONAL_ITK_MODULES Montage)
endif()
if(ITKImageProcessing_ENABLE_ITK_TOTAL_VARIATION)
list(APPEND ADDITIONAL_ITK_MODULES TotalVariation)
endif()
endif()
option(${PLUGIN_NAME}_ENABLE_SCIFIO "Enable SCIFIO ITK Modules" OFF)
set(DREAM3D_ADDITIONAL_INSTALL_ITK_DIRECTORIES "")
if(${${PLUGIN_NAME}_ENABLE_SCIFIO})
message(STATUS "${PLUGIN_NAME} Enabling SCIFIO Module")
set( ADDITIONAL_ITK_MODULES
${ADDITIONAL_ITK_MODULES}
SCIFIO
)
set(DREAM3D_ADDITIONAL_INSTALL_ITK_DIRECTORIES
jre
jars
)
endif()
set_property(GLOBAL APPEND PROPERTY ADDITIONAL_ITK_MODULES ${ADDITIONAL_ITK_MODULES})
set_property(GLOBAL APPEND PROPERTY ADDITIONAL_INSTALL_ITK_DIRECTORIES ${DREAM3D_ADDITIONAL_INSTALL_ITK_DIRECTORIES})
include(${CMP_SOURCE_DIR}/ITKSupport/IncludeITK.cmake)
#-------
# Start writing this header file
set(AllFiltersHeaderFile ${${PLUGIN_NAME}_BINARY_DIR}/${PLUGIN_NAME}Filters/${PLUGIN_NAME}Filters.h_tmp)
file(WRITE ${AllFiltersHeaderFile} "#ifndef _${PLUGIN_NAME}_Filters_H_\n#define _${PLUGIN_NAME}_Filters_H_\n\n")
# --------------------------------------------------------------------
# Create a File that will register all of the DREAM3D Filters
set(RegisterKnownFiltersFile ${${PLUGIN_NAME}_BINARY_DIR}/${PLUGIN_NAME}Filters/RegisterKnownFilters.cpp_tmp)
file(WRITE ${RegisterKnownFiltersFile} "/* This file was AUTO GENERATED During the CMake Run. DO NOT EDIT THIS FILE. Edit the CMake files that generate this file */\n")
file(APPEND ${RegisterKnownFiltersFile} "/* The CMake code that generates this file is located in ${CMAKE_CURRENT_LIST_FILE}*/\n")
file(APPEND ${RegisterKnownFiltersFile} "/* This file will be directly included in another source file. */\n")
file(APPEND ${RegisterKnownFiltersFile} "#include \"${PLUGIN_NAME}Filters.h\"\n\n")
file(APPEND ${RegisterKnownFiltersFile} "\n//----------------------------------------------------------\n")
file(APPEND ${RegisterKnownFiltersFile} "\nvoid ${PLUGIN_NAME}Plugin::registerFilters(FilterManager* fm)\n{\n")
set(Project_SRCS "")
# Add in our Filter classes
include(${${PLUGIN_NAME}_SOURCE_DIR}/${PLUGIN_NAME}Filters/SourceList.cmake)
# Add in our Plugin Specific FilterParameter
include(${${PLUGIN_NAME}_SOURCE_DIR}/FilterParameters/SourceList.cmake)
# -- Include all the resources
include(${${PLUGIN_NAME}_SOURCE_DIR}/Resources/SourceList.cmake)
set(${PLUGIN_NAME}_Project_SRCS ${Project_SRCS})
#-----------------------------------------------------
# Close up all the files that we just generated
file(APPEND ${AllFiltersHeaderFile} "\n#endif\n")
file(APPEND ${RegisterKnownFiltersFile} "\n}\n")
#-----------------------------------------------------
# Add function to return all filter names in a list
file(APPEND ${RegisterKnownFiltersFile} "\n//----------------------------------------------------------\n")
file(APPEND ${RegisterKnownFiltersFile} "\nQList<QString> ${PLUGIN_NAME}Plugin::getFilters()\n{\n")
ADD_FILTER_LIST()
file(APPEND ${RegisterKnownFiltersFile} "\n}\n\n")
cmpReplaceFileIfDifferent(OLD_FILE_PATH ${${PLUGIN_NAME}_BINARY_DIR}/${PLUGIN_NAME}Filters/${PLUGIN_NAME}Filters.h
NEW_FILE_PATH ${AllFiltersHeaderFile} )
cmpReplaceFileIfDifferent(OLD_FILE_PATH ${${PLUGIN_NAME}_BINARY_DIR}/${PLUGIN_NAME}Filters/RegisterKnownFilters.cpp
NEW_FILE_PATH ${RegisterKnownFiltersFile} )
set(AllFiltersHeaderFile ${${PLUGIN_NAME}_BINARY_DIR}/${PLUGIN_NAME}Filters/${PLUGIN_NAME}Filters.h)
set(RegisterKnownFiltersFile ${${PLUGIN_NAME}_BINARY_DIR}/${PLUGIN_NAME}Filters/RegisterKnownFilters.cpp)
#-- Compute some directories
get_filename_component(PLUGINS_SOURCE_DIR ${${PLUGIN_NAME}_SOURCE_DIR} DIRECTORY)
get_filename_component(PLUGINS_BINARY_DIR ${${PLUGIN_NAME}_BINARY_DIR} DIRECTORY)
set(FILTER_HEADERS "#include \"${AllFiltersHeaderFile}\"")
set(FILTER_WIDGETS_TEMP_DIR ${${PLUGIN_NAME}_BINARY_DIR}/Temp)
set(FILTER_WIDGETS_BINARY_DIR ${${PLUGIN_NAME}_BINARY_DIR})
set(FILTER_WIDGETS_SOURCE_DIR ${${PLUGIN_NAME}_SOURCE_DIR})
set(FILTER_WIDGETS_DOCS_DIR ${${PLUGIN_NAME}_SOURCE_DIR}/Documentation/Filters)
set(FILTER_INCLUDE_PREFIX "${PLUGIN_NAME}")
# --------------------------------------------------------------------
# On Linux we need -fPIC for linking static and shared libraries
if(UNIX AND NOT APPLE)
set_source_files_properties(${${PLUGIN_NAME}_Project_SRCS} PROPERTIES COMPILE_FLAGS -fPIC)
endif()
# --------------------------------------------------------------------
# These headers will be MOC'ed by the build system. They should all inherit from QObject
# --------------------------------------------------------------------
set(${PLUGIN_NAME}_HDRS
${${PLUGIN_NAME}_SOURCE_DIR}/${PLUGIN_NAME}Constants.h
)
set(${PLUGIN_NAME}_MISC_HDRS
)
cmp_IDE_SOURCE_PROPERTIES( "" "${${PLUGIN_NAME}_MOC_HDRS};${${PLUGIN_NAME}_HDRS};${${PLUGIN_NAME}_MISC_HDRS}" "${${PLUGIN_NAME}_SRCS}" "0")
# -----------------------------------------------------------------------------
# Collect all of our Generated header and source files so that they show up in the various projects
set(${PLUGIN_NAME}_GEN_HDRS
${AllFiltersHeaderFile}
${RegisterKnownFiltersFile}
)
# --------------------------------------------------------------------
# and finally this will run moc:
# QT5_WRAP_CPP( ${PLUGIN_NAME}_Generated_MOC_SRCS ${${PLUGIN_NAME}_MOC_HDRS} OPTIONS -I ${SIMPLProj_SOURCE_DIR}/Source)
set_source_files_properties( ${${PLUGIN_NAME}_Generated_MOC_SRCS} PROPERTIES HEADER_FILE_ONLY TRUE)
set_source_files_properties( ${${PLUGIN_NAME}_Generated_MOC_SRCS} PROPERTIES GENERATED TRUE)
# --------------------------------------------------------------------
#
# --------------------------------------------------------------------
set_source_files_properties( ${${PLUGIN_NAME}_MODULE_MOC_SRCS} PROPERTIES HEADER_FILE_ONLY TRUE)
set_source_files_properties( ${RegisterKnownFiltersFile} PROPERTIES HEADER_FILE_ONLY TRUE)
set_source_files_properties( ${RegisterKnownFilterParameterWidgetsFile} PROPERTIES HEADER_FILE_ONLY TRUE)
# --------------------------------------------------------------------
# Group all the generated source files in IDE's that support it. Makes it clear
# to the user of the IDE what is generated and what is not.
cmp_IDE_SOURCE_PROPERTIES( "Generated/Qt_Moc" "${${PLUGIN_NAME}_GEN_HDRS}" "${${PLUGIN_NAME}_Generated_MOC_SRCS};${${PLUGIN_NAME}_MOC_SRCS};${${PLUGIN_NAME}_GEN_SRCS}" "0")
cmp_IDE_SOURCE_PROPERTIES( "Generated/Qt_Uic" "${${PLUGIN_NAME}_Generated_UI_HDRS}" "" "0")
cmp_IDE_SOURCE_PROPERTIES( "Generated/Qt_Qrc" "${${PLUGIN_NAME}_Generated_RC_SRCS}" "" "0")
# --------------------------------------------------------------------
#
# --------------------------------------------------------------------
include(${${PLUGIN_NAME}_SOURCE_DIR}/ZeissXml/SourceList.cmake)
# --------------------------------------------------------------------
# Create a shared library that contains just code dependent on SIMPL but
# NOT any widget codes. This must be this way for Python bindings.
set(plug_target_name ${PLUGIN_NAME}Server)
add_library(${plug_target_name} SHARED)
#-- Configure the DLL export header file
configure_file(${SIMPLib_SOURCE_DIR}/Plugin/PluginDLLExport.h.in
${${PLUGIN_NAME}_BINARY_DIR}/${PLUGIN_NAME}DLLExport.h)
target_sources(${plug_target_name}
PRIVATE
# -- Add in the filter sources
${${PLUGIN_NAME}_Project_SRCS}
# -- Add in the FilterParameter source files
${${PLUGIN_NAME}_FilterParameters_SRCS}
${${PLUGIN_NAME}_FilterParameters_HDRS}
# -- Add in the plugin interface definition source files
${${PLUGIN_NAME}_SOURCE_DIR}/${PLUGIN_NAME}Plugin.cpp
${${PLUGIN_NAME}_SOURCE_DIR}/${PLUGIN_NAME}Plugin.h
# -- Add in our generated Version source files
${${PLUGIN_NAME}_BINARY_DIR}/${VERSION_HEADER_FILE_NAME}
${${PLUGIN_NAME}_BINARY_DIR}/${VERSION_SOURCE_FILE_NAME}
# -- Add in the DLL Export Header File
${${PLUGIN_NAME}_BINARY_DIR}/${PLUGIN_NAME}DLLExport.h
# -- Add in the XML Parsing sources
${ZeissXml_SRCS}
${ZeissXml_HDRS}
)
#-------------------------------
#
target_include_directories(${plug_target_name}
PUBLIC
${${PLUGIN_NAME}_BINARY_DIR}
${${PLUGIN_NAME}_SOURCE_DIR}
${PLUGINS_SOURCE_DIR}
${PLUGINS_BINARY_DIR}
${${PLUGIN_NAME}_BINARY_DIR}/${PLUGIN_NAME}Filters
${ITK_INCLUDE_DIRS}
)
# --------------------------------------------------------------------
# Set up the target and install rules for this plugin
PluginProperties(TARGET_NAME ${plug_target_name}
DEBUG_EXTENSION "_debug"
VERSION "${DREAM3D_VERSION}"
LIB_SUFFIX ".plugin"
FOLDER ${PLUGIN_NAME}
OUTPUT_NAME ${PLUGIN_NAME}
BINARY_DIR "${DREAM3D_BINARY_DIR}"
PLUGIN_FILE "${CMP_PLUGIN_LIST_FILE}"
ANACONDA_INSTALL ${DREAM3D_ANACONDA}
)
target_link_libraries(${plug_target_name}
Qt5::Core
Qt5::Xml
SIMPLib
${ITK_LIBRARIES}
)
if(MSVC)
# This removes some C++17 Deprecation Warnings inside of ITK 5.1
target_compile_definitions(${plug_target_name} PUBLIC "_SILENCE_CXX17_RESULT_OF_DEPRECATION_WARNING")
set_target_properties(${plug_target_name} PROPERTIES LINK_FLAGS_DEBUG "/INCREMENTAL:NO" )
# enable per object parallel compilation in this large library
target_compile_options(${plug_target_name} PRIVATE "/MP" "/bigobj")
endif()
if(${${PLUGIN_NAME}_ENABLE_SCIFIO})
target_compile_definitions(${PLUGIN_NAME} PUBLIC "ITK_IMAGE_PROCESSING_HAVE_SCIFIO")
endif()
if(BUILD_TESTING)
include(${${PLUGIN_NAME}_SOURCE_DIR}/Test/CMakeLists.txt)
endif()
# --------------------------------------------------------------------
# If Python Wrapping is enabled then generate the Python module code
if(SIMPL_WRAP_PYTHON)
include(${SIMPLProj_SOURCE_DIR}/Wrapping/Python/Binding/CreatePybind11Module.cmake)
CreatePybind11Plugin(PLUGIN_NAME ${PLUGIN_NAME}
PLUGIN_TARGET ${plug_target_name}
BODY_TOP_PATH ${${PLUGIN_NAME}_SOURCE_DIR}/Python/pyBodyTop.cpp
)
endif()
#-------------------------------------------------------------------------------
#- This installs all the prebuilt pipeline files.
if(EXISTS ${${PLUGIN_NAME}_SOURCE_DIR}/ExamplePipelines/${PLUGIN_NAME})
#-------------------------------------------------------------------------------
#- This copies all the Prebuilt Pipeline files into the Build directory
add_custom_target(${PLUGIN_NAME}ExamplePipelinesCopy ALL
COMMAND ${CMAKE_COMMAND} -E copy_directory ${${PLUGIN_NAME}_SOURCE_DIR}/ExamplePipelines/${PLUGIN_NAME}
${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/PrebuiltPipelines/Examples/${PLUGIN_NAME}
COMMENT "Copying ${PLUGIN_NAME} Example Pipelines into Binary Directory")
set_target_properties(${PLUGIN_NAME}ExamplePipelinesCopy PROPERTIES FOLDER ZZ_COPY_FILES)
if(APPLE)
set(INSTALL_DESTINATION "${DREAM3D_PACKAGE_DEST_PREFIX}/Resources/PrebuiltPipelines/Examples")
else()
set(INSTALL_DESTINATION "${DREAM3D_PACKAGE_DEST_PREFIX}/PrebuiltPipelines/Examples")
endif()
if(DREAM3D_ANACONDA)
set(INSTALL_DESTINATION "share/DREAM3D/PrebuiltPipelines/Examples")
endif()
install(DIRECTORY ${${PLUGIN_NAME}_SOURCE_DIR}/ExamplePipelines/${PLUGIN_NAME}
DESTINATION ${INSTALL_DESTINATION}
COMPONENT Applications
)
endif()
#-------------------------------------------------------------------------------
#- This installs all the Data files.
if(EXISTS ${${PLUGIN_NAME}_SOURCE_DIR}/Data/${PLUGIN_NAME})
#-------------------------------------------------------------------------------
# Copy the Data Folder to the build directory
add_custom_target(${PLUGIN_NAME}DataFolderCopy ALL
COMMAND ${CMAKE_COMMAND} -E copy_directory ${${PLUGIN_NAME}_SOURCE_DIR}/Data/${PLUGIN_NAME}
${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/Data
COMMENT "Copying ${PLUGIN_NAME} Data Folder into Binary Directory")
set_target_properties(${PLUGIN_NAME}DataFolderCopy PROPERTIES FOLDER ZZ_COPY_FILES)
set(INSTALL_DESTINATION "Data")
if(DREAM3D_ANACONDA)
set(INSTALL_DESTINATION "share/DREAM3D/Data")
endif()
install(DIRECTORY ${${PLUGIN_NAME}_SOURCE_DIR}/Data/${PLUGIN_NAME}
DESTINATION ${INSTALL_DESTINATION}
COMPONENT Applications
)
endif()
# -- Include the GUI Plugin codes
include(${${PLUGIN_NAME}_SOURCE_DIR}/Gui/CMakeLists.txt)
if(CMAKE_GENERATOR STREQUAL "Ninja")
option(ITKImageProcessing_USE_JOB_POOL "Forces ItkImageProcessing to use a job pool. Only intended to be used for memory limited CI build. Requires Ninja." OFF)
mark_as_advanced(FORCE ITKImageProcessing_USE_JOB_POOL)
endif()
if(ITKImageProcessing_USE_JOB_POOL)
if(NOT CMAKE_GENERATOR STREQUAL "Ninja")
message(FATAL_ERROR "ITKImageProcessing_USE_JOB_POOL requires Ninja as the generator.")
endif()
include(ProcessorCount)
ProcessorCount(thread_count)
# Guess job count as half the number of threads
math(EXPR itk_job_count "${thread_count} / 2")
set(ITKImageProcessing_JOB_POOL ${itk_job_count} CACHE STRING "Number of threads for ITKImageProcessing job pools")
mark_as_advanced(FORCE ITKImageProcessing_JOB_POOL)
message(STATUS "ITKImageProcessing_JOB_POOL: ${ITKImageProcessing_JOB_POOL}")
set_property(GLOBAL APPEND PROPERTY JOB_POOLS itk_pool=${ITKImageProcessing_JOB_POOL})
set_target_properties(${plug_target_name}
PROPERTIES
JOB_POOL_COMPILE itk_pool
)
endif()