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})
371 # List all available GDCM library files
372 file(GLOB GDCM_LIB_FILES
373 LIST_DIRECTORIES false
380 (.*)${CAMITK_DEBUG_POSTFIX}.lib
"
381 "\\1
" GDCM_LIB_FILE_OPTIMIZED
383 # Add both debug and optimized version
384 set(GDCM_LIBRARIES ${GDCM_LIBRARIES} debug ${GDCM_LIB_FILE}
385 optimized ${GDCM_LIB_FILE_OPTIMIZED})
389 set(GDCM_LIBRARIES gdcmCommon gdcmDICT gdcmDSED gdcmMEXD gdcmMSFF vtkgdcm)
392 message(FATAL_ERROR "${EXTENSION_NAME}: GDCM 2.x or above library required. Please install GDCM.
")
397 set(EXTERNAL_LIBRARIES)
398 if(${EXTENSION_NAME_CMAKE}_EXTERNAL_LIBRARIES)
399 foreach(EXTERNAL_LIBRARY ${${EXTENSION_NAME_CMAKE}_EXTERNAL_LIBRARIES})
401 list(APPEND EXTERNAL_LIBRARIES ${EXTERNAL_LIBRARIES}
402 debug ${EXTERNAL_LIBRARY}${CAMITK_DEBUG_POSTFIX}.lib
403 optimized ${EXTERNAL_LIBRARY}.lib
406 list(APPEND EXTERNAL_LIBRARIES ${EXTERNAL_LIBRARY})
413 #########################################################################
417 # * Link directories are used to indicate the compiler where #
418 # to look for folder containing libraries to link with. #
419 # * Must be done BEFORE creating the CMake target with add_library #
421 #########################################################################
423 # CAMITK BASIC LIB DIRECTORIES
424 link_directories(${CAMITK_LINK_DIRECTORIES})
428 #########################################################################
430 # TARGET COMPILATION DEFINITION #
432 # * Additional sources files to consider at compilation (.cpp) #
433 # * CMake project target definition #
435 #########################################################################
437 set(${EXTENSION_NAME_CMAKE}_SOURCES ${${EXTENSION_NAME_CMAKE}_SOURCES} ${${EXTENSION_NAME_CMAKE}_EXTERNAL_SOURCES})
439 # CMAKE TARGET DEFINITION
440 add_library(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} SHARED ${${EXTENSION_NAME_CMAKE}_SOURCES})
444 #########################################################################
446 # QT LINKING LIBRARIES #
448 # * Set at linking the Qt5 libraries #
450 #########################################################################
451 target_link_libraries(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} ${CAMITK_QT_LIBRARIES})
454 #########################################################################
456 # CAMITK ACTION / COMPONENT / LIBRARIES DEPENDENCIES #
458 # * Look for action / component / libraries dependencies #
459 # * Specific actions / components / libraries are specified as option #
460 # with the NEEDS_ACTION/COMPONENT_EXTENSION/CEP_LIBRARIES syntax #
461 # * Add dependencies to library-camitkcore and the testing #
462 # action/component if test are runned on it #
464 #########################################################################
466 # 1st CAMITKCORE LIBRARY DEPENDENCY
467 # add_dependencies(..) is only needed to enable parallel build during SDK build
468 # but generates an error for external CEP, where this target does not
470 # Using target_link_libraries(..) is enough to link the extension to the CamiTK core library
471 if(CAMITK_COMMUNITY_EDITION_BUILD)
472 add_dependencies(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} ${CAMITK_CORE_TARGET_LIB_NAME})
473 # add the dependency to the core automoc target only if inside a SDK build
474 set_property(TARGET ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} APPEND PROPERTY AUTOGEN_TARGET_DEPENDS ${CAMITK_CORE_TARGET_LIB_NAME})
478 # 2nd COMPONENTS DEPENDENCIES
479 if(${EXTENSION_NAME_CMAKE}_NEEDS_COMPONENT_EXTENSION)
480 set(COMPONENTS_DEPENDENCY_LIST "") #use for generating the project.xml file
481 foreach(COMPONENT_NEEDED ${${EXTENSION_NAME_CMAKE}_NEEDS_COMPONENT_EXTENSION})
482 # include directories from build, camitk (local or global install).
483 include_directories(${CAMITK_BUILD_INCLUDE_DIR}/components/${COMPONENT_NEEDED})
484 include_directories(${CAMITK_INCLUDE_DIR}/components/${COMPONENT_NEEDED})
487 list(APPEND COMPONENT_EXTENSION_LIBRARIES debug ${CAMITK_BUILD_PRIVATE_LIB_DIR}/components/${COMPONENT_NEEDED}${CAMITK_DEBUG_POSTFIX}.lib
488 optimized ${COMPONENT_NEEDED}
491 list(APPEND COMPONENT_EXTENSION_LIBRARIES ${COMPONENT_NEEDED})
493 # CMake / CDash dependencies
495 # if the target is installed in the CAMITK_INCLUDE_DIR, import it before adding the dependencies
496 if(EXISTS ${CAMITK_INCLUDE_DIR}/components/${COMPONENT_NEEDED} AND NOT TARGET component_${COMPONENT_NEEDED})
497 message(STATUS "Importing target component_${COMPONENT_NEEDED}
")
498 add_library(component_${COMPONENT_NEEDED} INTERFACE IMPORTED)
500 add_dependencies(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} component_${COMPONENT_NEEDED})
502 if(EXISTS ${CAMITK_INCLUDE_DIR}/components/${COMPONENT_NEEDED} AND NOT TARGET component-${COMPONENT_NEEDED})
503 message(STATUS "Importing target component-${COMPONENT_NEEDED}
")
504 add_library(component-${COMPONENT_NEEDED} INTERFACE IMPORTED)
506 add_dependencies(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} component-${COMPONENT_NEEDED})
507 list(APPEND COMPONENTS_DEPENDENCY_LIST component-${COMPONENT_NEEDED})
512 # 3rd ACTIONS DEPENDENCIES
513 if(${EXTENSION_NAME_CMAKE}_NEEDS_ACTION_EXTENSION)
514 set(ACTIONS_DEPENDENCY_LIST "") #use for generating the project.xml file
515 foreach(ACTION_NEEDED ${${EXTENSION_NAME_CMAKE}_NEEDS_ACTION_EXTENSION})
516 # include directories from build, camitk (local or global install).
517 include_directories(${CAMITK_BUILD_INCLUDE_DIR}/actions/${ACTION_NEEDED})
518 include_directories(${CAMITK_INCLUDE_DIR}/actions/${ACTION_NEEDED})
521 list(APPEND ACTION_EXTENSION_LIBRARIES debug ${CAMITK_BUILD_PRIVATE_LIB_DIR}/actions/${ACTION_NEEDED}${CAMITK_DEBUG_POSTFIX}.lib
522 optimized ${ACTION_NEEDED}
525 list(APPEND ACTION_EXTENSION_LIBRARIES ${ACTION_NEEDED})
527 # CMake / CDash dependencies
529 # if the target is installed in the CAMITK_INCLUDE_DIR, import it before adding the dependencies
530 if(EXISTS ${CAMITK_INCLUDE_DIR}/actions/${ACTION_NEEDED} AND NOT TARGET action_${ACTION_NEEDED})
531 message(STATUS "Importing target action_${ACTION_NEEDED}
")
532 add_library(action_${ACTION_NEEDED} INTERFACE IMPORTED)
534 add_dependencies(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} action_${ACTION_NEEDED})
536 # if the target is installed in the CAMITK_INCLUDE_DIR, import it before adding the dependencies
537 if(EXISTS ${CAMITK_INCLUDE_DIR}/actions/${ACTION_NEEDED} AND NOT TARGET action-${ACTION_NEEDED})
538 message(STATUS "Importing target action-${ACTION_NEEDED}
")
539 add_library(action-${ACTION_NEEDED} INTERFACE IMPORTED)
541 add_dependencies(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} action-${ACTION_NEEDED})
542 list(APPEND ACTIONS_DEPENDENCY_LIST action-${ACTION_NEEDED})
547 # 4th VIEWERS DEPENDENCIES
548 if(${EXTENSION_NAME_CMAKE}_NEEDS_VIEWER_EXTENSION)
549 set(VIEWERS_DEPENDENCY_LIST "") #use for generating the project.xml file
550 foreach(VIEWER_NEEDED ${${EXTENSION_NAME_CMAKE}_NEEDS_VIEWER_EXTENSION})
551 # include directories from build, camitk (local or global install).
552 include_directories(${CAMITK_BUILD_INCLUDE_DIR}/viewers/${VIEWER_NEEDED})
553 include_directories(${CAMITK_INCLUDE_DIR}/viewers/${VIEWER_NEEDED})
556 list(APPEND VIEWER_EXTENSION_LIBRARIES debug ${CAMITK_BUILD_PRIVATE_LIB_DIR}/viewers/${VIEWER_NEEDED}${CAMITK_DEBUG_POSTFIX}.lib
557 optimized ${VIEWER_NEEDED}
560 list(APPEND VIEWER_EXTENSION_LIBRARIES ${VIEWER_NEEDED})
562 # CMake / CDash dependencies
564 if(EXISTS ${CAMITK_INCLUDE_DIR}/viewers/${VIEWER_NEEDED} AND NOT TARGET viewer_${VIEWER_NEEDED})
565 message(STATUS "Importing target viewer_${VIEWER_NEEDED}
")
566 add_library(viewer_${VIEWER_NEEDED} INTERFACE IMPORTED)
568 # now add the dependency
569 add_dependencies(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} viewer_${VIEWER_NEEDED})
571 # if the target is installed in the CAMITK_INCLUDE_DIR, import it before adding the 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 add_dependencies(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} viewer-${VIEWER_NEEDED})
577 list(APPEND VIEWERS_DEPENDENCY_LIST viewer-${VIEWER_NEEDED})
582 # 5th CEP LIBRARIES DEPENDENCIES
583 if(${EXTENSION_NAME_CMAKE}_NEEDS_CEP_LIBRARIES)
584 set(CEP_LIBRARIES_DEPENDENCY_LIST "") #use for generating the project.xml file
585 foreach(CEP_LIBRARY_NEEDED ${${EXTENSION_NAME_CMAKE}_NEEDS_CEP_LIBRARIES})
586 # include directories from build, camitk (local or global install).
587 include_directories(${CAMITK_BUILD_INCLUDE_DIR}/libraries/${CEP_LIBRARY_NEEDED})
588 include_directories(${CAMITK_INCLUDE_DIR}/libraries/${CEP_LIBRARY_NEEDED})
591 list(APPEND CEP_LIBRARIES debug ${CEP_LIBRARY_NEEDED}${CAMITK_DEBUG_POSTFIX}.lib
592 optimized ${CEP_LIBRARY_NEEDED}
595 list(APPEND CEP_LIBRARIES ${CEP_LIBRARY_NEEDED})
597 # CMake / CDash dependencies
599 if (EXISTS ${CAMITK_INCLUDE_DIR}/libraries/${CEP_LIBRARY_NEEDED} AND NOT TARGET library_${CEP_LIBRARY_NEEDED})
600 message(STATUS "Importing target library_${CEP_LIBRARY_NEEDED}
")
601 add_library(library_${CEP_LIBRARY_NEEDED} INTERFACE IMPORTED)
603 # now add the dependency
604 add_dependencies(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} library_${CEP_LIBRARY_NEEDED})
605 # add the dependency to the component automoc target only if compiling SDK
606 #if(CAMITK_COMMUNITY_EDITION_BUILD)
607 #set_property(TARGET ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} APPEND PROPERTY AUTOGEN_TARGET_DEPENDS library_${CEP_LIBRARY_NEEDED})
610 # if the target is installed in the CAMITK_INCLUDE_DIR, import it before adding the dependencies
611 if (EXISTS ${CAMITK_INCLUDE_DIR}/libraries/${CEP_LIBRARY_NEEDED} AND NOT TARGET library-${CEP_LIBRARY_NEEDED})
612 message(STATUS "Importing target library-${CEP_LIBRARY_NEEDED}
")
613 add_library(library-${CEP_LIBRARY_NEEDED} INTERFACE IMPORTED)
615 add_dependencies(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} library-${CEP_LIBRARY_NEEDED})
616 list(APPEND CEP_LIBRARIES_DEPENDENCY_LIST ${CEP_LIBRARY_NEEDED} library-${CEP_LIBRARY_NEEDED})
617 ## add the dependency to the component automoc target only if compiling SDK
618 #if(CAMITK_COMMUNITY_EDITION_BUILD)
619 #set_property(TARGET ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} APPEND PROPERTY AUTOGEN_TARGET_DEPENDS library-${CEP_LIBRARY_NEEDED})
625 #########################################################################
629 # * Flags are options to give to the compiler #
630 # * Add user input flags #
631 # * Add platform specific flags #
633 #########################################################################
635 # USER INPUT DEFINES COMPILER FLAG
636 if(${EXTENSION_NAME_CMAKE}_DEFINES)
637 foreach (FLAG ${${EXTENSION_NAME_CMAKE}_DEFINES})
638 add_definitions(-D${FLAG})
642 # USER INPUT CUSTOM COMPILER FLAG
643 if(${EXTENSION_NAME_CMAKE}_CXX_FLAGS)
644 foreach (FLAG ${${EXTENSION_NAME_CMAKE}_CXX_FLAGS})
645 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAG}
")
649 # PLATFORM SPECIFIC COMPILER FLAG
650 # 64bits and other platform with relocation needs -fPIC
651 include(TestCXXAcceptsFlag)
652 check_cxx_accepts_flag(-fPIC FPIC_FLAG_ACCEPTED)
653 # no need to add -fPIC on mingw, otherwise it generates a warning: -fPIC ignored for target (all code is position independent) [enabled by default]
654 # msvc is also accepting the flag, but then produce warning D9002 : ignoring unknown option '-fPIC' cl
655 if(FPIC_FLAG_ACCEPTED AND NOT WIN32)
656 set_property(TARGET ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} APPEND PROPERTY COMPILE_FLAGS -fPIC)
661 #########################################################################
665 # * Linking is the last stage of compilation #
666 # * Indicate what libraries to use for linking the target #
668 #########################################################################
670 # Any component or action has to be linked with ${CAMITK_CORE_LIBRARIES} and with all its dependencies
671 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})
675 #########################################################################
679 # * Define the output directory (location and name) #
680 # * Define the output name of the library #
681 # * Add ${CAMITK_DEBUG_POSTFIX} suffix to Debug MSVC built libraries #
682 # * Additional Linux .so files information #
684 #########################################################################
686 # OUTPUT LIBRARY NAME
687 set_target_properties(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
688 PROPERTIES OUTPUT_NAME ${${TYPE_EXTENSION_CMAKE}_OUTPUT_NAME}
691 # OUTPUT DIRECTORY LOCATION AND NAME
692 # Output directory (all extensions are private)
693 set_target_properties(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CAMITK_BUILD_PRIVATE_LIB_DIR}/${TYPE_EXTENSION}s
694 LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CAMITK_BUILD_PRIVATE_LIB_DIR}/${TYPE_EXTENSION}s
695 LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CAMITK_BUILD_PRIVATE_LIB_DIR}/${TYPE_EXTENSION}s
697 # Output directory (for dll plateform, this is still the same, extensions are private)
698 set_target_properties(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CAMITK_BUILD_PRIVATE_LIB_DIR}/${TYPE_EXTENSION}s
699 RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CAMITK_BUILD_PRIVATE_LIB_DIR}/${TYPE_EXTENSION}s
700 RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CAMITK_BUILD_PRIVATE_LIB_DIR}/${TYPE_EXTENSION}s
702 # Output directory (for dll plateform, this is still the same, extensions are private)
703 set_target_properties(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CAMITK_BUILD_PRIVATE_LIB_DIR}/${TYPE_EXTENSION}s
704 ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CAMITK_BUILD_PRIVATE_LIB_DIR}/${TYPE_EXTENSION}s
705 ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CAMITK_BUILD_PRIVATE_LIB_DIR}/${TYPE_EXTENSION}s
708 # OUTPUT LIBRARY NAME MSVC in DEBUG mode
710 set_target_properties(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} PROPERTIES DEBUG_POSTFIX ${CAMITK_DEBUG_POSTFIX})
713 # ADDITIONAL LINUX .so FILE INFORMATION
714 set(${TYPE_EXTENSION_CMAKE}_LIBRARY_PROPERTIES ${${TYPE_EXTENSION_CMAKE}_LIBRARY_PROPERTIES}
715 VERSION "${CAMITK_VERSION_MAJOR}.${CAMITK_VERSION_MINOR}.${CAMITK_VERSION_PATCH}
"
716 SOVERSION "${CAMITK_VERSION_MAJOR}
"
718 # set the library specific info (SONAME...)
719 set_target_properties(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} PROPERTIES ${${TYPE_EXTENSION_CMAKE}_LIBRARY_PROPERTIES} LINK_INTERFACE_LIBRARIES "")
721 # see http://www.cmake.org/pipermail/cmake/2012-April/049889.html
722 # target properties (outputname and remove soname)
723 # set_property(TARGET ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} PROPERTY NO_SONAME 1)
724 # in CEP the version patch might not have been set
725 if (NOT CAMITK_VERSION_PATCH)
726 set(CAMITK_VERSION_PATCH 0)
731 #########################################################################
735 # * When installing the project, header files (.h) and test data are #
736 # copied into a installation folder to determine. #
737 # * Indicate in this section, where to install your project and which #
738 # files to copy into that folder (during local/global installation) #
740 #########################################################################
742 # FOLDER INSTALLATION
743 # Indicate where to install the action/component
744 install(TARGETS ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
745 # TODO always use private lib, even for runtime
746 RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}/${CAMITK_SHORT_VERSION_STRING}/${TYPE_EXTENSION}s
747 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/${CAMITK_SHORT_VERSION_STRING}/${TYPE_EXTENSION}s
748 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/${CAMITK_SHORT_VERSION_STRING}/${TYPE_EXTENSION}s
749 COMPONENT ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
752 # HEADERS INSTALLATION
753 # Build target to install provided headers to install (with HEADERS_TO_INSTALL option)
754 if(${EXTENSION_NAME_CMAKE}_HEADERS_TO_INSTALL)
755 export_headers(${${EXTENSION_NAME_CMAKE}_HEADERS_TO_INSTALL} COMPONENT ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} GROUP ${TYPE_EXTENSION}s)
758 # Build target to install all header files(with INSTALL_ALL_HEADERS option)
759 if(${EXTENSION_NAME_CMAKE}_INSTALL_ALL_HEADERS)
760 export_headers(${${EXTENSION_NAME_CMAKE}_HEADERS} COMPONENT ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} GROUP ${TYPE_EXTENSION}s)
763 # TESTDATA INSTALLATION
764 if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/testdata
")
765 # Check test data dir directory
766 if (NOT EXISTS ${CAMITK_BUILD_TESTDATA_DIR})
767 make_directory( ${CAMITK_BUILD_TESTDATA_DIR} )
770 # copy the files to test data directory
771 execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory testdata ${CAMITK_BUILD_TESTDATA_DIR}
772 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
775 # during installation, copy the files to install directory
776 set (TESTDATA_DEST_DIR share/${CAMITK_SHORT_VERSION_STRING}/testdata)
777 install(DIRECTORY testdata/
778 #DESTINATION share/testdata
779 #DESTINATION share/${CAMITK_SHORT_VERSION_STRING}/testdata
780 DESTINATION ${TESTDATA_DEST_DIR}
781 # COMPONENT ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
782 PATTERN ".svn
" EXCLUDE
787 #########################################################################
789 # CDASH SUBPROJECT DESCRIPTION #
791 # * Update the XML description of the subprojects dependencies #
794 #########################################################################
795 # CDASH XML SUBPROJECTS DESCRIPTION UPDATE
796 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})
800 #########################################################################
802 # PACKAGING CATEGORIZATION #
804 # * On Windows, when building a package (win32 installer), the #
805 # install shield wizard proposes you to select which component #
807 # * Each component to install has a short description following its #
808 # name to understand its role. #
809 # * This section deals with the categorization and the description #
810 # of the component in this installer. #
812 #########################################################################
814 # WINDOWS INSTALLER CATEGORIZATION
815 if(${EXTENSION_NAME_CMAKE}_CEP_NAME)
816 if (${EXTENSION_NAME_CMAKE}_CEP_NAME MATCHES "SDK
")
817 # The default SDK extensions are categorized as "required
" and are not "unselectable
" by the user at installation time
818 cpack_add_component(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
819 DISPLAY_NAME ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
820 DESCRIPTION ${${EXTENSION_NAME_CMAKE}_DESCRIPTION}
826 # Extension is selectable for installation in the wizard of the installer
827 cpack_add_component(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
828 DISPLAY_NAME ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
829 DESCRIPTION ${${EXTENSION_NAME_CMAKE}_DESCRIPTION}
830 GROUP ${${EXTENSION_NAME_CMAKE}_CEP_NAME}
834 # Extension if not categorized for packaging presentation
835 cpack_add_component(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
836 DISPLAY_NAME ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
837 DESCRIPTION ${${EXTENSION_NAME_CMAKE}_DESCRIPTION}
842 #####################################################################################
846 # * CAMITK_TRANSLATIONS contains the list of language to translate #
849 # * Create the translate.pro file which contains 4 sections: #
850 # - HEADERS: list of .h/.hpp files to look for tr("") QString #
851 # - SOURCES: list of .cpp files to look for tr("") QString #
852 # - FORMS: list of .ui files to look for tr("") QString #
853 # - TRANSLATIONS: list of .ts files which use CAMITK_TRANSLATIONS #
854 # to define each .ts file #
856 # * Execute lupdate program to update the .ts files with new QString #
859 # * Execute lrelease program to create .qm files (binary equivalent of #
862 # * Create translate.qrc which contains the list of .qm files. #
863 # * Create the flags.qrc file which contains the list of .png flags #
866 #####################################################################################
868 if(${EXTENSION_NAME_CMAKE}_EXTRA_TRANSLATE_LANGUAGE)
869 if(EXTENSION_NAME STREQUAL "application
")
870 camitk_translate(USE_FLAGS
871 EXTRA_LANGUAGE ${${EXTENSION_NAME_CMAKE}_EXTRA_TRANSLATE_LANGUAGE})
873 camitk_translate(EXTRA_LANGUAGE ${${EXTENSION_NAME_CMAKE}_EXTRA_TRANSLATE_LANGUAGE})
876 if(EXTENSION_NAME STREQUAL "application
")
877 camitk_translate(USE_FLAGS)
886 #########################################################################
888 # CTEST - COMPONENT TESTS DESCRIPTION #
890 #########################################################################
892 # if auto test possible and required
893 if (NOT PACKAGING_NSIS AND BUILD_TESTING AND ${EXTENSION_NAME_CMAKE}_ENABLE_AUTO_TEST)
894 if(${EXTENSION_NAME_CMAKE}_COMPONENT_EXTENSION)
895 camitk_init_test( camitk-testcomponents )
897 camitk_parse_test_add_separator(EXTENSION_TYPE ${TYPE_EXTENSION} EXTENSION_NAME ${EXTENSION_NAME})
899 # Retrieve the files in testdata directory - a test will be applied for each of these files
900 # or use only the given files
901 if (${EXTENSION_NAME_CMAKE}_TEST_FILES)
902 # add testdata dir to filename
904 foreach(COMPONENT_TESTDATA_FILE ${${EXTENSION_NAME_CMAKE}_TEST_FILES})
905 list(APPEND TESTFILES ${CMAKE_CURRENT_SOURCE_DIR}/${COMPONENT_TESTDATA_FILE})
908 get_subdirectoryfiles( ${CMAKE_CURRENT_SOURCE_DIR}/testdata TESTFILES )
911 if (NOT ${EXTENSION_NAME_CMAKE}_AUTO_TEST_LEVEL)
915 set(TESTLEVEL ${${EXTENSION_NAME_CMAKE}_AUTO_TEST_LEVEL})
916 if (NOT ${TESTLEVEL} MATCHES "^[1-3]
")
918 message(WARNING "AUTO_TEST_LEVEL
set to 3 (${TESTLEVEL} is not
a valid level)
")
921 set(TESTLEVEL ${${EXTENSION_NAME_CMAKE}_AUTO_TEST_LEVEL})
925 # Different the test level are done automatically:
926 # - level 1: load component extension, open & close test data
927 # - level 2: load component extension, open & close test data, save as
928 # - level 3: load component extension, open & close test data, save as and compare input with output
929 # disable some tests accordingly to options defined in camitk_extension macro arguments
930 if(TESTLEVEL STREQUAL "1
")
931 set(TEST_DESCRIPTION "Test loading the extension, opening and closing the component.
")
932 elseif(TESTLEVEL STREQUAL "2
")
933 set(TEST_DESCRIPTION "Test loading the extension, opening the component and saving it as
a file.
")
936 set(TEST_DESCRIPTION "Test loading the extension, opening, saving and closing the component and comparing saved with input component.
")
939 foreach(COMPONENT_TESTDATA_FILE ${TESTFILES})
940 # Give the file name (full path)
941 get_directory_name(${COMPONENT_TESTDATA_FILE} DATA_FILE)
943 # Test procedure: Open an extension and a component- save it - Compare saved file to original file(level3)
944 if(${TESTLEVEL} EQUAL 3)
945 # Level 3 = level 2 + test the output -> test level 2 + add the PASS_FILE_OUTPUT options to the test
946 camitk_add_test(EXECUTABLE_ARGS "-i ${CAMITK_BUILD_TESTDATA_DIR}/${DATA_FILE} -c ${EXTENSION_PLUGIN_FILE} -l 2
"
947 PASS_FILE_OUTPUT ${CAMITK_BUILD_TESTDATA_DIR}/${DATA_FILE}
948 TEST_SUFFIX "-level3-
"
949 PROJECT_NAME ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
953 if(${TESTLEVEL} EQUAL 2)
954 camitk_add_test(EXECUTABLE_ARGS "-i ${CAMITK_BUILD_TESTDATA_DIR}/${DATA_FILE} -c ${EXTENSION_PLUGIN_FILE} -l 2
"
955 TEST_SUFFIX "-level2-
"
956 PROJECT_NAME ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
960 if(${TESTLEVEL} EQUAL 1)
961 camitk_add_test(EXECUTABLE_ARGS "-i ${CAMITK_BUILD_TESTDATA_DIR}/${DATA_FILE} -c ${EXTENSION_PLUGIN_FILE} -l 1
"
962 TEST_SUFFIX "-level1-
"
963 PROJECT_NAME ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
967 camitk_parse_test_add(NAME ${CAMITK_TEST_NAME} LEVEL ${TESTLEVEL} DESCRIPTION ${TEST_DESCRIPTION})
970 #########################################################################
972 # CTEST - ACTION TESTS DESCRIPTION #
974 #########################################################################
975 # We do not apply automatic tests on actions like (close, save, save as) as they
976 # may not act directly on components
977 elseif( ${EXTENSION_NAME_CMAKE}_ACTION_EXTENSION AND NOT (${${TYPE_EXTENSION_CMAKE}_OUTPUT_NAME} MATCHES "application
"))
978 camitk_init_test( camitk-testactions )
980 camitk_parse_test_add_separator(EXTENSION_TYPE ${TYPE_EXTENSION} EXTENSION_NAME ${EXTENSION_NAME})
982 # get the names of actions .dlls in lib directory
983 get_subdirectoryfiles( ${CAMITK_BUILD_PRIVATE_LIB_DIR}/actions/ ACTIONSDLLS )
985 # Retrieve the files in testdata directory - a test will be applied for each of these files
986 # or use only the given files
987 if (${EXTENSION_NAME_CMAKE}_TEST_FILES)
988 # add testdata dir to filename
990 foreach(ACTION_TESTDATA_FILE ${${EXTENSION_NAME_CMAKE}_TEST_FILES})
991 list(APPEND TESTFILES ${CAMITK_BUILD_TESTDATA_DIR}/${ACTION_TESTDATA_FILE})
994 get_subdirectoryfiles(${CAMITK_BUILD_TESTDATA_DIR} TESTFILES)
997 foreach( ACTION_TESTDATA_FILE ${TESTFILES})
998 # Test procedure: Open a file - load an action extension - Apply an action on the component wrapping the file
999 camitk_add_test(EXECUTABLE_ARGS "-i ${ACTION_TESTDATA_FILE} -
a ${EXTENSION_PLUGIN_FILE}
"
1000 TEST_SUFFIX "-level1-
"
1001 PROJECT_NAME ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
1003 camitk_parse_test_add(NAME ${CAMITK_TEST_NAME} LEVEL 1 DESCRIPTION "Open
a file, load the action and apply it on the component.
")
1006 endif() # NOT PACKAGING_NSIS AND BUILD_TESTING AND ${EXTENSION_NAME_CMAKE}_ENABLE_AUTO_TEST)
1008 #########################################################################
1010 # CTEST - Integration test #
1012 #########################################################################
1014 if (NOT PACKAGING_NSIS AND BUILD_TESTING AND ${EXTENSION_NAME_CMAKE}_ENABLE_INTEGRATION_TEST)
1015 # add a specific test to run the action, save the output and compare it to expected
1016 camitk_add_integration_test()
1019 endif() # ${TYPE_EXTENSION_CMAKE}_${EXTENSION_NAME_CMAKE}_ENABLED
1024 # TODO write a viewer_extension macro in CamiTK