Computer Assisted Medical Intervention Tool Kit  version 5.2
 
Loading...
Searching...
No Matches
CamiTKExtension.h
Go to the documentation of this file.
1
116
117
118 # Instruct CMake to run moc automatically when needed.
119 set(CMAKE_AUTOMOC ON)
120
121
122 #########################################################################
123 # #
124 # ARGUMENTS PARSING #
125 # #
126 # * Use a macro to create the CMAKE variables according to the #
127 # provided options as input. #
128 # #
129 #########################################################################
130
131 get_directory_name(${CMAKE_CURRENT_SOURCE_DIR} EXTENSION_NAME)
132
133 set(options ACTION_EXTENSION COMPONENT_EXTENSION VIEWER_EXTENSION DISABLED NEEDS_XERCESC NEEDS_ITK NEEDS_LIBXML2 NEEDS_XSD NEEDS_OPENCV NEEDS_IGSTK INSTALL_ALL_HEADERS NEEDS_GDCM ENABLE_AUTO_TEST ENABLE_INTEGRATION_TEST)
134 set(oneValueArgs TARGET_NAME CEP_NAME DESCRIPTION AUTO_TEST_LEVEL)
135 set(multiValueArgs NEEDS_TOOL NEEDS_CEP_LIBRARIES NEEDS_COMPONENT_EXTENSION NEEDS_ACTION_EXTENSION NEEDS_VIEWER_EXTENSION INCLUDE_DIRECTORIES EXTERNAL_LIBRARIES HEADERS_TO_INSTALL DEFINES CXX_FLAGS EXTERNAL_SOURCES EXTRA_TRANSLATE_LANGUAGE TEST_FILES)
136 cmake_parse_arguments(${EXTENSION_NAME_CMAKE} "${options}" "${oneValueArgs}"
137 "${multiValueArgs}" ${ARGN} )
138
139 #########################################################################
140 # #
141 # CREATE CMAKE VARIABLES #
142 # #
143 # * Create required and useful CMake variables for the macro #
144 # #
145 #########################################################################
146
147 # TYPE EXTENSION : ACTION or COMPONENT or VIEWER
148 if (${EXTENSION_NAME_CMAKE}_ACTION_EXTENSION)
149 set(TYPE_EXTENSION "action")
150 string(TOUPPER ${TYPE_EXTENSION} TYPE_EXTENSION_CMAKE)
151 elseif(${EXTENSION_NAME_CMAKE}_COMPONENT_EXTENSION)
152 set(TYPE_EXTENSION "component")
153 string(TOUPPER ${TYPE_EXTENSION} TYPE_EXTENSION_CMAKE)
154 elseif(${EXTENSION_NAME_CMAKE}_VIEWER_EXTENSION)
155 set(TYPE_EXTENSION "viewer")
156 string(TOUPPER ${TYPE_EXTENSION} TYPE_EXTENSION_CMAKE)
157 endif()
158
159 # CMAKE CACHE VARIABLE
160 # if it is the first cmake run, create the extension variable with a correct initial value
161 if(NOT ${TYPE_EXTENSION_CMAKE}_${EXTENSION_NAME_CMAKE}_INTERNAL)
162 # add option to enable/disable this extension and set it to true by default
163 # Building the extension can be disabled by giving the argument DISABLED to the macro
164 # or by passing the flag -D${TYPE_EXTENSION_CMAKE}_${EXTENSION_NAME_CMAKE}_DISABLED:BOOL=TRUE
165 if(${EXTENSION_NAME_CMAKE}_DISABLED)
166 set(${TYPE_EXTENSION_CMAKE}_${EXTENSION_NAME_CMAKE}_ENABLED FALSE)
167 else()
168 set(${TYPE_EXTENSION_CMAKE}_${EXTENSION_NAME_CMAKE}_ENABLED TRUE)
169 endif()
170 set(${TYPE_EXTENSION_CMAKE}_${EXTENSION_NAME_CMAKE} ${${TYPE_EXTENSION_CMAKE}_${EXTENSION_NAME_CMAKE}_ENABLED} CACHE BOOL "Build extension ${EXTENSION_NAME}")
171 set(${TYPE_EXTENSION_CMAKE}_${EXTENSION_NAME_CMAKE}_INTERNAL TRUE CACHE INTERNAL "Is variable ${TYPE_EXTENSION_CMAKE}_${EXTENSION_NAME} already created?")
172 endif()
173
174 # if this extension is enabled, do everything needed
175 # otherwise... do nothing
176 if (${${TYPE_EXTENSION_CMAKE}_${EXTENSION_NAME_CMAKE}})
177
178 # TARGET NAME
179 # The target name is composed of the following: [action / component]-name
180 # * action / component is the type of extension as prefix
181 # * name is deduced from the input folder containing the calling CMakeLists.txt file of the extension.
182 if (${EXTENSION_NAME_CMAKE}_TARGET_NAME)
183 set(${TYPE_EXTENSION_CMAKE}_OUTPUT_NAME ${${EXTENSION_NAME_CMAKE}_TARGET_NAME})
184 else()
185 set(${TYPE_EXTENSION_CMAKE}_OUTPUT_NAME ${EXTENSION_NAME})
186 endif()
187 # replace "-" by "_" if the extension is being packaged with NSIS, the program to create a Windows installer.
188 if (PACKAGING_NSIS)
189 # NSIS requires that cpack component names do not feature space or "-" characters
190 set(${TYPE_EXTENSION_CMAKE}_TARGET_NAME ${TYPE_EXTENSION}_${${TYPE_EXTENSION_CMAKE}_OUTPUT_NAME})
191 else()
192 set(${TYPE_EXTENSION_CMAKE}_TARGET_NAME ${TYPE_EXTENSION}-${${TYPE_EXTENSION_CMAKE}_OUTPUT_NAME})
193 endif()
194
195 message(STATUS "Building extension ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}")
196
197 # EXTENSION_PLUGIN_FILE
198 # determine the extension full file name depending on the plateform
199 set(EXTENSION_PLUGIN_FILE "${CAMITK_BUILD_PRIVATE_LIB_DIR}/${TYPE_EXTENSION}s")
200 if (MSVC)
201 set(EXTENSION_PLUGIN_FILE ${EXTENSION_PLUGIN_FILE}/${${TYPE_EXTENSION_CMAKE}_OUTPUT_NAME}${CAMITK_DEBUG_POSTFIX}.dll)
202 elseif(APPLE)
203 set(EXTENSION_PLUGIN_FILE ${EXTENSION_PLUGIN_FILE}/lib${${TYPE_EXTENSION_CMAKE}_OUTPUT_NAME}.dylib)
204 else()
205 # Must be Linux
206 set(EXTENSION_PLUGIN_FILE ${EXTENSION_PLUGIN_FILE}/lib${${TYPE_EXTENSION_CMAKE}_OUTPUT_NAME}.so)
207 endif()
208
209 #########################################################################
210 # #
211 # INCLUDE DIRECTORIES #
212 # #
213 # * Include basic directories where to look header files #
214 # * Include also additional user provided directories #
215 # * These directories are used for compilation step #
216 # #
217 #########################################################################
218 # BASIC DIRECTORIES
219
220 include_directories(${CMAKE_CURRENT_SOURCE_DIR})
221 include_directories(${CMAKE_CURRENT_BINARY_DIR})
222 include_directories(${CAMITK_INCLUDE_DIRECTORIES})
223
224 # USER INPUT DIRECTORIES
225 include_directories(${${EXTENSION_NAME_CMAKE}_INCLUDE_DIRECTORIES})
226
227
228
229 #########################################################################
230 # #
231 # GATHER RESOURCES #
232 # #
233 # * Get all the headers (.h) and source files (.cpp) of the project #
234 # * Create the needed Qt files (using moc and uic) #
235 # * On Windows, Visual Studio, group .moc and .ui files #
236 # in subdirectories #
237 # #
238 #########################################################################
239
240 # get all headers, sources and do what is needed for Qt
241 # one need to do this just before the add_library so that all defines, include directories and link directories
242 # are set properly (gather_headers_and_sources include the call to Qt moc and uic)
243 gather_headers_and_sources(${EXTENSION_NAME_CMAKE})
244
245
246
247 #########################################################################
248 # #
249 # ADDITIONAL KNOWN EXTERNAL LIBRARY DEPENDENCIES #
250 # #
251 # * Look for specific library needed #
252 # * Specific libraries are specified as option with the #
253 # NEEDS_LIBRARY syntax (see macro syntax for more options) #
254 # * Backward compatibility : Warn user if using old NEEDS_TOOL syntax #
255 # #
256 #########################################################################
257
258 # Looking for ITK
259 set(ITK_LIBRARIES "")
260 if(${EXTENSION_NAME_CMAKE}_NEEDS_ITK)
261 find_package(ITK REQUIRED PATHS /usr/lib/InsightToolkit)
262 if(ITK_FOUND)
263 include(${ITK_USE_FILE})
264 set(ITK_VERSION ${ITK_VERSION_MAJOR}.${ITK_VERSION_MINOR}.${ITK_VERSION_PATCH}) #ITK_VERSION is not always set
265 set(CAMITK_ITK_VERSION ${ITK_VERSION_MAJOR}.${ITK_VERSION_MINOR})
266 message(STATUS "${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}: Found ITK version ${ITK_VERSION}")
267
268 if ((${ITK_VERSION} VERSION_GREATER "4")) # ITK 4.9 on Windows, maybe a lesser version for Linux.
269 if(MSVC)
270 set(ITK_DIR ${ITK_DIR}/../..)
271 # Construct list of ITK libraries for linking = CAMITK_ITK_LIBRARIES
272 foreach(ITK_LIBRARY ${ITK_LIBRARIES})
273 string(SUBSTRING ${ITK_LIBRARY} 0 3 ${ITK_LIBRARY}_PREFIX)
274 # Some libraries have not the expected 'itk' prefix. Add it then
275 if((NOT ${${ITK_LIBRARY}_PREFIX} STREQUAL "itk") AND (NOT ${${ITK_LIBRARY}_PREFIX} STREQUAL "ITK"))
276 set(ITK_LIBRARY itk${ITK_LIBRARY})
277 endif()
278 list(APPEND CAMITK_ITK_LIBRARIES debug ${ITK_DIR}/${ITK_LIBRARY}-${CAMITK_ITK_VERSION}${CAMITK_DEBUG_POSTFIX}.lib optimized ${ITK_DIR}/${ITK_LIBRARY}-${CAMITK_ITK_VERSION}.lib)
279 endforeach()
280 elseif(UNIX)
281 set(CAMITK_ITK_LIBRARIES ${ITK_LIBRARIES})
282 elseif(APPLE)
283 message(WARNING "CamiTKExtension.cmake: ITK LIBRARY NOT SET FOR APPLE")
284 endif()
285 else()
286 message(FATAL_ERROR "Wrong version of ITK : ${ITK_VERSION}. Required is at least 4.x")
287 endif()
288 else()
289 message(FATAL_ERROR "ITK not found but required for ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}")
290 endif()
291 endif()
292
293 # LIBXML2
294 set(LIBXML2_LIBRARY "")
295 if(${EXTENSION_NAME_CMAKE}_NEEDS_LIBXML2)
296 # LibXml2 is required
297 find_package(Xml2)
298 if (LIBXML2_FOUND)
299 add_definitions(${LIBXML2_DEFINITIONS})
300 include_directories(${LIBXML2_INCLUDE_DIR})
301 set(LIBXML2_LIBRARY ${LIBXML2_LIBRARIES})
302 else()
303 # most probably win32 or crosscompiling
304 message(STATUS "${EXTENSION_NAME}: libxml2 required")
305 endif()
306 endif()
307
308 # OPENCV
309 set(OpenCV_LIBRARIES "")
310 if(${EXTENSION_NAME_CMAKE}_NEEDS_OPENCV)
311 # OpenCV is required
312 find_package( OpenCV REQUIRED )
313 else ( )
314 set(OpenCV_LIBRARIES "")
315 endif()
316
317 # IGSTK
318 set(IGSTK_LIBRARIES "")
319 if(${EXTENSION_NAME_CMAKE}_NEEDS_IGSTK)
320 find_package(IGSTK REQUIRED)
321 include(${IGSTK_USE_FILE})
322 else()
323 set(IGSTK_LIBRARIES "")
324 endif()
325
326 # XERCES-C
327 set(XERCESC_LIBRARIES)
328 if(${EXTENSION_NAME_CMAKE}_NEEDS_XERCESC)
329 # XercesC is required
330 if (NOT XERCESC_LIBRARY)
331 find_package(XercesC REQUIRED)
332 endif()
333 if (XERCESC_FOUND)
334 include_directories(${XERCESC_INCLUDE_DIR})
335 set(XERCESC_LIBRARIES ${XERCESC_LIBRARY})
336 else()
337 # most probably win32 or crosscompiling
338 message(FATAL_ERROR "${EXTENSION_NAME}: xerces-c required. Please provide Xerces-C path.")
339 endif()
340 endif()
341
342 # XSD
343 if(${EXTENSION_NAME_CMAKE}_NEEDS_XSD)
344 # XercesC is required
345 if (NOT XERCESC_LIBRARY)
346 find_package(XercesC REQUIRED)
347 endif()
348 find_package(XercesC REQUIRED)
349 if (XERCESC_FOUND)
350 include_directories(${XERCESC_INCLUDE_DIR})
351 set(XERCESC_LIBRARIES ${XERCESC_LIBRARY})
352 find_package(XSD REQUIRED)
353 include_directories(${XSD_INCLUDE_DIR})
354 else()
355 # most probably win32 or crosscompiling
356 message(FATAL_ERROR "${EXTENSION_NAME}: xerces-c required because of XSD cxx, please set XERCESC_INCLUDE_DIR")
357 endif()
358 endif()
359
360 # GDCM 2.2.x
361 set(GDCM_LIBRARIES)
362 if(${EXTENSION_NAME_CMAKE}_NEEDS_GDCM)
363 if(NOT GDCM_FOUND)
364 # Look for GDCM library only if not found (for instance, ITK has already search for it)
365 # Calling find_package(GDCM ..) more than once creates CMake errors.
366 find_package(GDCM 2.0 REQUIRED)
367 endif()
368 if(GDCM_FOUND)
369 include(${GDCM_USE_FILE})
370 if (${VTK_VERSION} VERSION_GREATER 9)
371 message(STATUS "Detected VTK ${VTK_VERSION_MAJOR}.${VTK_VERSION_MINOR} in GDCM ${GDCM_VERSION_MAJOR}.${GDCM_VERSION_MINOR}: adding extra path for include ${GDCM_INCLUDE_DIRS}/vtk-${VTK_VERSION_MAJOR}.${VTK_VERSION_MINOR}")
372 include_directories(${GDCM_INCLUDE_DIRS}/vtk-${VTK_VERSION_MAJOR}.${VTK_VERSION_MINOR})
373 set(VTK_GDCM_LIB vtkgdcm-${VTK_VERSION_MAJOR}.${VTK_VERSION_MINOR})
374 else()
375 set(VTK_GDCM_LIB vtkgdcm)
376 endif()
377
378 if (MSVC)
379 # List all available GDCM library files
380 file(GLOB GDCM_LIB_FILES
381 LIST_DIRECTORIES false
382 "${GDCM_DIR}/../*${CAMITK_DEBUG_POSTFIX}.lib"
383
384 )
385 unset(GDCM_LIBRARIES)
386 foreach(GDCM_LIB_FILE ${GDCM_LIB_FILES})
387 # Get the actual name of the library
388 string(REGEX REPLACE "^.*/(.*)${CAMITK_DEBUG_POSTFIX}.lib"
389 "\\1" GDCM_LIB_FILE_OPTIMIZED
390 "${GDCM_LIB_FILE}")
391 # Add both debug and optimized version
392 set(GDCM_LIBRARIES ${GDCM_LIBRARIES} debug ${GDCM_LIB_FILE}
393 optimized ${GDCM_LIB_FILE_OPTIMIZED})
394 endforeach()
395
396 else()
397 set(GDCM_LIBRARIES gdcmCommon gdcmDICT gdcmDSED gdcmMEXD gdcmMSFF ${VTK_GDCM_LIB})
398 endif()
399 else()
400 message(FATAL_ERROR "${EXTENSION_NAME}: GDCM 2.x or above library required. Please install GDCM.")
401 endif()
402 endif()
403
404 # EXTERNAL LIBRARIES
405 set(EXTERNAL_LIBRARIES)
406 if(${EXTENSION_NAME_CMAKE}_EXTERNAL_LIBRARIES)
407 foreach(EXTERNAL_LIBRARY ${${EXTENSION_NAME_CMAKE}_EXTERNAL_LIBRARIES})
408 if (MSVC)
409 list(APPEND EXTERNAL_LIBRARIES ${EXTERNAL_LIBRARIES}
410 debug ${EXTERNAL_LIBRARY}${CAMITK_DEBUG_POSTFIX}.lib
411 optimized ${EXTERNAL_LIBRARY}.lib
412 )
413 else()
414 list(APPEND EXTERNAL_LIBRARIES ${EXTERNAL_LIBRARY})
415 endif()
416 endforeach()
417 endif()
418
419
420
421 #########################################################################
422 # #
423 # LINK DIRECTORIES #
424 # #
425 # * Link directories are used to indicate the compiler where #
426 # to look for folder containing libraries to link with. #
427 # * Must be done BEFORE creating the CMake target with add_library #
428 # #
429 #########################################################################
430
431 # CAMITK BASIC LIB DIRECTORIES
432 link_directories(${CAMITK_LINK_DIRECTORIES})
433
434
435
436 #########################################################################
437 # #
438 # TARGET COMPILATION DEFINITION #
439 # #
440 # * Additional sources files to consider at compilation (.cpp) #
441 # * CMake project target definition #
442 # #
443 #########################################################################
444 # EXTERNAL SOURCES
445 set(${EXTENSION_NAME_CMAKE}_SOURCES ${${EXTENSION_NAME_CMAKE}_SOURCES} ${${EXTENSION_NAME_CMAKE}_EXTERNAL_SOURCES})
446
447 # CMAKE TARGET DEFINITION
448 add_library(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} SHARED ${${EXTENSION_NAME_CMAKE}_SOURCES})
449
450
451
452 #########################################################################
453 # #
454 # QT LINKING LIBRARIES #
455 # #
456 # * Set at linking the Qt5 libraries #
457 # #
458 #########################################################################
459 target_link_libraries(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} ${CAMITK_QT_LIBRARIES})
460
461
462 #########################################################################
463 # #
464 # CAMITK ACTION / COMPONENT / LIBRARIES DEPENDENCIES #
465 # #
466 # * Look for action / component / libraries dependencies #
467 # * Specific actions / components / libraries are specified as option #
468 # with the NEEDS_ACTION/COMPONENT_EXTENSION/CEP_LIBRARIES syntax #
469 # * Add dependencies to library-camitkcore and the testing #
470 # action/component if test are runned on it #
471 # #
472 #########################################################################
473
474 # 1st CAMITKCORE LIBRARY DEPENDENCY
475 # add_dependencies(..) is only needed to enable parallel build during SDK build
476 # but generates an error for external CEP, where this target does not
477 # exists.
478 # Using target_link_libraries(..) is enough to link the extension to the CamiTK core library
479 if(CAMITK_COMMUNITY_EDITION_BUILD)
480 add_dependencies(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} ${CAMITK_CORE_TARGET_LIB_NAME})
481 # add the dependency to the core automoc target only if inside a SDK build
482 set_property(TARGET ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} APPEND PROPERTY AUTOGEN_TARGET_DEPENDS ${CAMITK_CORE_TARGET_LIB_NAME})
483 endif()
484
485
486 # 2nd COMPONENTS DEPENDENCIES
487 if(${EXTENSION_NAME_CMAKE}_NEEDS_COMPONENT_EXTENSION)
488 set(COMPONENTS_DEPENDENCY_LIST "") #use for generating the project.xml file
489 foreach(COMPONENT_NEEDED ${${EXTENSION_NAME_CMAKE}_NEEDS_COMPONENT_EXTENSION})
490 # include directories from build, camitk (local or global install).
491 include_directories(${CAMITK_BUILD_INCLUDE_DIR}/components/${COMPONENT_NEEDED})
492 include_directories(${CAMITK_INCLUDE_DIR}/components/${COMPONENT_NEEDED})
493 # file dependency
494 if (MSVC)
495 list(APPEND COMPONENT_EXTENSION_LIBRARIES debug ${CAMITK_BUILD_PRIVATE_LIB_DIR}/components/${COMPONENT_NEEDED}${CAMITK_DEBUG_POSTFIX}.lib
496 optimized ${COMPONENT_NEEDED}
497 )
498 else()
499 list(APPEND COMPONENT_EXTENSION_LIBRARIES ${COMPONENT_NEEDED})
500 endif()
501 # CMake / CDash dependencies
502 if(PACKAGING_NSIS)
503 # if the target is installed in the CAMITK_INCLUDE_DIR, import it before adding the dependencies
504 if(EXISTS ${CAMITK_INCLUDE_DIR}/components/${COMPONENT_NEEDED} AND NOT TARGET component_${COMPONENT_NEEDED})
505 message(STATUS "Importing target component_${COMPONENT_NEEDED}")
506 add_library(component_${COMPONENT_NEEDED} INTERFACE IMPORTED)
507 endif()
508 add_dependencies(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} component_${COMPONENT_NEEDED})
509 else()
510 if(EXISTS ${CAMITK_INCLUDE_DIR}/components/${COMPONENT_NEEDED} AND NOT TARGET component-${COMPONENT_NEEDED})
511 message(STATUS "Importing target component-${COMPONENT_NEEDED}")
512 add_library(component-${COMPONENT_NEEDED} INTERFACE IMPORTED)
513 endif()
514 add_dependencies(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} component-${COMPONENT_NEEDED})
515 list(APPEND COMPONENTS_DEPENDENCY_LIST component-${COMPONENT_NEEDED})
516 endif()
517 endforeach()
518 endif()
519
520 # 3rd ACTIONS DEPENDENCIES
521 if(${EXTENSION_NAME_CMAKE}_NEEDS_ACTION_EXTENSION)
522 set(ACTIONS_DEPENDENCY_LIST "") #use for generating the project.xml file
523 foreach(ACTION_NEEDED ${${EXTENSION_NAME_CMAKE}_NEEDS_ACTION_EXTENSION})
524 # include directories from build, camitk (local or global install).
525 include_directories(${CAMITK_BUILD_INCLUDE_DIR}/actions/${ACTION_NEEDED})
526 include_directories(${CAMITK_INCLUDE_DIR}/actions/${ACTION_NEEDED})
527 # file dependency
528 if (MSVC)
529 list(APPEND ACTION_EXTENSION_LIBRARIES debug ${CAMITK_BUILD_PRIVATE_LIB_DIR}/actions/${ACTION_NEEDED}${CAMITK_DEBUG_POSTFIX}.lib
530 optimized ${ACTION_NEEDED}
531 )
532 else()
533 list(APPEND ACTION_EXTENSION_LIBRARIES ${ACTION_NEEDED})
534 endif()
535 # CMake / CDash dependencies
536 if (PACKAGING_NSIS)
537 # if the target is installed in the CAMITK_INCLUDE_DIR, import it before adding the dependencies
538 if(EXISTS ${CAMITK_INCLUDE_DIR}/actions/${ACTION_NEEDED} AND NOT TARGET action_${ACTION_NEEDED})
539 message(STATUS "Importing target action_${ACTION_NEEDED}")
540 add_library(action_${ACTION_NEEDED} INTERFACE IMPORTED)
541 endif()
542 add_dependencies(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} action_${ACTION_NEEDED})
543 else()
544 # if the target is installed in the CAMITK_INCLUDE_DIR, import it before adding the dependencies
545 if(EXISTS ${CAMITK_INCLUDE_DIR}/actions/${ACTION_NEEDED} AND NOT TARGET action-${ACTION_NEEDED})
546 message(STATUS "Importing target action-${ACTION_NEEDED}")
547 add_library(action-${ACTION_NEEDED} INTERFACE IMPORTED)
548 endif()
549 add_dependencies(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} action-${ACTION_NEEDED})
550 list(APPEND ACTIONS_DEPENDENCY_LIST action-${ACTION_NEEDED})
551 endif()
552 endforeach()
553 endif()
554
555 # 4th VIEWERS DEPENDENCIES
556 if(${EXTENSION_NAME_CMAKE}_NEEDS_VIEWER_EXTENSION)
557 set(VIEWERS_DEPENDENCY_LIST "") #use for generating the project.xml file
558 foreach(VIEWER_NEEDED ${${EXTENSION_NAME_CMAKE}_NEEDS_VIEWER_EXTENSION})
559 # include directories from build, camitk (local or global install).
560 include_directories(${CAMITK_BUILD_INCLUDE_DIR}/viewers/${VIEWER_NEEDED})
561 include_directories(${CAMITK_INCLUDE_DIR}/viewers/${VIEWER_NEEDED})
562 # file dependency
563 if (MSVC)
564 list(APPEND VIEWER_EXTENSION_LIBRARIES debug ${CAMITK_BUILD_PRIVATE_LIB_DIR}/viewers/${VIEWER_NEEDED}${CAMITK_DEBUG_POSTFIX}.lib
565 optimized ${VIEWER_NEEDED}
566 )
567 else()
568 list(APPEND VIEWER_EXTENSION_LIBRARIES ${VIEWER_NEEDED})
569 endif()
570 # CMake / CDash dependencies
571 if (PACKAGING_NSIS)
572 if(EXISTS ${CAMITK_INCLUDE_DIR}/viewers/${VIEWER_NEEDED} AND NOT TARGET viewer_${VIEWER_NEEDED})
573 message(STATUS "Importing target viewer_${VIEWER_NEEDED}")
574 add_library(viewer_${VIEWER_NEEDED} INTERFACE IMPORTED)
575 endif()
576 # now add the dependency
577 add_dependencies(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} viewer_${VIEWER_NEEDED})
578 else()
579 # if the target is installed in the CAMITK_INCLUDE_DIR, import it before adding the dependencies
580 if(EXISTS ${CAMITK_INCLUDE_DIR}/viewers/${VIEWER_NEEDED} AND NOT TARGET viewer-${VIEWER_NEEDED})
581 message(STATUS "Importing target viewer-${VIEWER_NEEDED}")
582 add_library(viewer-${VIEWER_NEEDED} INTERFACE IMPORTED)
583 endif()
584 add_dependencies(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} viewer-${VIEWER_NEEDED})
585 list(APPEND VIEWERS_DEPENDENCY_LIST viewer-${VIEWER_NEEDED})
586 endif()
587 endforeach()
588 endif()
589
590 # 5th CEP LIBRARIES DEPENDENCIES
591 if(${EXTENSION_NAME_CMAKE}_NEEDS_CEP_LIBRARIES)
592 set(CEP_LIBRARIES_DEPENDENCY_LIST "") #use for generating the project.xml file
593 foreach(CEP_LIBRARY_NEEDED ${${EXTENSION_NAME_CMAKE}_NEEDS_CEP_LIBRARIES})
594 # include directories from build, camitk (local or global install).
595 include_directories(${CAMITK_BUILD_INCLUDE_DIR}/libraries/${CEP_LIBRARY_NEEDED})
596 include_directories(${CAMITK_INCLUDE_DIR}/libraries/${CEP_LIBRARY_NEEDED})
597 # file dependency
598 if (MSVC)
599 list(APPEND CEP_LIBRARIES debug ${CEP_LIBRARY_NEEDED}${CAMITK_DEBUG_POSTFIX}.lib
600 optimized ${CEP_LIBRARY_NEEDED}
601 )
602 else()
603 list(APPEND CEP_LIBRARIES ${CEP_LIBRARY_NEEDED})
604 endif()
605 # CMake / CDash dependencies
606 if (PACKAGING_NSIS)
607 if (EXISTS ${CAMITK_INCLUDE_DIR}/libraries/${CEP_LIBRARY_NEEDED} AND NOT TARGET library_${CEP_LIBRARY_NEEDED})
608 message(STATUS "Importing target library_${CEP_LIBRARY_NEEDED}")
609 add_library(library_${CEP_LIBRARY_NEEDED} INTERFACE IMPORTED)
610 endif()
611 # now add the dependency
612 add_dependencies(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} library_${CEP_LIBRARY_NEEDED})
613 # add the dependency to the component automoc target only if compiling SDK
614 #if(CAMITK_COMMUNITY_EDITION_BUILD)
615 #set_property(TARGET ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} APPEND PROPERTY AUTOGEN_TARGET_DEPENDS library_${CEP_LIBRARY_NEEDED})
616 #endif()
617 else()
618 # if the target is installed in the CAMITK_INCLUDE_DIR, import it before adding the dependencies
619 if (NOT TARGET library-${CEP_LIBRARY_NEEDED})
620 message(STATUS "Importing target library-${CEP_LIBRARY_NEEDED}")
621 add_library(library-${CEP_LIBRARY_NEEDED} INTERFACE IMPORTED)
622 endif()
623 add_dependencies(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} library-${CEP_LIBRARY_NEEDED})
624 list(APPEND CEP_LIBRARIES_DEPENDENCY_LIST ${CEP_LIBRARY_NEEDED} library-${CEP_LIBRARY_NEEDED})
625 ## add the dependency to the component automoc target only if compiling SDK
626 #if(CAMITK_COMMUNITY_EDITION_BUILD)
627 #set_property(TARGET ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} APPEND PROPERTY AUTOGEN_TARGET_DEPENDS library-${CEP_LIBRARY_NEEDED})
628 #endif()
629 endif()
630 endforeach()
631 endif()
632
633 #########################################################################
634 # #
635 # COMPILATION FLAG #
636 # #
637 # * Flags are options to give to the compiler #
638 # * Add user input flags #
639 # * Add platform specific flags #
640 # #
641 #########################################################################
642
643 # USER INPUT DEFINES COMPILER FLAG
644 if(${EXTENSION_NAME_CMAKE}_DEFINES)
645 foreach (FLAG ${${EXTENSION_NAME_CMAKE}_DEFINES})
646 add_definitions(-D${FLAG})
647 endforeach()
648 endif()
649
650 # USER INPUT CUSTOM COMPILER FLAG
651 if(${EXTENSION_NAME_CMAKE}_CXX_FLAGS)
652 foreach (FLAG ${${EXTENSION_NAME_CMAKE}_CXX_FLAGS})
653 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAG}")
654 endforeach()
655 endif()
656
657 # PLATFORM SPECIFIC COMPILER FLAG
658 # 64bits and other platform with relocation needs -fPIC
659 include(TestCXXAcceptsFlag)
660 check_cxx_accepts_flag(-fPIC FPIC_FLAG_ACCEPTED)
661 # no need to add -fPIC on mingw, otherwise it generates a warning: -fPIC ignored for target (all code is position independent) [enabled by default]
662 # msvc is also accepting the flag, but then produce warning D9002 : ignoring unknown option '-fPIC' cl
663 if(FPIC_FLAG_ACCEPTED AND NOT WIN32)
664 set_property(TARGET ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} APPEND PROPERTY COMPILE_FLAGS -fPIC)
665 endif()
666
667
668
669 #########################################################################
670 # #
671 # LINKING #
672 # #
673 # * Linking is the last stage of compilation #
674 # * Indicate what libraries to use for linking the target #
675 # #
676 #########################################################################
677 # LINKING LIBRARIES
678 # Any component or action has to be linked with ${CAMITK_CORE_LIBRARIES} and with all its dependencies
679 target_link_libraries(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} ${CAMITK_CORE_LIBRARIES} ${CAMITK_LIBRARIES} ${COMPONENT_EXTENSION_LIBRARIES} ${ACTION_EXTENSION_LIBRARIES} ${VIEWER_EXTENSION_LIBRARIES} ${CEP_LIBRARIES} ${CAMITK_ITK_LIBRARIES} ${LIBXML2_LIBRARY} ${OpenCV_LIBRARIES} ${IGSTK_LIBRARIES} ${XERCESC_LIBRARIES} ${GDCM_LIBRARIES} ${EXTERNAL_LIBRARIES})
680 if("${VTK_VERSION}" VERSION_GREATER_EQUAL 9.0)
681 vtk_module_autoinit(
682 TARGETS ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
683 MODULES ${CAMITK_VTK_LIBRARIES})
684 endif()
685
686
687 #########################################################################
688 # #
689 # OUTPUT #
690 # #
691 # * Define the output directory (location and name) #
692 # * Define the output name of the library #
693 # * Add ${CAMITK_DEBUG_POSTFIX} suffix to Debug MSVC built libraries #
694 # * Additional Linux .so files information #
695 # #
696 #########################################################################
697
698 # OUTPUT LIBRARY NAME
699 set_target_properties(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
700 PROPERTIES OUTPUT_NAME ${${TYPE_EXTENSION_CMAKE}_OUTPUT_NAME}
701 )
702
703 # OUTPUT DIRECTORY LOCATION AND NAME
704 # Output directory (all extensions are private)
705 set_target_properties(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CAMITK_BUILD_PRIVATE_LIB_DIR}/${TYPE_EXTENSION}s
706 LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CAMITK_BUILD_PRIVATE_LIB_DIR}/${TYPE_EXTENSION}s
707 LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CAMITK_BUILD_PRIVATE_LIB_DIR}/${TYPE_EXTENSION}s
708 )
709 # Output directory (for dll plateform, this is still the same, extensions are private)
710 set_target_properties(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CAMITK_BUILD_PRIVATE_LIB_DIR}/${TYPE_EXTENSION}s
711 RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CAMITK_BUILD_PRIVATE_LIB_DIR}/${TYPE_EXTENSION}s
712 RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CAMITK_BUILD_PRIVATE_LIB_DIR}/${TYPE_EXTENSION}s
713 )
714 # Output directory (for dll plateform, this is still the same, extensions are private)
715 set_target_properties(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CAMITK_BUILD_PRIVATE_LIB_DIR}/${TYPE_EXTENSION}s
716 ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CAMITK_BUILD_PRIVATE_LIB_DIR}/${TYPE_EXTENSION}s
717 ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CAMITK_BUILD_PRIVATE_LIB_DIR}/${TYPE_EXTENSION}s
718 )
719
720 # OUTPUT LIBRARY NAME MSVC in DEBUG mode
721 if (MSVC)
722 set_target_properties(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} PROPERTIES DEBUG_POSTFIX ${CAMITK_DEBUG_POSTFIX})
723 endif()
724
725 # ADDITIONAL LINUX .so FILE INFORMATION
726 set(${TYPE_EXTENSION_CMAKE}_LIBRARY_PROPERTIES ${${TYPE_EXTENSION_CMAKE}_LIBRARY_PROPERTIES}
727 VERSION "${CAMITK_VERSION_MAJOR}.${CAMITK_VERSION_MINOR}.${CAMITK_VERSION_PATCH}"
728 SOVERSION "${CAMITK_VERSION_MAJOR}"
729 )
730 # set the library specific info (SONAME...)
731 set_target_properties(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} PROPERTIES ${${TYPE_EXTENSION_CMAKE}_LIBRARY_PROPERTIES} LINK_INTERFACE_LIBRARIES "")
732
733 # see http://www.cmake.org/pipermail/cmake/2012-April/049889.html
734 # target properties (outputname and remove soname)
735 # set_property(TARGET ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} PROPERTY NO_SONAME 1)
736 # in CEP the version patch might not have been set
737 if (NOT CAMITK_VERSION_PATCH)
738 set(CAMITK_VERSION_PATCH 0)
739 endif()
740
741
742
743 #########################################################################
744 # #
745 # INSTALLATION #
746 # #
747 # * When installing the project, header files (.h) and test data are #
748 # copied into a installation folder to determine. #
749 # * Indicate in this section, where to install your project and which #
750 # files to copy into that folder (during local/global installation) #
751 # #
752 #########################################################################
753
754 # FOLDER INSTALLATION
755 # Indicate where to install the action/component
756 install(TARGETS ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
757 # TODO always use private lib, even for runtime
758 RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}/${CAMITK_SHORT_VERSION_STRING}/${TYPE_EXTENSION}s
759 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/${CAMITK_SHORT_VERSION_STRING}/${TYPE_EXTENSION}s
760 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/${CAMITK_SHORT_VERSION_STRING}/${TYPE_EXTENSION}s
761 COMPONENT ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
762 )
763
764 # HEADERS INSTALLATION
765 # Build target to install provided headers to install (with HEADERS_TO_INSTALL option)
766 if(${EXTENSION_NAME_CMAKE}_HEADERS_TO_INSTALL)
767 export_headers(${${EXTENSION_NAME_CMAKE}_HEADERS_TO_INSTALL} COMPONENT ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} GROUP ${TYPE_EXTENSION}s)
768 endif()
769
770 # Build target to install all header files(with INSTALL_ALL_HEADERS option)
771 if(${EXTENSION_NAME_CMAKE}_INSTALL_ALL_HEADERS)
772 export_headers(${${EXTENSION_NAME_CMAKE}_HEADERS} COMPONENT ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} GROUP ${TYPE_EXTENSION}s)
773 endif()
774
775 # TESTDATA INSTALLATION
776 if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/testdata")
777 # Check test data dir directory
778 if (NOT EXISTS ${CAMITK_BUILD_TESTDATA_DIR})
779 make_directory( ${CAMITK_BUILD_TESTDATA_DIR} )
780 endif()
781
782 # copy the files to test data directory
783 execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory testdata ${CAMITK_BUILD_TESTDATA_DIR}
784 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
785 )
786
787 # during installation, copy the files to install directory
788 set (TESTDATA_DEST_DIR share/${CAMITK_SHORT_VERSION_STRING}/testdata)
789 install(DIRECTORY testdata/
790 #DESTINATION share/testdata
791 #DESTINATION share/${CAMITK_SHORT_VERSION_STRING}/testdata
792 DESTINATION ${TESTDATA_DEST_DIR}
793 # COMPONENT ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
794 PATTERN ".svn" EXCLUDE
795 PATTERN "*~" EXCLUDE
796 )
797 endif()
798
799 #########################################################################
800 # #
801 # CDASH SUBPROJECT DESCRIPTION #
802 # #
803 # * Update the XML description of the subprojects dependencies #
804 # for CDash. #
805 # #
806 #########################################################################
807 # CDASH XML SUBPROJECTS DESCRIPTION UPDATE
808 camitk_register_subproject(${TYPE_EXTENSION_CMAKE} ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} DEPENDENCIES library-camitkcore ${COMPONENTS_DEPENDENCY_LIST} ${ACTIONS_DEPENDENCY_LIST} ${VIEWERS_DEPENDENCY_LIST} ${CEP_LIBRARIES_DEPENDENCY_LIST})
809
810
811
812 #########################################################################
813 # #
814 # PACKAGING CATEGORIZATION #
815 # #
816 # * On Windows, when building a package (win32 installer), the #
817 # install shield wizard proposes you to select which component #
818 # to install. #
819 # * Each component to install has a short description following its #
820 # name to understand its role. #
821 # * This section deals with the categorization and the description #
822 # of the component in this installer. #
823 # #
824 #########################################################################
825
826 # WINDOWS INSTALLER CATEGORIZATION
827 if(${EXTENSION_NAME_CMAKE}_CEP_NAME)
828 if (${EXTENSION_NAME_CMAKE}_CEP_NAME MATCHES "SDK")
829 # The default SDK extensions are categorized as "required" and are not "unselectable" by the user at installation time
830 cpack_add_component(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
831 DISPLAY_NAME ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
832 DESCRIPTION ${${EXTENSION_NAME_CMAKE}_DESCRIPTION}
833 REQUIRED
834 GROUP SDK
835 )
836
837 else()
838 # Extension is selectable for installation in the wizard of the installer
839 cpack_add_component(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
840 DISPLAY_NAME ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
841 DESCRIPTION ${${EXTENSION_NAME_CMAKE}_DESCRIPTION}
842 GROUP ${${EXTENSION_NAME_CMAKE}_CEP_NAME}
843 )
844 endif()
845 else()
846 # Extension if not categorized for packaging presentation
847 cpack_add_component(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
848 DISPLAY_NAME ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
849 DESCRIPTION ${${EXTENSION_NAME_CMAKE}_DESCRIPTION}
850 )
851 endif()
852
853
854 #####################################################################################
855 # #
856 # TRANSLATION #
857 # #
858 # * CAMITK_TRANSLATIONS contains the list of language to translate #
859 # the QString to. #
860 # #
861 # * Create the translate.pro file which contains 4 sections: #
862 # - HEADERS: list of .h/.hpp files to look for tr("") QString #
863 # - SOURCES: list of .cpp files to look for tr("") QString #
864 # - FORMS: list of .ui files to look for tr("") QString #
865 # - TRANSLATIONS: list of .ts files which use CAMITK_TRANSLATIONS #
866 # to define each .ts file #
867 # #
868 # * Execute lupdate program to update the .ts files with new QString #
869 # found. #
870 # #
871 # * Execute lrelease program to create .qm files (binary equivalent of #
872 # .ts files #
873 # #
874 # * Create translate.qrc which contains the list of .qm files. #
875 # * Create the flags.qrc file which contains the list of .png flags #
876 # images #
877 # #
878 #####################################################################################
879 if(CAMITK_TRANSLATE)
880 if(${EXTENSION_NAME_CMAKE}_EXTRA_TRANSLATE_LANGUAGE)
881 if(EXTENSION_NAME STREQUAL "application")
882 camitk_translate(USE_FLAGS
883 EXTRA_LANGUAGE ${${EXTENSION_NAME_CMAKE}_EXTRA_TRANSLATE_LANGUAGE})
884 else()
885 camitk_translate(EXTRA_LANGUAGE ${${EXTENSION_NAME_CMAKE}_EXTRA_TRANSLATE_LANGUAGE})
886 endif()
887 else()
888 if(EXTENSION_NAME STREQUAL "application")
889 camitk_translate(USE_FLAGS)
890 else()
891 camitk_translate()
892 endif()
893 endif()
894 endif()
895
896
897
898 #########################################################################
899 # #
900 # CTEST - COMPONENT TESTS DESCRIPTION #
901 # #
902 #########################################################################
903
904 # if auto test possible and required
905 if (NOT PACKAGING_NSIS AND BUILD_TESTING AND ${EXTENSION_NAME_CMAKE}_ENABLE_AUTO_TEST)
906 if(${EXTENSION_NAME_CMAKE}_COMPONENT_EXTENSION)
907 camitk_init_test( camitk-testcomponents )
908
909 camitk_parse_test_add_separator(EXTENSION_TYPE ${TYPE_EXTENSION} EXTENSION_NAME ${EXTENSION_NAME})
910
911 # Retrieve the files in testdata directory - a test will be applied for each of these files
912 # or use only the given files
913 if (${EXTENSION_NAME_CMAKE}_TEST_FILES)
914 # add testdata dir to filename
915 set(TESTFILES)
916 foreach(COMPONENT_TESTDATA_FILE ${${EXTENSION_NAME_CMAKE}_TEST_FILES})
917 list(APPEND TESTFILES ${CMAKE_CURRENT_SOURCE_DIR}/${COMPONENT_TESTDATA_FILE})
918 endforeach()
919 else()
920 get_subdirectoryfiles( ${CMAKE_CURRENT_SOURCE_DIR}/testdata TESTFILES )
921 endif()
922
923 if (NOT ${EXTENSION_NAME_CMAKE}_AUTO_TEST_LEVEL)
924 # default
925 set(TESTLEVEL 3)
926 else()
927 set(TESTLEVEL ${${EXTENSION_NAME_CMAKE}_AUTO_TEST_LEVEL})
928 if (NOT ${TESTLEVEL} MATCHES "^[1-3]")
929 # default
930 message(WARNING "AUTO_TEST_LEVEL set to 3 (${TESTLEVEL} is not a valid level)")
931 set(TESTLEVEL 3)
932 else()
933 set(TESTLEVEL ${${EXTENSION_NAME_CMAKE}_AUTO_TEST_LEVEL})
934 endif()
935 endif()
936
937 # Different the test level are done automatically:
938 # - level 1: load component extension, open & close test data
939 # - level 2: load component extension, open & close test data, save as
940 # - level 3: load component extension, open & close test data, save as and compare input with output
941 # disable some tests accordingly to options defined in camitk_extension macro arguments
942 if(TESTLEVEL STREQUAL "1")
943 set(TEST_DESCRIPTION "Test loading the extension, opening and closing the component.")
944 elseif(TESTLEVEL STREQUAL "2")
945 set(TEST_DESCRIPTION "Test loading the extension, opening the component and saving it as a file.")
946 else()
947 # level 3
948 set(TEST_DESCRIPTION "Test loading the extension, opening, saving and closing the component and comparing saved with input component.")
949 endif()
950
951 foreach(COMPONENT_TESTDATA_FILE ${TESTFILES})
952 # Give the file name (full path)
953 get_directory_name(${COMPONENT_TESTDATA_FILE} DATA_FILE)
954
955 # Test procedure: Open an extension and a component- save it - Compare saved file to original file(level3)
956 if(${TESTLEVEL} EQUAL 3)
957 # Level 3 = level 2 + test the output -> test level 2 + add the PASS_FILE_OUTPUT options to the test
958 camitk_add_test(EXECUTABLE_ARGS "-i ${CAMITK_BUILD_TESTDATA_DIR}/${DATA_FILE} -c ${EXTENSION_PLUGIN_FILE} -l 2"
959 PASS_FILE_OUTPUT ${CAMITK_BUILD_TESTDATA_DIR}/${DATA_FILE}
960 TEST_SUFFIX "-level3-"
961 PROJECT_NAME ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
962 )
963 endif()
964
965 if(${TESTLEVEL} EQUAL 2)
966 camitk_add_test(EXECUTABLE_ARGS "-i ${CAMITK_BUILD_TESTDATA_DIR}/${DATA_FILE} -c ${EXTENSION_PLUGIN_FILE} -l 2"
967 TEST_SUFFIX "-level2-"
968 PROJECT_NAME ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
969 )
970 endif()
971
972 if(${TESTLEVEL} EQUAL 1)
973 camitk_add_test(EXECUTABLE_ARGS "-i ${CAMITK_BUILD_TESTDATA_DIR}/${DATA_FILE} -c ${EXTENSION_PLUGIN_FILE} -l 1"
974 TEST_SUFFIX "-level1-"
975 PROJECT_NAME ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
976 )
977 endif()
978
979 camitk_parse_test_add(NAME ${CAMITK_TEST_NAME} LEVEL ${TESTLEVEL} DESCRIPTION ${TEST_DESCRIPTION})
980 endforeach()
981
982 #########################################################################
983 # #
984 # CTEST - ACTION TESTS DESCRIPTION #
985 # #
986 #########################################################################
987 # We do not apply automatic tests on actions like (close, save, save as) as they
988 # may not act directly on components
989 elseif( ${EXTENSION_NAME_CMAKE}_ACTION_EXTENSION AND NOT (${${TYPE_EXTENSION_CMAKE}_OUTPUT_NAME} MATCHES "application"))
990 camitk_init_test( camitk-testactions )
991
992 camitk_parse_test_add_separator(EXTENSION_TYPE ${TYPE_EXTENSION} EXTENSION_NAME ${EXTENSION_NAME})
993
994 # get the names of actions .dlls in lib directory
995 get_subdirectoryfiles( ${CAMITK_BUILD_PRIVATE_LIB_DIR}/actions/ ACTIONSDLLS )
996
997 # Retrieve the files in testdata directory - a test will be applied for each of these files
998 # or use only the given files
999 if (${EXTENSION_NAME_CMAKE}_TEST_FILES)
1000 # add testdata dir to filename
1001 set(TESTFILES)
1002 foreach(ACTION_TESTDATA_FILE ${${EXTENSION_NAME_CMAKE}_TEST_FILES})
1003 list(APPEND TESTFILES ${CAMITK_BUILD_TESTDATA_DIR}/${ACTION_TESTDATA_FILE})
1004 endforeach()
1005 else()
1006 get_subdirectoryfiles(${CAMITK_BUILD_TESTDATA_DIR} TESTFILES)
1007 endif()
1008
1009 foreach( ACTION_TESTDATA_FILE ${TESTFILES})
1010 # Test procedure: Open a file - load an action extension - Apply an action on the component wrapping the file
1011 camitk_add_test(EXECUTABLE_ARGS "-i ${ACTION_TESTDATA_FILE} -a ${EXTENSION_PLUGIN_FILE}"
1012 TEST_SUFFIX "-level1-"
1013 PROJECT_NAME ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
1014 )
1015 camitk_parse_test_add(NAME ${CAMITK_TEST_NAME} LEVEL 1 DESCRIPTION "Open a file, load the action and apply it on the component.")
1016 endforeach()
1017 endif()
1018 endif() # NOT PACKAGING_NSIS AND BUILD_TESTING AND ${EXTENSION_NAME_CMAKE}_ENABLE_AUTO_TEST)
1019
1020 #########################################################################
1021 # #
1022 # CTEST - Integration test #
1023 # #
1024 #########################################################################
1025
1026 if (NOT PACKAGING_NSIS AND BUILD_TESTING AND ${EXTENSION_NAME_CMAKE}_ENABLE_INTEGRATION_TEST)
1027 # add a specific test to run the action, save the output and compare it to expected
1028 camitk_add_integration_test()
1029 endif()
1030
1031 endif() # ${TYPE_EXTENSION_CMAKE}_${EXTENSION_NAME_CMAKE}_ENABLED
1032
1033end(){)
1034
1035
1036# TODO write a viewer_extension macro in CamiTK
cmake modules macros camitk test endif() add_custom_target(camitk-ce-iwyu COMMAND $
Definition CamiTKIncludeWhatYouUse.h:37
#define a
iwyu out CACHE PATH Output filename for include what you use set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE ${IWYU_EXECUTABLE}) if(NOT EXISTS $
Definition CamiTKIncludeWhatYouUse.h:22
static void include(QRect &r, const QRect &rect)
Definition canvas_typed/qtcanvas.cpp:98
camitk_extension()
Macro camitk_extension simplifies writing a camitk extension (component, action, viewer)
Definition CamiTKExtension.h:115
get_directory_name()
macro get_directory_name set the variable VariableName to the name of the last directory of FullPathD...
Definition GetDirectoryName.h:14
gather_headers_and_sources()
macro gather_headers_and_sources find all headers, sources, including the qt ui, moc and resources an...
Definition GatherHeadersAndSources.h:15