118 # Instruct CMake to run moc automatically when needed.
119 set(CMAKE_AUTOMOC ON)
122 #########################################################################
124 # ARGUMENTS PARSING #
126 # * Use a macro to create the CMAKE variables according to the #
127 # provided options as input. #
129 #########################################################################
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} )
139 #########################################################################
141 # CREATE CMAKE VARIABLES #
143 # * Create required and useful CMake variables
for the macro #
145 #########################################################################
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)
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)
168 set(${TYPE_EXTENSION_CMAKE}_${EXTENSION_NAME_CMAKE}_ENABLED TRUE)
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?")
174 # if this extension is enabled, do everything needed
175 # otherwise... do nothing
176 if (${${TYPE_EXTENSION_CMAKE}_${EXTENSION_NAME_CMAKE}})
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})
185 set(${TYPE_EXTENSION_CMAKE}_OUTPUT_NAME ${EXTENSION_NAME})
187 # replace "-" by "_" if the extension is being packaged with NSIS, the program to create a Windows installer.
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})
192 set(${TYPE_EXTENSION_CMAKE}_TARGET_NAME ${TYPE_EXTENSION}-${${TYPE_EXTENSION_CMAKE}_OUTPUT_NAME})
195 message(STATUS "Building extension ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
")
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
")
201 set(EXTENSION_PLUGIN_FILE ${EXTENSION_PLUGIN_FILE}/${${TYPE_EXTENSION_CMAKE}_OUTPUT_NAME}${CAMITK_DEBUG_POSTFIX}.dll)
203 set(EXTENSION_PLUGIN_FILE ${EXTENSION_PLUGIN_FILE}/lib${${TYPE_EXTENSION_CMAKE}_OUTPUT_NAME}.dylib)
206 set(EXTENSION_PLUGIN_FILE ${EXTENSION_PLUGIN_FILE}/lib${${TYPE_EXTENSION_CMAKE}_OUTPUT_NAME}.so)
209 #########################################################################
211 # INCLUDE DIRECTORIES #
213 # * Include basic directories where to look header files #
214 # * Include also additional user provided directories #
215 # * These directories are used for compilation step #
217 #########################################################################
220 include_directories(${CMAKE_CURRENT_SOURCE_DIR})
221 include_directories(${CMAKE_CURRENT_BINARY_DIR})
222 include_directories(${CAMITK_INCLUDE_DIRECTORIES})
224 # USER INPUT DIRECTORIES
225 include_directories(${${EXTENSION_NAME_CMAKE}_INCLUDE_DIRECTORIES})
229 #########################################################################
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 #
238 #########################################################################
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})
247 #########################################################################
249 # ADDITIONAL KNOWN EXTERNAL LIBRARY DEPENDENCIES #
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 #
256 #########################################################################
259 set(ITK_LIBRARIES "")
260 if(${EXTENSION_NAME_CMAKE}_NEEDS_ITK)
261 find_package(ITK REQUIRED PATHS /usr/lib/InsightToolkit)
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}
")
268 if ((${ITK_VERSION} VERSION_GREATER "4
")) # ITK 4.9 on Windows, maybe a lesser version for Linux.
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})
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)
281 set(CAMITK_ITK_LIBRARIES ${ITK_LIBRARIES})
283 message(WARNING "CamiTKExtension.cmake: ITK LIBRARY NOT SET FOR APPLE
")
286 message(FATAL_ERROR "Wrong version of ITK : ${ITK_VERSION}. Required is at least 4.x
")
289 message(FATAL_ERROR "ITK not found but required
for ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
")
294 set(LIBXML2_LIBRARY "")
295 if(${EXTENSION_NAME_CMAKE}_NEEDS_LIBXML2)
296 # LibXml2 is required
299 add_definitions(${LIBXML2_DEFINITIONS})
300 include_directories(${LIBXML2_INCLUDE_DIR})
301 set(LIBXML2_LIBRARY ${LIBXML2_LIBRARIES})
303 # most probably win32 or crosscompiling
304 message(STATUS "${EXTENSION_NAME}: libxml2 required
")
309 set(OpenCV_LIBRARIES "")
310 if(${EXTENSION_NAME_CMAKE}_NEEDS_OPENCV)
312 find_package( OpenCV REQUIRED )
314 set(OpenCV_LIBRARIES "")
318 set(IGSTK_LIBRARIES "")
319 if(${EXTENSION_NAME_CMAKE}_NEEDS_IGSTK)
320 find_package(IGSTK REQUIRED)
321 include(${IGSTK_USE_FILE})
323 set(IGSTK_LIBRARIES "")
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)
334 include_directories(${XERCESC_INCLUDE_DIR})
335 set(XERCESC_LIBRARIES ${XERCESC_LIBRARY})
337 # most probably win32 or crosscompiling
338 message(FATAL_ERROR "${EXTENSION_NAME}: xerces-c required. Please provide Xerces-C path.
")
343 if(${EXTENSION_NAME_CMAKE}_NEEDS_XSD)
344 # XercesC is required
345 if (NOT XERCESC_LIBRARY)
346 find_package(XercesC REQUIRED)
348 find_package(XercesC REQUIRED)
350 include_directories(${XERCESC_INCLUDE_DIR})
351 set(XERCESC_LIBRARIES ${XERCESC_LIBRARY})
352 find_package(XSD REQUIRED)
353 include_directories(${XSD_INCLUDE_DIR})
355 # most probably win32 or crosscompiling
356 message(FATAL_ERROR "${EXTENSION_NAME}: xerces-c required because of XSD cxx, please
set XERCESC_INCLUDE_DIR
")
362 if(${EXTENSION_NAME_CMAKE}_NEEDS_GDCM)
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)
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})
375 set(VTK_GDCM_LIB vtkgdcm)
379 # List all available GDCM library files
380 file(GLOB GDCM_LIB_FILES
381 LIST_DIRECTORIES false
388 (.*)${CAMITK_DEBUG_POSTFIX}.lib
"
389 "\\1
" GDCM_LIB_FILE_OPTIMIZED
391 # Add both debug and optimized version
392 set(GDCM_LIBRARIES ${GDCM_LIBRARIES} debug ${GDCM_LIB_FILE}
393 optimized ${GDCM_LIB_FILE_OPTIMIZED})
397 set(GDCM_LIBRARIES gdcmCommon gdcmDICT gdcmDSED gdcmMEXD gdcmMSFF ${VTK_GDCM_LIB})
400 message(FATAL_ERROR "${EXTENSION_NAME}: GDCM 2.x or above library required. Please install GDCM.
")
405 set(EXTERNAL_LIBRARIES)
406 if(${EXTENSION_NAME_CMAKE}_EXTERNAL_LIBRARIES)
407 foreach(EXTERNAL_LIBRARY ${${EXTENSION_NAME_CMAKE}_EXTERNAL_LIBRARIES})
409 list(APPEND EXTERNAL_LIBRARIES ${EXTERNAL_LIBRARIES}
410 debug ${EXTERNAL_LIBRARY}${CAMITK_DEBUG_POSTFIX}.lib
411 optimized ${EXTERNAL_LIBRARY}.lib
414 list(APPEND EXTERNAL_LIBRARIES ${EXTERNAL_LIBRARY})
421 #########################################################################
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 #
429 #########################################################################
431 # CAMITK BASIC LIB DIRECTORIES
432 link_directories(${CAMITK_LINK_DIRECTORIES})
436 #########################################################################
438 # TARGET COMPILATION DEFINITION #
440 # * Additional sources files to consider at compilation (.cpp) #
441 # * CMake project target definition #
443 #########################################################################
445 set(${EXTENSION_NAME_CMAKE}_SOURCES ${${EXTENSION_NAME_CMAKE}_SOURCES} ${${EXTENSION_NAME_CMAKE}_EXTERNAL_SOURCES})
447 # CMAKE TARGET DEFINITION
448 add_library(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} SHARED ${${EXTENSION_NAME_CMAKE}_SOURCES})
452 #########################################################################
454 # QT LINKING LIBRARIES #
456 # * Set at linking the Qt5 libraries #
458 #########################################################################
459 target_link_libraries(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} ${CAMITK_QT_LIBRARIES})
462 #########################################################################
464 # CAMITK ACTION / COMPONENT / LIBRARIES DEPENDENCIES #
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 #
472 #########################################################################
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
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})
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})
495 list(APPEND COMPONENT_EXTENSION_LIBRARIES debug ${CAMITK_BUILD_PRIVATE_LIB_DIR}/components/${COMPONENT_NEEDED}${CAMITK_DEBUG_POSTFIX}.lib
496 optimized ${COMPONENT_NEEDED}
499 list(APPEND COMPONENT_EXTENSION_LIBRARIES ${COMPONENT_NEEDED})
501 # CMake / CDash dependencies
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)
508 add_dependencies(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} component_${COMPONENT_NEEDED})
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)
514 add_dependencies(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} component-${COMPONENT_NEEDED})
515 list(APPEND COMPONENTS_DEPENDENCY_LIST component-${COMPONENT_NEEDED})
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})
529 list(APPEND ACTION_EXTENSION_LIBRARIES debug ${CAMITK_BUILD_PRIVATE_LIB_DIR}/actions/${ACTION_NEEDED}${CAMITK_DEBUG_POSTFIX}.lib
530 optimized ${ACTION_NEEDED}
533 list(APPEND ACTION_EXTENSION_LIBRARIES ${ACTION_NEEDED})
535 # CMake / CDash dependencies
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)
542 add_dependencies(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} action_${ACTION_NEEDED})
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)
549 add_dependencies(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} action-${ACTION_NEEDED})
550 list(APPEND ACTIONS_DEPENDENCY_LIST action-${ACTION_NEEDED})
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})
564 list(APPEND VIEWER_EXTENSION_LIBRARIES debug ${CAMITK_BUILD_PRIVATE_LIB_DIR}/viewers/${VIEWER_NEEDED}${CAMITK_DEBUG_POSTFIX}.lib
565 optimized ${VIEWER_NEEDED}
568 list(APPEND VIEWER_EXTENSION_LIBRARIES ${VIEWER_NEEDED})
570 # CMake / CDash dependencies
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)
576 # now add the dependency
577 add_dependencies(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} viewer_${VIEWER_NEEDED})
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)
584 add_dependencies(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} viewer-${VIEWER_NEEDED})
585 list(APPEND VIEWERS_DEPENDENCY_LIST viewer-${VIEWER_NEEDED})
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})
599 list(APPEND CEP_LIBRARIES debug ${CEP_LIBRARY_NEEDED}${CAMITK_DEBUG_POSTFIX}.lib
600 optimized ${CEP_LIBRARY_NEEDED}
603 list(APPEND CEP_LIBRARIES ${CEP_LIBRARY_NEEDED})
605 # CMake / CDash dependencies
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)
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})
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)
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})
633 #########################################################################
637 # * Flags are options to give to the compiler #
638 # * Add user input flags #
639 # * Add platform specific flags #
641 #########################################################################
643 # USER INPUT DEFINES COMPILER FLAG
644 if(${EXTENSION_NAME_CMAKE}_DEFINES)
645 foreach (FLAG ${${EXTENSION_NAME_CMAKE}_DEFINES})
646 add_definitions(-D${FLAG})
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}
")
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)
669 #########################################################################
673 # * Linking is the last stage of compilation #
674 # * Indicate what libraries to use for linking the target #
676 #########################################################################
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})
683 #########################################################################
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 #
692 #########################################################################
694 # OUTPUT LIBRARY NAME
695 set_target_properties(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
696 PROPERTIES OUTPUT_NAME ${${TYPE_EXTENSION_CMAKE}_OUTPUT_NAME}
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
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
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
716 # OUTPUT LIBRARY NAME MSVC in DEBUG mode
718 set_target_properties(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} PROPERTIES DEBUG_POSTFIX ${CAMITK_DEBUG_POSTFIX})
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}
"
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 "")
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)
739 #########################################################################
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) #
748 #########################################################################
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}
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)
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)
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} )
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}
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
795 #########################################################################
797 # CDASH SUBPROJECT DESCRIPTION #
799 # * Update the XML description of the subprojects dependencies #
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})
808 #########################################################################
810 # PACKAGING CATEGORIZATION #
812 # * On Windows, when building a package (win32 installer), the #
813 # install shield wizard proposes you to select which component #
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. #
820 #########################################################################
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}
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}
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}
850 #####################################################################################
854 # * CAMITK_TRANSLATIONS contains the list of language to translate #
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 #
864 # * Execute lupdate program to update the .ts files with new QString #
867 # * Execute lrelease program to create .qm files (binary equivalent of #
870 # * Create translate.qrc which contains the list of .qm files. #
871 # * Create the flags.qrc file which contains the list of .png flags #
874 #####################################################################################
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})
881 camitk_translate(EXTRA_LANGUAGE ${${EXTENSION_NAME_CMAKE}_EXTRA_TRANSLATE_LANGUAGE})
884 if(EXTENSION_NAME STREQUAL "application
")
885 camitk_translate(USE_FLAGS)
894 #########################################################################
896 # CTEST - COMPONENT TESTS DESCRIPTION #
898 #########################################################################
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 )
905 camitk_parse_test_add_separator(EXTENSION_TYPE ${TYPE_EXTENSION} EXTENSION_NAME ${EXTENSION_NAME})
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
912 foreach(COMPONENT_TESTDATA_FILE ${${EXTENSION_NAME_CMAKE}_TEST_FILES})
913 list(APPEND TESTFILES ${CMAKE_CURRENT_SOURCE_DIR}/${COMPONENT_TESTDATA_FILE})
916 get_subdirectoryfiles( ${CMAKE_CURRENT_SOURCE_DIR}/testdata TESTFILES )
919 if (NOT ${EXTENSION_NAME_CMAKE}_AUTO_TEST_LEVEL)
923 set(TESTLEVEL ${${EXTENSION_NAME_CMAKE}_AUTO_TEST_LEVEL})
924 if (NOT ${TESTLEVEL} MATCHES "^[1-3]
")
926 message(WARNING "AUTO_TEST_LEVEL
set to 3 (${TESTLEVEL} is not
a valid level)
")
929 set(TESTLEVEL ${${EXTENSION_NAME_CMAKE}_AUTO_TEST_LEVEL})
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.
")
944 set(TEST_DESCRIPTION "Test loading the extension, opening, saving and closing the component and comparing saved with input component.
")
947 foreach(COMPONENT_TESTDATA_FILE ${TESTFILES})
948 # Give the file name (full path)
949 get_directory_name(${COMPONENT_TESTDATA_FILE} DATA_FILE)
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}
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}
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}
975 camitk_parse_test_add(NAME ${CAMITK_TEST_NAME} LEVEL ${TESTLEVEL} DESCRIPTION ${TEST_DESCRIPTION})
978 #########################################################################
980 # CTEST - ACTION TESTS DESCRIPTION #
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 )
988 camitk_parse_test_add_separator(EXTENSION_TYPE ${TYPE_EXTENSION} EXTENSION_NAME ${EXTENSION_NAME})
990 # get the names of actions .dlls in lib directory
991 get_subdirectoryfiles( ${CAMITK_BUILD_PRIVATE_LIB_DIR}/actions/ ACTIONSDLLS )
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
998 foreach(ACTION_TESTDATA_FILE ${${EXTENSION_NAME_CMAKE}_TEST_FILES})
999 list(APPEND TESTFILES ${CAMITK_BUILD_TESTDATA_DIR}/${ACTION_TESTDATA_FILE})
1002 get_subdirectoryfiles(${CAMITK_BUILD_TESTDATA_DIR} TESTFILES)
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}
1011 camitk_parse_test_add(NAME ${CAMITK_TEST_NAME} LEVEL 1 DESCRIPTION "Open
a file, load the action and apply it on the component.
")
1014 endif() # NOT PACKAGING_NSIS AND BUILD_TESTING AND ${EXTENSION_NAME_CMAKE}_ENABLE_AUTO_TEST)
1016 #########################################################################
1018 # CTEST - Integration test #
1020 #########################################################################
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()
1027 endif() # ${TYPE_EXTENSION_CMAKE}_${EXTENSION_NAME_CMAKE}_ENABLED
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
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