Computer Assisted Medical Intervention Tool Kit  version 5.2
CamiTKExtension.h
Go to the documentation of this file.
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 
681 
682 
683  #########################################################################
684  # #
685  # OUTPUT #
686  # #
687  # * Define the output directory (location and name) #
688  # * Define the output name of the library #
689  # * Add ${CAMITK_DEBUG_POSTFIX} suffix to Debug MSVC built libraries #
690  # * Additional Linux .so files information #
691  # #
692  #########################################################################
693 
694  # OUTPUT LIBRARY NAME
695  set_target_properties(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
696  PROPERTIES OUTPUT_NAME ${${TYPE_EXTENSION_CMAKE}_OUTPUT_NAME}
697  )
698 
699  # OUTPUT DIRECTORY LOCATION AND NAME
700  # Output directory (all extensions are private)
701  set_target_properties(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CAMITK_BUILD_PRIVATE_LIB_DIR}/${TYPE_EXTENSION}s
702  LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CAMITK_BUILD_PRIVATE_LIB_DIR}/${TYPE_EXTENSION}s
703  LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CAMITK_BUILD_PRIVATE_LIB_DIR}/${TYPE_EXTENSION}s
704  )
705  # Output directory (for dll plateform, this is still the same, extensions are private)
706  set_target_properties(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CAMITK_BUILD_PRIVATE_LIB_DIR}/${TYPE_EXTENSION}s
707  RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CAMITK_BUILD_PRIVATE_LIB_DIR}/${TYPE_EXTENSION}s
708  RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CAMITK_BUILD_PRIVATE_LIB_DIR}/${TYPE_EXTENSION}s
709  )
710  # Output directory (for dll plateform, this is still the same, extensions are private)
711  set_target_properties(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CAMITK_BUILD_PRIVATE_LIB_DIR}/${TYPE_EXTENSION}s
712  ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CAMITK_BUILD_PRIVATE_LIB_DIR}/${TYPE_EXTENSION}s
713  ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CAMITK_BUILD_PRIVATE_LIB_DIR}/${TYPE_EXTENSION}s
714  )
715 
716  # OUTPUT LIBRARY NAME MSVC in DEBUG mode
717  if (MSVC)
718  set_target_properties(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} PROPERTIES DEBUG_POSTFIX ${CAMITK_DEBUG_POSTFIX})
719  endif()
720 
721  # ADDITIONAL LINUX .so FILE INFORMATION
722  set(${TYPE_EXTENSION_CMAKE}_LIBRARY_PROPERTIES ${${TYPE_EXTENSION_CMAKE}_LIBRARY_PROPERTIES}
723  VERSION "${CAMITK_VERSION_MAJOR}.${CAMITK_VERSION_MINOR}.${CAMITK_VERSION_PATCH}"
724  SOVERSION "${CAMITK_VERSION_MAJOR}"
725  )
726  # set the library specific info (SONAME...)
727  set_target_properties(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} PROPERTIES ${${TYPE_EXTENSION_CMAKE}_LIBRARY_PROPERTIES} LINK_INTERFACE_LIBRARIES "")
728 
729  # see http://www.cmake.org/pipermail/cmake/2012-April/049889.html
730  # target properties (outputname and remove soname)
731  # set_property(TARGET ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} PROPERTY NO_SONAME 1)
732  # in CEP the version patch might not have been set
733  if (NOT CAMITK_VERSION_PATCH)
734  set(CAMITK_VERSION_PATCH 0)
735  endif()
736 
737 
738 
739  #########################################################################
740  # #
741  # INSTALLATION #
742  # #
743  # * When installing the project, header files (.h) and test data are #
744  # copied into a installation folder to determine. #
745  # * Indicate in this section, where to install your project and which #
746  # files to copy into that folder (during local/global installation) #
747  # #
748  #########################################################################
749 
750  # FOLDER INSTALLATION
751  # Indicate where to install the action/component
752  install(TARGETS ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
753  # TODO always use private lib, even for runtime
754  RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}/${CAMITK_SHORT_VERSION_STRING}/${TYPE_EXTENSION}s
755  LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/${CAMITK_SHORT_VERSION_STRING}/${TYPE_EXTENSION}s
756  ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/${CAMITK_SHORT_VERSION_STRING}/${TYPE_EXTENSION}s
757  COMPONENT ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
758  )
759 
760  # HEADERS INSTALLATION
761  # Build target to install provided headers to install (with HEADERS_TO_INSTALL option)
762  if(${EXTENSION_NAME_CMAKE}_HEADERS_TO_INSTALL)
763  export_headers(${${EXTENSION_NAME_CMAKE}_HEADERS_TO_INSTALL} COMPONENT ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} GROUP ${TYPE_EXTENSION}s)
764  endif()
765 
766  # Build target to install all header files(with INSTALL_ALL_HEADERS option)
767  if(${EXTENSION_NAME_CMAKE}_INSTALL_ALL_HEADERS)
768  export_headers(${${EXTENSION_NAME_CMAKE}_HEADERS} COMPONENT ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} GROUP ${TYPE_EXTENSION}s)
769  endif()
770 
771  # TESTDATA INSTALLATION
772  if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/testdata")
773  # Check test data dir directory
774  if (NOT EXISTS ${CAMITK_BUILD_TESTDATA_DIR})
775  make_directory( ${CAMITK_BUILD_TESTDATA_DIR} )
776  endif()
777 
778  # copy the files to test data directory
779  execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory testdata ${CAMITK_BUILD_TESTDATA_DIR}
780  WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
781  )
782 
783  # during installation, copy the files to install directory
784  set (TESTDATA_DEST_DIR share/${CAMITK_SHORT_VERSION_STRING}/testdata)
785  install(DIRECTORY testdata/
786  #DESTINATION share/testdata
787  #DESTINATION share/${CAMITK_SHORT_VERSION_STRING}/testdata
788  DESTINATION ${TESTDATA_DEST_DIR}
789  # COMPONENT ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
790  PATTERN ".svn" EXCLUDE
791  PATTERN "*~" EXCLUDE
792  )
793  endif()
794 
795  #########################################################################
796  # #
797  # CDASH SUBPROJECT DESCRIPTION #
798  # #
799  # * Update the XML description of the subprojects dependencies #
800  # for CDash. #
801  # #
802  #########################################################################
803  # CDASH XML SUBPROJECTS DESCRIPTION UPDATE
804  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})
805 
806 
807 
808  #########################################################################
809  # #
810  # PACKAGING CATEGORIZATION #
811  # #
812  # * On Windows, when building a package (win32 installer), the #
813  # install shield wizard proposes you to select which component #
814  # to install. #
815  # * Each component to install has a short description following its #
816  # name to understand its role. #
817  # * This section deals with the categorization and the description #
818  # of the component in this installer. #
819  # #
820  #########################################################################
821 
822  # WINDOWS INSTALLER CATEGORIZATION
823  if(${EXTENSION_NAME_CMAKE}_CEP_NAME)
824  if (${EXTENSION_NAME_CMAKE}_CEP_NAME MATCHES "SDK")
825  # The default SDK extensions are categorized as "required" and are not "unselectable" by the user at installation time
826  cpack_add_component(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
827  DISPLAY_NAME ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
828  DESCRIPTION ${${EXTENSION_NAME_CMAKE}_DESCRIPTION}
829  REQUIRED
830  GROUP SDK
831  )
832 
833  else()
834  # Extension is selectable for installation in the wizard of the installer
835  cpack_add_component(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
836  DISPLAY_NAME ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
837  DESCRIPTION ${${EXTENSION_NAME_CMAKE}_DESCRIPTION}
838  GROUP ${${EXTENSION_NAME_CMAKE}_CEP_NAME}
839  )
840  endif()
841  else()
842  # Extension if not categorized for packaging presentation
843  cpack_add_component(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
844  DISPLAY_NAME ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
845  DESCRIPTION ${${EXTENSION_NAME_CMAKE}_DESCRIPTION}
846  )
847  endif()
848 
849 
850  #####################################################################################
851  # #
852  # TRANSLATION #
853  # #
854  # * CAMITK_TRANSLATIONS contains the list of language to translate #
855  # the QString to. #
856  # #
857  # * Create the translate.pro file which contains 4 sections: #
858  # - HEADERS: list of .h/.hpp files to look for tr("") QString #
859  # - SOURCES: list of .cpp files to look for tr("") QString #
860  # - FORMS: list of .ui files to look for tr("") QString #
861  # - TRANSLATIONS: list of .ts files which use CAMITK_TRANSLATIONS #
862  # to define each .ts file #
863  # #
864  # * Execute lupdate program to update the .ts files with new QString #
865  # found. #
866  # #
867  # * Execute lrelease program to create .qm files (binary equivalent of #
868  # .ts files #
869  # #
870  # * Create translate.qrc which contains the list of .qm files. #
871  # * Create the flags.qrc file which contains the list of .png flags #
872  # images #
873  # #
874  #####################################################################################
875  if(CAMITK_TRANSLATE)
876  if(${EXTENSION_NAME_CMAKE}_EXTRA_TRANSLATE_LANGUAGE)
877  if(EXTENSION_NAME STREQUAL "application")
878  camitk_translate(USE_FLAGS
879  EXTRA_LANGUAGE ${${EXTENSION_NAME_CMAKE}_EXTRA_TRANSLATE_LANGUAGE})
880  else()
881  camitk_translate(EXTRA_LANGUAGE ${${EXTENSION_NAME_CMAKE}_EXTRA_TRANSLATE_LANGUAGE})
882  endif()
883  else()
884  if(EXTENSION_NAME STREQUAL "application")
885  camitk_translate(USE_FLAGS)
886  else()
887  camitk_translate()
888  endif()
889  endif()
890  endif()
891 
892 
893 
894  #########################################################################
895  # #
896  # CTEST - COMPONENT TESTS DESCRIPTION #
897  # #
898  #########################################################################
899 
900  # if auto test possible and required
901  if (NOT PACKAGING_NSIS AND BUILD_TESTING AND ${EXTENSION_NAME_CMAKE}_ENABLE_AUTO_TEST)
902  if(${EXTENSION_NAME_CMAKE}_COMPONENT_EXTENSION)
903  camitk_init_test( camitk-testcomponents )
904 
905  camitk_parse_test_add_separator(EXTENSION_TYPE ${TYPE_EXTENSION} EXTENSION_NAME ${EXTENSION_NAME})
906 
907  # Retrieve the files in testdata directory - a test will be applied for each of these files
908  # or use only the given files
909  if (${EXTENSION_NAME_CMAKE}_TEST_FILES)
910  # add testdata dir to filename
911  set(TESTFILES)
912  foreach(COMPONENT_TESTDATA_FILE ${${EXTENSION_NAME_CMAKE}_TEST_FILES})
913  list(APPEND TESTFILES ${CMAKE_CURRENT_SOURCE_DIR}/${COMPONENT_TESTDATA_FILE})
914  endforeach()
915  else()
916  get_subdirectoryfiles( ${CMAKE_CURRENT_SOURCE_DIR}/testdata TESTFILES )
917  endif()
918 
919  if (NOT ${EXTENSION_NAME_CMAKE}_AUTO_TEST_LEVEL)
920  # default
921  set(TESTLEVEL 3)
922  else()
923  set(TESTLEVEL ${${EXTENSION_NAME_CMAKE}_AUTO_TEST_LEVEL})
924  if (NOT ${TESTLEVEL} MATCHES "^[1-3]")
925  # default
926  message(WARNING "AUTO_TEST_LEVEL set to 3 (${TESTLEVEL} is not a valid level)")
927  set(TESTLEVEL 3)
928  else()
929  set(TESTLEVEL ${${EXTENSION_NAME_CMAKE}_AUTO_TEST_LEVEL})
930  endif()
931  endif()
932 
933  # Different the test level are done automatically:
934  # - level 1: load component extension, open & close test data
935  # - level 2: load component extension, open & close test data, save as
936  # - level 3: load component extension, open & close test data, save as and compare input with output
937  # disable some tests accordingly to options defined in camitk_extension macro arguments
938  if(TESTLEVEL STREQUAL "1")
939  set(TEST_DESCRIPTION "Test loading the extension, opening and closing the component.")
940  elseif(TESTLEVEL STREQUAL "2")
941  set(TEST_DESCRIPTION "Test loading the extension, opening the component and saving it as a file.")
942  else()
943  # level 3
944  set(TEST_DESCRIPTION "Test loading the extension, opening, saving and closing the component and comparing saved with input component.")
945  endif()
946 
947  foreach(COMPONENT_TESTDATA_FILE ${TESTFILES})
948  # Give the file name (full path)
949  get_directory_name(${COMPONENT_TESTDATA_FILE} DATA_FILE)
950 
951  # Test procedure: Open an extension and a component- save it - Compare saved file to original file(level3)
952  if(${TESTLEVEL} EQUAL 3)
953  # Level 3 = level 2 + test the output -> test level 2 + add the PASS_FILE_OUTPUT options to the test
954  camitk_add_test(EXECUTABLE_ARGS "-i ${CAMITK_BUILD_TESTDATA_DIR}/${DATA_FILE} -c ${EXTENSION_PLUGIN_FILE} -l 2"
955  PASS_FILE_OUTPUT ${CAMITK_BUILD_TESTDATA_DIR}/${DATA_FILE}
956  TEST_SUFFIX "-level3-"
957  PROJECT_NAME ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
958  )
959  endif()
960 
961  if(${TESTLEVEL} EQUAL 2)
962  camitk_add_test(EXECUTABLE_ARGS "-i ${CAMITK_BUILD_TESTDATA_DIR}/${DATA_FILE} -c ${EXTENSION_PLUGIN_FILE} -l 2"
963  TEST_SUFFIX "-level2-"
964  PROJECT_NAME ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
965  )
966  endif()
967 
968  if(${TESTLEVEL} EQUAL 1)
969  camitk_add_test(EXECUTABLE_ARGS "-i ${CAMITK_BUILD_TESTDATA_DIR}/${DATA_FILE} -c ${EXTENSION_PLUGIN_FILE} -l 1"
970  TEST_SUFFIX "-level1-"
971  PROJECT_NAME ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
972  )
973  endif()
974 
975  camitk_parse_test_add(NAME ${CAMITK_TEST_NAME} LEVEL ${TESTLEVEL} DESCRIPTION ${TEST_DESCRIPTION})
976  endforeach()
977 
978  #########################################################################
979  # #
980  # CTEST - ACTION TESTS DESCRIPTION #
981  # #
982  #########################################################################
983  # We do not apply automatic tests on actions like (close, save, save as) as they
984  # may not act directly on components
985  elseif( ${EXTENSION_NAME_CMAKE}_ACTION_EXTENSION AND NOT (${${TYPE_EXTENSION_CMAKE}_OUTPUT_NAME} MATCHES "application"))
986  camitk_init_test( camitk-testactions )
987 
988  camitk_parse_test_add_separator(EXTENSION_TYPE ${TYPE_EXTENSION} EXTENSION_NAME ${EXTENSION_NAME})
989 
990  # get the names of actions .dlls in lib directory
991  get_subdirectoryfiles( ${CAMITK_BUILD_PRIVATE_LIB_DIR}/actions/ ACTIONSDLLS )
992 
993  # Retrieve the files in testdata directory - a test will be applied for each of these files
994  # or use only the given files
995  if (${EXTENSION_NAME_CMAKE}_TEST_FILES)
996  # add testdata dir to filename
997  set(TESTFILES)
998  foreach(ACTION_TESTDATA_FILE ${${EXTENSION_NAME_CMAKE}_TEST_FILES})
999  list(APPEND TESTFILES ${CAMITK_BUILD_TESTDATA_DIR}/${ACTION_TESTDATA_FILE})
1000  endforeach()
1001  else()
1002  get_subdirectoryfiles(${CAMITK_BUILD_TESTDATA_DIR} TESTFILES)
1003  endif()
1004 
1005  foreach( ACTION_TESTDATA_FILE ${TESTFILES})
1006  # Test procedure: Open a file - load an action extension - Apply an action on the component wrapping the file
1007  camitk_add_test(EXECUTABLE_ARGS "-i ${ACTION_TESTDATA_FILE} -a ${EXTENSION_PLUGIN_FILE}"
1008  TEST_SUFFIX "-level1-"
1009  PROJECT_NAME ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
1010  )
1011  camitk_parse_test_add(NAME ${CAMITK_TEST_NAME} LEVEL 1 DESCRIPTION "Open a file, load the action and apply it on the component.")
1012  endforeach()
1013  endif()
1014  endif() # NOT PACKAGING_NSIS AND BUILD_TESTING AND ${EXTENSION_NAME_CMAKE}_ENABLE_AUTO_TEST)
1015 
1016  #########################################################################
1017  # #
1018  # CTEST - Integration test #
1019  # #
1020  #########################################################################
1021 
1022  if (NOT PACKAGING_NSIS AND BUILD_TESTING AND ${EXTENSION_NAME_CMAKE}_ENABLE_INTEGRATION_TEST)
1023  # add a specific test to run the action, save the output and compare it to expected
1024  camitk_add_integration_test()
1025  endif()
1026 
1027  endif() # ${TYPE_EXTENSION_CMAKE}_${EXTENSION_NAME_CMAKE}_ENABLED
1028 
1029 end(){)
1030 
1031 
1032 # TODO write a viewer_extension macro in CamiTK
if(${CMAKE_VERSION} VERSION_GREATER "3.3" OR ${CMAKE_VERSION} VERSION_EQUAL "3.3") option(CAMITK_INCLUDE_WHAT_YOU_USE "Enable the header analysis on you code
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
Definition: itkImageToVTKImageFilter.h:39