CamiTKExtension.cmake 59.3 KB
Newer Older
promayon's avatar
promayon committed
1
#!
2
#! @ingroup group_sdk_cmake_camitk
promayon's avatar
promayon committed
3
#!
4
#! Macro camitk_extension simplifies writing a camitk extension (component, action, viewer)
promayon's avatar
promayon committed
5 6 7
#!
#! The name of the extension is automatically the name of the directory from where this macro
#! is called, unless it is overriden by the TARGET_NAME parameter.
8 9
#!
#! \note
10 11 12 13 14 15
#! To be more precise, after the execution of this macro, the variable <type>_TARGET_NAME (i.e.,
#! ACTION_TARGET_NAME, COMPONENT_TARGET_NAME, or VIEWER_TARGET_NAME) holds the name
#! of the CMake target produced by this macro.
#! The target name itself is equals to either "action-<name>", "component-<name>" 
#! or viewer-<name> (depending on the <type> of the extension), where <name> is 
#! the name of the current folder in lowercase, unless TARGET_NAME
16
#! is provided
17
#! On windows, the "-" (dash) is replaced by "_" (underscore)
promayon's avatar
promayon committed
18 19 20
#!
#!  usage:
#! \code
21
#!   camitk_extension( <type>
promayon's avatar
promayon committed
22 23 24 25 26 27
#!                     [DISABLED]
#!                     [NEEDS_ITK]
#!                     [NEEDS_LIBXML2]
#!                     [NEEDS_OPENCV]
#!                     [NEEDS_IGSTK]
#!                     [NEEDS_XSD]
28
#!                     [NEEDS_GDCM]
29
#!                     [NEEDS_ACTION_EXTENSION action1 action2 ...]
30
#!                     [NEEDS_VIEWER_EXTENSION viewer1 viewer2 ...]
promayon's avatar
promayon committed
31
#!                     [NEEDS_COMPONENT_EXTENSION component1 component2 ...]
32
#!                     [NEEDS_CEP_LIBRARIES CEPLib1 CEPLib2 ...]
promayon's avatar
promayon committed
33 34
#!                     [INCLUDE_DIRECTORIES dir1 dir2 ...]
#!                     [DEFINES flag1 flag2 ...]
35
#!                     [CXX_FLAGS flag1 flag2 ...]
promayon's avatar
promayon committed
36
#!                     [EXTERNAL_SOURCES file1 file2 ...]
37
#!                     [EXTERNAL_LIBRARIES lib1 lib2 ...]
promayon's avatar
promayon committed
38 39 40
#!                     [HEADERS_TO_INSTALL header1.h header2.h ...]
#!                     [INSTALL_ALL_HEADERS]
#!                     [TARGET_NAME non-default-targetname]
41
#!                     [DESCRIPTION description]
42
#!                     [EXTRA_TRANSLATE_LANGUAGE]
43
#!                     [ENABLE_AUTO_TEST]
44
#!                     [TEST_FILES file1 file2 ...]
45 46
#!                     [AUTO_TEST_LEVEL 1]
#!                     [AUTO_TEST_LEVEL 2]
47
#!                     [ENABLE_INTEGRATION_TEST]
promayon's avatar
promayon committed
48 49 50
#!     )
#! \endcode
#!
51
#! \param <type>                    = REQUIRED. The selected type of extension you wish to build.
52 53
#                                     possible values : ACTION_EXTENSION, COMPONENT_EXTENSION
#!                                    or VIEWER_EXTENSION.
promayon's avatar
promayon committed
54
#! \param DISABLED                  = means this is a not a default extension, it will not be compiled automatically
55
#! \param NEEDS_ITK                 = add this if your extension needs ITK.
56
#!                                    Do not forget to add the needed list of ITK libraries in the LIBRARIES parameter
57 58 59 60 61 62
#! \param NEEDS_LIBXML2             = add this if your extension needs libxml2
#! \param NEEDS_XSD                 = add this if your extension needs Codesynthesis xsd cxx (xml schema compiler)
#! \param NEEDS_OPENCV              = add this if your extension needs OpenCV
#! \param NEEDS_IGSTK               = add this if your extension needs IgsTK
#! \param NEEDS_XERCESC             = add this if your extension needs XercesC library
#! \param NEEDS_GDCM                = Add this if your extension requires GDCM library
promayon's avatar
promayon committed
63 64
#! \param NEEDS_CEP_LIBRARIES       = list of needed CEP libraries (not external dependencies)
#! \param NEEDS_COMPONENT_EXTENSION = list of needed component extensions
65 66
#! \param NEEDS_ACTION_EXTENSION    = list of needed action extensions
#! \param NEEDS_VIEWER_EXTENSION    = list of needed viewer extensions
promayon's avatar
promayon committed
67
#! \param INCLUDE_DIRECTORIES       = additional include directories
68 69
#! \param DEFINES                   = list of define flags to add at compilation time.
#! \param CXX_FLAGS                 = list of compiler flags to add (such as warning levels (-Wall ...)).
promayon's avatar
promayon committed
70 71 72
#! \param EXTERNAL_SOURCES          = list of extra source/headers files (external to the current directory)
#!                                    that needed to be added to the SOURCES variable.
#!                                    Note: EXTERNAL_SOURCES are not installed
73
#! \param EXTERNAL_LIBRARIES        = external libraries to add to the link command
promayon's avatar
promayon committed
74
#! \param HEADERS_TO_INSTALL        = list of headers to install, if present this will automatically
75 76 77 78
#!                                    create an "install-EXTENSION_NAME" target, that can be used
#!                                    anywhere else to manage dependencies to this extension.
#!                                    The headers are installed ${CAMITK_BUILD_INCLUDE_DIR}/EXTENSION_TYPE/EXTENSION_NAME
#!                                    when the target "install-EXTENSION_NAME" is called.
promayon's avatar
promayon committed
79
#! \param INSTALL_ALL_HEADERS       = install all of the headers (this is the lazy solution, please consider
80
#!                                    making a list and using HEADERS_TO_INSTALL parameter instead.
81
#!                                    Only the files matching the regex *.h will be install. If you need to add
82
#!                                    other files, you need to use the HEADERS_TO_INSTALL option.
83 84 85
#! \param TARGET_NAME               = specify a target name different than the default (default is the extension source code directory name)
#!                                    this can be very useful for example when you have an extension source code directory in your CEP that has
#!                                    the same name as one in the camitk community edition.
86 87 88
#! \param CEP_NAME                  = specify the CEP_NAME, which is used to categorized the extension for packaging purpose
#!                                    No CEP_NAME provided will result in default categorization (generic extension).
#! \param DESCRIPTION               = Simple description of the extension. Used for packaging presentation for instance.
89
#! \param EXTRA_TRANSLATE_LANGUAGE  = Additionnal extra language to translate the application
90
#! \param ENABLE_AUTO_TEST          = Create automatic test with either testactions or testcomponents.
91 92
#!                                    By default, auto test are run at the highlest level (level 3) unless AUTO_TEST_LEVEL is specified
#!                                    See also TEST_FILES and AUTO_TEST_LEVEL options
93 94 95 96
#! \param TEST_FILES                = List of files to use for testing.
#!                                    If provided, only the filenames are required (not the absolute paths), each of them should be
#!                                    found in the testdata build dir.
#!                                    If no test files are provided:
97
#!                                        - for component extension auto test: all the files in the component
98 99
#!                                          testdata subdir are used by default
#!                                        - for action extension auto test: all the files available in the testdata build dir (i.e.,
100
#!                                          all the component testdata) are used by default (which might be too many!).
101 102 103 104
#! \param AUTO_TEST_LEVEL i         = for automatic test of component extensions: set the highest level of automatic test to perform:
#!                                    - level 1: load the component extension, open and close a testdata component file
#!                                    - level 2: same as level 1, but save the component before closing it.
#!                                    - level 3 (default): same as level 2, but also compare the saved component to the input.
105
#! \param ENABLE_INTEGRATION_TEST   = add a specific integration test (see camitk_add_integration_test) CamiTK CMake macro.
106
#!                                    New in CamiTK 4.1
107 108
#!                                    It does add an integration test using the action-state-machine to process a chain
#!                                    of actions (requires that subdirectory integration-testdata exists, and contains
109 110
#!                                    a file called "asm-input.scxml" and at least one file name "output-*.*")
#!                                    Check the wiki for more information about integration test
111
#!
112 113
#!
#!
114
#!
promayon's avatar
promayon committed
115 116
macro(camitk_extension)

117 118 119

    # Instruct CMake to run moc automatically when needed.
    set(CMAKE_AUTOMOC ON)
120 121


122 123 124 125 126 127 128 129 130 131
    #########################################################################
    #                                                                       #
    #   ARGUMENTS PARSING                                                   #
    #                                                                       #
    #   * Use a macro to create the CMAKE variables according to the        #
    #     provided options as input.                                        #
    #                                                                       #
    #########################################################################

    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 137
    cmake_parse_arguments(${EXTENSION_NAME_CMAKE} "${options}" "${oneValueArgs}"
                          "${multiValueArgs}" ${ARGN} )
promayon's avatar
promayon committed
138

139 140 141 142
    #########################################################################
    #                                                                       #
    #   CREATE CMAKE VARIABLES                                              #
    #                                                                       #
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)
promayon's avatar
promayon committed
149 150
        set(TYPE_EXTENSION "action")
        string(TOUPPER ${TYPE_EXTENSION} TYPE_EXTENSION_CMAKE)
151
    elseif(${EXTENSION_NAME_CMAKE}_COMPONENT_EXTENSION)
promayon's avatar
promayon committed
152 153
        set(TYPE_EXTENSION "component")
        string(TOUPPER ${TYPE_EXTENSION} TYPE_EXTENSION_CMAKE)
154 155 156
	elseif(${EXTENSION_NAME_CMAKE}_VIEWER_EXTENSION)
		set(TYPE_EXTENSION "viewer")
        string(TOUPPER ${TYPE_EXTENSION} TYPE_EXTENSION_CMAKE)
promayon's avatar
promayon committed
157 158
    endif()

159 160 161 162 163 164 165 166
    # CMAKE CACHE VARIABLE
    # if it is the first cmake run, create the extension variable with a correct initial value
    if(NOT ${TYPE_EXTENSION_CMAKE}_${EXTENSION_NAME_CMAKE}_INTERNAL)
        # add option to enable/disable this extension and set it to true by default
        # Building the extension can be disabled by giving the argument DISABLED to the macro
        # or by passing the flag -D${TYPE_EXTENSION_CMAKE}_${EXTENSION_NAME_CMAKE}_DISABLED:BOOL=TRUE
        if(${EXTENSION_NAME_CMAKE}_DISABLED)
            set(${TYPE_EXTENSION_CMAKE}_${EXTENSION_NAME_CMAKE}_ENABLED FALSE)
167
        else()
168
            set(${TYPE_EXTENSION_CMAKE}_${EXTENSION_NAME_CMAKE}_ENABLED TRUE)
169
        endif()
170 171
        set(${TYPE_EXTENSION_CMAKE}_${EXTENSION_NAME_CMAKE} ${${TYPE_EXTENSION_CMAKE}_${EXTENSION_NAME_CMAKE}_ENABLED} CACHE BOOL "Build extension ${EXTENSION_NAME}")
        set(${TYPE_EXTENSION_CMAKE}_${EXTENSION_NAME_CMAKE}_INTERNAL TRUE CACHE INTERNAL "Is variable ${TYPE_EXTENSION_CMAKE}_${EXTENSION_NAME} already created?")
promayon's avatar
promayon committed
172 173
    endif()

174 175
    # if this extension is enabled, do everything needed
    # otherwise... do nothing
176
    if (${${TYPE_EXTENSION_CMAKE}_${EXTENSION_NAME_CMAKE}})
177 178 179 180 181 182 183

        # TARGET NAME
        # The target name is composed of the following: [action / component]-name
        # * action / component is the type of extension as prefix
        # * name is deduced from the input folder containing the calling CMakeLists.txt file of the extension.
        if (${EXTENSION_NAME_CMAKE}_TARGET_NAME)
            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 188 189 190 191 192 193
        # replace "-" by "_" if the extension is being packaged with NSIS, the program to create a Windows installer.
        if (PACKAGING_NSIS)
            # NSIS requires that cpack component names do not feature space or "-" characters
            set(${TYPE_EXTENSION_CMAKE}_TARGET_NAME ${TYPE_EXTENSION}_${${TYPE_EXTENSION_CMAKE}_OUTPUT_NAME})
        else()
            set(${TYPE_EXTENSION_CMAKE}_TARGET_NAME ${TYPE_EXTENSION}-${${TYPE_EXTENSION_CMAKE}_OUTPUT_NAME})
        endif()
194

195
        message(STATUS "Building extension ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}")
196

197 198 199 200 201 202 203 204 205
        # EXTENSION_PLUGIN_FILE
        # determine the extension full file name depending on the plateform
        set(EXTENSION_PLUGIN_FILE "${CAMITK_BUILD_PRIVATE_LIB_DIR}/${TYPE_EXTENSION}s")
        if (MSVC)
            set(EXTENSION_PLUGIN_FILE ${EXTENSION_PLUGIN_FILE}/${${TYPE_EXTENSION_CMAKE}_OUTPUT_NAME}${CAMITK_DEBUG_POSTFIX}.dll)
        elseif(APPLE)
            set(EXTENSION_PLUGIN_FILE ${EXTENSION_PLUGIN_FILE}/lib${${TYPE_EXTENSION_CMAKE}_OUTPUT_NAME}.dylib)
        else()
            # Must be Linux
206
            set(EXTENSION_PLUGIN_FILE ${EXTENSION_PLUGIN_FILE}/lib${${TYPE_EXTENSION_CMAKE}_OUTPUT_NAME}.so)
207
        endif()
208

209 210 211 212 213 214 215 216 217
        #########################################################################
        #                                                                       #
        #   INCLUDE DIRECTORIES                                                 #
        #                                                                       #
        #   * Include basic directories where to look header files              #
        #   * Include also additional user provided directories                 #
        #   * These directories are used for compilation step                   #
        #                                                                       #
        #########################################################################
218 219
        # BASIC DIRECTORIES

220
        include_directories(${CAMITK_INCLUDE_DIRECTORIES})
221 222
        include_directories(${CMAKE_CURRENT_BINARY_DIR})
        include_directories(${CMAKE_CURRENT_SOURCE_DIR})
223

224
        # USER INPUT DIRECTORIES
225
        include_directories(${${EXTENSION_NAME_CMAKE}_INCLUDE_DIRECTORIES})
226 227 228



229 230
        #########################################################################
        #                                                                       #
231
        #   GATHER RESOURCES                                                   #
232 233 234
        #                                                                       #
        #   * Get all the headers (.h) and source files (.cpp) of the project   #
        #   * 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 242 243
        # one need to do this just before the add_library so that all defines, include directories and link directories
        # are set properly (gather_headers_and_sources include the call to Qt moc and uic)
        gather_headers_and_sources(${EXTENSION_NAME_CMAKE})
244

245 246


247 248
        #########################################################################
        #                                                                       #
249
        #   ADDITIONAL KNOWN EXTERNAL LIBRARY DEPENDENCIES                      #
250 251 252 253 254 255 256
        #                                                                       #
        #   * Look for specific library needed                                  #
        #   * Specific libraries are specified as option with the               #
        #     NEEDS_LIBRARY syntax (see macro syntax for more options)          #
        #   * Backward compatibility : Warn user if using old NEEDS_TOOL syntax #
        #                                                                       #
        #########################################################################
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 263 264
            if(ITK_FOUND)
                include(${ITK_USE_FILE})
                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") AND (${ITK_VERSION} VERSION_LESS "5")) # 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 276 277
                            if((NOT ${${ITK_LIBRARY}_PREFIX} STREQUAL "itk") AND (NOT ${${ITK_LIBRARY}_PREFIX} STREQUAL "ITK"))
                                set(ITK_LIBRARY itk${ITK_LIBRARY})
                            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 281
                    elseif(UNIX)
                        set(CAMITK_ITK_LIBRARIES ${ITK_LIBRARIES})
282
                    elseif(APPLE)
283
                        message(WARNING "CamiTKExtension.cmake: ITK LIBRARY NOT SET FOR APPLE")
284
                    endif()
285 286
                else()
                    message(FATAL_ERROR "Wrong version of ITK : ${ITK_VERSION}. Required is at least 4.x to 4.9")
287
                endif()
288 289
            else()
                message(FATAL_ERROR "ITK not found but required for ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}")
290
            endif()
291 292
        endif()

293
        # LIBXML2
294
        set(LIBXML2_LIBRARY "")
295
        if(${EXTENSION_NAME_CMAKE}_NEEDS_LIBXML2)
296 297 298 299 300
            # LibXml2 is required
            find_package(Xml2)
            if (LIBXML2_FOUND)
                add_definitions(${LIBXML2_DEFINITIONS})
                include_directories(${LIBXML2_INCLUDE_DIR})
301
                set(LIBXML2_LIBRARY ${LIBXML2_LIBRARIES})
302 303 304 305
            else()
                # most probably win32 or crosscompiling
                message(STATUS "${EXTENSION_NAME}: libxml2 required")
            endif()
306
        endif()
promayon's avatar
promayon committed
307

308
        # OPENCV
promayon's avatar
promayon committed
309
        set(OpenCV_LIBRARIES "")
310 311 312 313 314 315
        if(${EXTENSION_NAME_CMAKE}_NEEDS_OPENCV)
            # OpenCV is required
            find_package( OpenCV REQUIRED )
        else ( )
            set(OpenCV_LIBRARIES "")
        endif()
promayon's avatar
promayon committed
316

317
        # IGSTK
promayon's avatar
promayon committed
318
        set(IGSTK_LIBRARIES "")
319 320 321
        if(${EXTENSION_NAME_CMAKE}_NEEDS_IGSTK)
            find_package(IGSTK REQUIRED)
            include(${IGSTK_USE_FILE})
322
        else()
323
            set(IGSTK_LIBRARIES "")
324
        endif()
promayon's avatar
promayon committed
325

326 327 328
        # XERCES-C
        set(XERCESC_LIBRARIES)
        if(${EXTENSION_NAME_CMAKE}_NEEDS_XERCESC)
329
            # XercesC is required
330 331 332
            if (NOT XERCESC_LIBRARY)
                find_package(XercesC REQUIRED)
            endif()
333 334
            if (XERCESC_FOUND)
                include_directories(${XERCESC_INCLUDE_DIR})
335
                set(XERCESC_LIBRARIES ${XERCESC_LIBRARY})
336 337
            else()
                # most probably win32 or crosscompiling
saubatn's avatar
saubatn committed
338
                message(FATAL_ERROR "${EXTENSION_NAME}: xerces-c required. Please provide Xerces-C path.")
339
            endif()
340
        endif()
promayon's avatar
promayon committed
341

342 343
        # XSD
        if(${EXTENSION_NAME_CMAKE}_NEEDS_XSD)
344
            # XercesC is required
345 346 347
            if (NOT XERCESC_LIBRARY)
                find_package(XercesC REQUIRED)
            endif()
348 349 350
            find_package(XercesC REQUIRED)
            if (XERCESC_FOUND)
                include_directories(${XERCESC_INCLUDE_DIR})
351
                set(XERCESC_LIBRARIES ${XERCESC_LIBRARY})
352 353 354 355
                find_package(XSD REQUIRED)
                include_directories(${XSD_INCLUDE_DIR})
            else()
                # 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 361 362
        # GDCM 2.2.x
        set(GDCM_LIBRARIES)
        if(${EXTENSION_NAME_CMAKE}_NEEDS_GDCM)
363 364 365 366 367 368 369 370
            if(NOT GDCM_FOUND)
                # Look for GDCM library only if not found (for instance, ITK has already search for it)
                # Calling find_package(GDCM ..) more than once creates CMake errors.
                find_package(GDCM 2.0 REQUIRED)
            endif()
            if(GDCM_FOUND)
                include(${GDCM_USE_FILE})
                if (MSVC)
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387
					# List all available GDCM library files
					file(GLOB GDCM_LIB_FILES
						LIST_DIRECTORIES false
						"${GDCM_DIR}/../*${CAMITK_DEBUG_POSTFIX}.lib"
						
					)
					unset(GDCM_LIBRARIES)
					foreach(GDCM_LIB_FILE ${GDCM_LIB_FILES})
						# Get the actual name of the library
						string(REGEX REPLACE "^.*/(.*)${CAMITK_DEBUG_POSTFIX}.lib"
						   "\\1" GDCM_LIB_FILE_OPTIMIZED
						   "${GDCM_LIB_FILE}")
						# Add both debug and optimized version
						set(GDCM_LIBRARIES ${GDCM_LIBRARIES} debug ${GDCM_LIB_FILE}
							optimized ${GDCM_LIB_FILE_OPTIMIZED})
					endforeach()
					
388
                else()
389
                    set(GDCM_LIBRARIES gdcmCommon gdcmDICT gdcmDSED gdcmMEXD gdcmMSFF vtkgdcm)
390 391
                endif()
            else()
392
                message(ERROR "${EXTENSION_NAME}: GDCM 2.x or above library required. Please install GDCM.")
393 394
            endif()
        endif()
395 396

        # EXTERNAL LIBRARIES
397 398 399 400
        set(EXTERNAL_LIBRARIES)
        if(${EXTENSION_NAME_CMAKE}_EXTERNAL_LIBRARIES)
            foreach(EXTERNAL_LIBRARY ${${EXTENSION_NAME_CMAKE}_EXTERNAL_LIBRARIES})
                if (MSVC)
401 402
                    list(APPEND EXTERNAL_LIBRARIES ${EXTERNAL_LIBRARIES}
                                                   debug ${EXTERNAL_LIBRARY}${CAMITK_DEBUG_POSTFIX}.lib
403
                                                   optimized ${EXTERNAL_LIBRARY}.lib
404 405
                    )
                else()
406
                    list(APPEND EXTERNAL_LIBRARIES ${EXTERNAL_LIBRARY})
407 408 409
                endif()
            endforeach()
        endif()
410 411


412

413 414 415 416 417 418
        #########################################################################
        #                                                                       #
        #   LINK DIRECTORIES                                                    #
        #                                                                       #
        #   * Link directories are used to indicate the compiler where          #
        #     to look for folder containing libraries to link with.             #
419
        #   * Must be done BEFORE creating the CMake target with add_library    #
420 421
        #                                                                       #
        #########################################################################
422

423 424
        # CAMITK BASIC LIB DIRECTORIES
        link_directories(${CAMITK_LINK_DIRECTORIES})
425

426

427

428 429 430 431 432 433 434 435 436 437
        #########################################################################
        #                                                                       #
        #   TARGET COMPILATION DEFINITION                                       #
        #                                                                       #
        #   * Additional sources files to consider at compilation (.cpp)        #
        #   * CMake project target definition                                   #
        #                                                                       #
        #########################################################################
        # EXTERNAL SOURCES
        set(${EXTENSION_NAME_CMAKE}_SOURCES ${${EXTENSION_NAME_CMAKE}_SOURCES} ${${EXTENSION_NAME_CMAKE}_EXTERNAL_SOURCES})
438

439 440
        # CMAKE TARGET DEFINITION
        add_library(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} SHARED ${${EXTENSION_NAME_CMAKE}_SOURCES})
441

442 443


444 445 446 447 448 449 450 451
        #########################################################################
        #                                                                       #
        #   QT LINKING LIBRARIES                                                #
        #                                                                       #
        #   * Set at linking the Qt5 libraries                                  #
        #                                                                       #
        #########################################################################
        qt5_use_modules(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} ${CAMITK_QT_COMPONENTS})
452 453 454



455 456
        #########################################################################
        #                                                                       #
457
        #   CAMITK ACTION / COMPONENT / LIBRARIES DEPENDENCIES                  #
458
        #                                                                       #
459 460 461 462
        #   * Look for action / component / libraries dependencies              #
        #   * Specific actions / components / libraries are specified as option #
        #     with the NEEDS_ACTION/COMPONENT_EXTENSION/CEP_LIBRARIES syntax    #
        #   * Add dependencies to library-camitkcore and the testing            #
463
        #     action/component if test are runned on it                         #
464 465
        #                                                                       #
        #########################################################################
466

467
        # 1st CAMITKCORE LIBRARY DEPENDENCY
468 469 470 471
        # add_dependencies(..) is only needed to enable parallel build during SDK build
        # but generates an error for external CEP, where this target does not
        # exists.
        # Using target_link_libraries(..) is enough to link the extension to the CamiTK core library
472
        if(CAMITK_COMMUNITY_EDITION_BUILD)
473 474
            add_dependencies(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} ${CAMITK_CORE_TARGET_LIB_NAME})
            # add the dependency to the core automoc target only if inside a SDK build
475
            set_property(TARGET ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} APPEND PROPERTY AUTOGEN_TARGET_DEPENDS ${CAMITK_CORE_TARGET_LIB_NAME})
476 477
        endif()

478

479
        # 2nd COMPONENTS DEPENDENCIES
480
        if(${EXTENSION_NAME_CMAKE}_NEEDS_COMPONENT_EXTENSION)
481 482
            set(COMPONENTS_DEPENDENCY_LIST "") #use for generating the project.xml file
            foreach(COMPONENT_NEEDED ${${EXTENSION_NAME_CMAKE}_NEEDS_COMPONENT_EXTENSION})
483
                 # include directories from build, camitk (local or global install).
484 485 486 487
                include_directories(${CAMITK_BUILD_INCLUDE_DIR}/components/${COMPONENT_NEEDED})
                include_directories(${CAMITK_INCLUDE_DIR}/components/${COMPONENT_NEEDED})
                # file dependency
                if (MSVC)
488 489
                    list(APPEND COMPONENT_EXTENSION_LIBRARIES debug ${CAMITK_BUILD_PRIVATE_LIB_DIR}/components/${COMPONENT_NEEDED}${CAMITK_DEBUG_POSTFIX}.lib
                                                              optimized ${COMPONENT_NEEDED}
490 491
                    )
                else()
492
                    list(APPEND COMPONENT_EXTENSION_LIBRARIES ${COMPONENT_NEEDED})
493 494 495 496
                endif()
                # CMake / CDash dependencies
                if(PACKAGING_NSIS)
                    add_dependencies(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} component_${COMPONENT_NEEDED})
497
                    # add the dependency to the component automoc target only if compiling SDK
498
                    if(CAMITK_COMMUNITY_EDITION_BUILD)
499
                        set_property(TARGET ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} APPEND PROPERTY AUTOGEN_TARGET_DEPENDS component_${COMPONENT_NEEDED})
500
                    endif()
501 502
                else()
                    add_dependencies(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} component-${COMPONENT_NEEDED})
503
                    list(APPEND COMPONENTS_DEPENDENCY_LIST component-${COMPONENT_NEEDED})
504
                    # add the dependency to the component automoc target only if compiling SDK
505
                    if(CAMITK_COMMUNITY_EDITION_BUILD)
506
                        set_property(TARGET ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} APPEND PROPERTY AUTOGEN_TARGET_DEPENDS component-${COMPONENT_NEEDED})
507
                    endif()
508 509
                endif()
            endforeach()
510
        endif()
511

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})
519
                # file dependency
520
                if (MSVC)
521 522
                    list(APPEND ACTION_EXTENSION_LIBRARIES debug ${CAMITK_BUILD_PRIVATE_LIB_DIR}/actions/${ACTION_NEEDED}${CAMITK_DEBUG_POSTFIX}.lib
                                                           optimized ${ACTION_NEEDED}
523 524
                    )
                else()
525
                    list(APPEND ACTION_EXTENSION_LIBRARIES ${ACTION_NEEDED})
526
                endif()
527 528 529
                # CMake / CDash dependencies
                if (PACKAGING_NSIS)
                    add_dependencies(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} action_${ACTION_NEEDED})
530
                    # add the dependency to the component automoc target only if compiling SDK
531
                    if(CAMITK_COMMUNITY_EDITION_BUILD)
532 533
                        set_property(TARGET ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} APPEND PROPERTY AUTOGEN_TARGET_DEPENDS action_${ACTION_NEEDED})
                    endif()
534 535
                else()
                    add_dependencies(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} action-${ACTION_NEEDED})
536
                    list(APPEND ACTIONS_DEPENDENCY_LIST action-${ACTION_NEEDED})
537
                    # add the dependency to the component automoc target only if compiling SDK
538
                    if(CAMITK_COMMUNITY_EDITION_BUILD)
539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573
                        set_property(TARGET ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} APPEND PROPERTY AUTOGEN_TARGET_DEPENDS action-${ACTION_NEEDED})
                    endif()
                endif()
            endforeach()
        endif()

		# 3rd VIEWERS DEPENDENCIES
        if(${EXTENSION_NAME_CMAKE}_NEEDS_VIEWER_EXTENSION)
            set(VIEWERS_DEPENDENCY_LIST "") #use for generating the project.xml file
            foreach(VIEWER_NEEDED ${${EXTENSION_NAME_CMAKE}_NEEDS_VIEWER_EXTENSION})
                # include directories from build, camitk (local or global install).
                include_directories(${CAMITK_BUILD_INCLUDE_DIR}/viewers/${VIEWER_NEEDED})
                include_directories(${CAMITK_INCLUDE_DIR}/viewers/${VIEWER_NEEDED})
                # file dependency
                if (MSVC)
                    list(APPEND VIEWER_EXTENSION_LIBRARIES debug ${CAMITK_BUILD_PRIVATE_LIB_DIR}/viewers/${VIEWER_NEEDED}${CAMITK_DEBUG_POSTFIX}.lib
                                                           optimized ${VIEWER_NEEDED}
                    )
                else()
                    list(APPEND VIEWER_EXTENSION_LIBRARIES ${VIEWER_NEEDED})
                endif()
                # CMake / CDash dependencies
                if (PACKAGING_NSIS)
                    add_dependencies(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} viewer_${VIEWER_NEEDED})
                    # add the dependency to the component automoc target only if compiling SDK
                    if(CAMITK_COMMUNITY_EDITION_BUILD)
                        set_property(TARGET ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} APPEND PROPERTY AUTOGEN_TARGET_DEPENDS viewer_${VIEWER_NEEDED})
                    endif()
                else()
                    add_dependencies(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} viewer-${VIEWER_NEEDED})
                    list(APPEND VIEWERS_DEPENDENCY_LIST viewer-${VIEWER_NEEDED})
                    # add the dependency to the component automoc target only if compiling SDK
                    if(CAMITK_COMMUNITY_EDITION_BUILD)
                        set_property(TARGET ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} APPEND PROPERTY AUTOGEN_TARGET_DEPENDS viewer-${VIEWER_NEEDED})
                    endif()
574
                endif()
575
            endforeach()
576
        endif()
577

578 579 580 581
        # 4th CEP LIBRARIES DEPENDENCIES
        if(${EXTENSION_NAME_CMAKE}_NEEDS_CEP_LIBRARIES)
            set(CEP_LIBRARIES_DEPENDENCY_LIST "") #use for generating the project.xml file
            foreach(CEP_LIBRARY_NEEDED ${${EXTENSION_NAME_CMAKE}_NEEDS_CEP_LIBRARIES})
582
                 # include directories from build, camitk (local or global install).
583 584 585 586
                include_directories(${CAMITK_BUILD_INCLUDE_DIR}/libraries/${CEP_LIBRARY_NEEDED})
                include_directories(${CAMITK_INCLUDE_DIR}/libraries/${CEP_LIBRARY_NEEDED})
                # file dependency
                if (MSVC)
587 588 589
                    list(APPEND CEP_LIBRARIES debug ${CEP_LIBRARY_NEEDED}${CAMITK_DEBUG_POSTFIX}.lib
                                              optimized ${CEP_LIBRARY_NEEDED}
                    )
590
                else()
591
                    list(APPEND CEP_LIBRARIES ${CEP_LIBRARY_NEEDED})
592 593 594 595
                endif()
                # CMake / CDash dependencies
                if (PACKAGING_NSIS)
                    add_dependencies(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} library_${CEP_LIBRARY_NEEDED})
596
                    # add the dependency to the component automoc target only if compiling SDK
597
                    if(CAMITK_COMMUNITY_EDITION_BUILD)
598 599
                        set_property(TARGET ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} APPEND PROPERTY AUTOGEN_TARGET_DEPENDS library_${CEP_LIBRARY_NEEDED})
                    endif()
600 601
                else()
                    add_dependencies(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} library-${CEP_LIBRARY_NEEDED})
602
                    list(APPEND CEP_LIBRARIES_DEPENDENCY_LIST ${CEP_LIBRARY_NEEDED} library-${CEP_LIBRARY_NEEDED})
603
                    # add the dependency to the component automoc target only if compiling SDK
604
                    if(CAMITK_COMMUNITY_EDITION_BUILD)
605 606
                        set_property(TARGET ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} APPEND PROPERTY AUTOGEN_TARGET_DEPENDS library-${CEP_LIBRARY_NEEDED})
                    endif()
607 608 609
                endif()
            endforeach()
        endif()
610

saubatn's avatar
saubatn committed
611 612 613 614 615 616 617 618 619
        #########################################################################
        #                                                                       #
        #   COMPILATION FLAG                                                    #
        #                                                                       #
        #   * Flags are options to give to the compiler                         #
        #   * Add user input flags                                              #
        #   * Add platform specific flags                                       #
        #                                                                       #
        #########################################################################
620

621
        # USER INPUT DEFINES COMPILER FLAG
622 623 624 625 626
        if(${EXTENSION_NAME_CMAKE}_DEFINES)
          foreach (FLAG ${${EXTENSION_NAME_CMAKE}_DEFINES})
            add_definitions(-D${FLAG})
          endforeach()
        endif()
627

628
        # USER INPUT CUSTOM COMPILER FLAG
629 630
        if(${EXTENSION_NAME_CMAKE}_CXX_FLAGS)
          foreach (FLAG ${${EXTENSION_NAME_CMAKE}_CXX_FLAGS})
631
            set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAG}")
632 633
          endforeach()
        endif()
634

saubatn's avatar
saubatn committed
635 636
        # PLATFORM SPECIFIC COMPILER FLAG
        # 64bits and other platform with relocation needs -fPIC
637 638 639 640 641 642 643
        include(TestCXXAcceptsFlag)
        check_cxx_accepts_flag(-fPIC FPIC_FLAG_ACCEPTED)
        # no need to add -fPIC on mingw, otherwise it generates a warning: -fPIC ignored for target (all code is position independent) [enabled by default]
        # msvc is also accepting the flag, but then produce warning D9002 : ignoring unknown option '-fPIC'   cl
        if(FPIC_FLAG_ACCEPTED AND NOT WIN32)
            set_property(TARGET ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} APPEND PROPERTY COMPILE_FLAGS -fPIC)
        endif()
promayon's avatar
promayon committed
644

645 646


647 648 649 650 651 652 653 654 655
        #########################################################################
        #                                                                       #
        #   LINKING                                                             #
        #                                                                       #
        #   * Linking is the last stage of compilation                          #
        #   * Indicate what libraries to use for linking the target             #
        #                                                                       #
        #########################################################################
        # LINKING LIBRARIES
656
        # Any component or action has to be linked with ${CAMITK_CORE_LIBRARIES} and with all its dependencies
657
        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})
658 659


660

661 662 663 664 665 666 667 668 669 670
        #########################################################################
        #                                                                       #
        #   OUTPUT                                                              #
        #                                                                       #
        #   * Define the output directory (location and name)                   #
        #   * Define the output name of the library                             #
        #   * Add ${CAMITK_DEBUG_POSTFIX} suffix to Debug MSVC built libraries  #
        #   * Additional Linux .so files information                            #
        #                                                                       #
        #########################################################################
671

672 673 674 675
        # OUTPUT LIBRARY NAME
        set_target_properties(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
                               PROPERTIES OUTPUT_NAME ${${TYPE_EXTENSION_CMAKE}_OUTPUT_NAME}
        )
promayon's avatar
promayon committed
676

677
        # OUTPUT DIRECTORY LOCATION AND NAME
678 679 680
        # Output directory (all extensions are private)
        set_target_properties(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CAMITK_BUILD_PRIVATE_LIB_DIR}/${TYPE_EXTENSION}s
                                                                                LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CAMITK_BUILD_PRIVATE_LIB_DIR}/${TYPE_EXTENSION}s
681
                                                                                LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CAMITK_BUILD_PRIVATE_LIB_DIR}/${TYPE_EXTENSION}s
682 683 684 685 686 687 688 689 690 691 692
        )
        # Output directory (for dll plateform, this is still the same, extensions are private)
        set_target_properties(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CAMITK_BUILD_PRIVATE_LIB_DIR}/${TYPE_EXTENSION}s
                                                                                RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CAMITK_BUILD_PRIVATE_LIB_DIR}/${TYPE_EXTENSION}s
                                                                                RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CAMITK_BUILD_PRIVATE_LIB_DIR}/${TYPE_EXTENSION}s
        )
        # Output directory (for dll plateform, this is still the same, extensions are private)
        set_target_properties(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CAMITK_BUILD_PRIVATE_LIB_DIR}/${TYPE_EXTENSION}s
                                                                                ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CAMITK_BUILD_PRIVATE_LIB_DIR}/${TYPE_EXTENSION}s
                                                                                ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CAMITK_BUILD_PRIVATE_LIB_DIR}/${TYPE_EXTENSION}s
        )
693

694
        # OUTPUT LIBRARY NAME MSVC in DEBUG mode
695 696 697
        if (MSVC)
            set_target_properties(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} PROPERTIES DEBUG_POSTFIX ${CAMITK_DEBUG_POSTFIX})
        endif()
698

699
        # ADDITIONAL LINUX .so FILE INFORMATION
700 701 702 703 704 705
        set(${TYPE_EXTENSION_CMAKE}_LIBRARY_PROPERTIES ${${TYPE_EXTENSION_CMAKE}_LIBRARY_PROPERTIES}
            VERSION   "${CAMITK_VERSION_MAJOR}.${CAMITK_VERSION_MINOR}.${CAMITK_VERSION_PATCH}"
            SOVERSION "${CAMITK_VERSION_MAJOR}"
        )
        # set the library specific info (SONAME...)
        set_target_properties(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} PROPERTIES ${${TYPE_EXTENSION_CMAKE}_LIBRARY_PROPERTIES} LINK_INTERFACE_LIBRARIES "")
706

707 708 709 710 711 712 713
        # see http://www.cmake.org/pipermail/cmake/2012-April/049889.html
        # target properties (outputname and remove soname)
        #  set_property(TARGET ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} PROPERTY NO_SONAME 1)
        # in CEP the version patch might not have been set
        if (NOT CAMITK_VERSION_PATCH)
            set(CAMITK_VERSION_PATCH 0)
        endif()
714 715 716



717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736
        #########################################################################
        #                                                                       #
        #   INSTALLATION                                                        #
        #                                                                       #
        #   * When installing the project, header files (.h) and test data are  #
        #     copied into a installation folder to determine.                   #
        #   * Indicate in this section, where to install your project and which #
        #     files to copy into that folder (during local/global installation) #
        #                                                                       #
        #########################################################################

        # FOLDER INSTALLATION
        # Indicate where to install the action/component
        install(TARGETS ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
                # TODO always use private lib, even for runtime
                RUNTIME DESTINATION lib/${CAMITK_SHORT_VERSION_STRING}/${TYPE_EXTENSION}s
                LIBRARY DESTINATION lib/${CAMITK_SHORT_VERSION_STRING}/${TYPE_EXTENSION}s
                ARCHIVE DESTINATION lib/${CAMITK_SHORT_VERSION_STRING}/${TYPE_EXTENSION}s
                COMPONENT ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
        )
promayon's avatar
promayon committed
737

738 739 740 741 742
        # HEADERS INSTALLATION
        # Build target to install provided headers to install (with HEADERS_TO_INSTALL option)
        if(${EXTENSION_NAME_CMAKE}_HEADERS_TO_INSTALL)
            export_headers(${${EXTENSION_NAME_CMAKE}_HEADERS_TO_INSTALL} COMPONENT ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} GROUP ${TYPE_EXTENSION}s)
        endif()
743

744
        # Build target to install all header files(with INSTALL_ALL_HEADERS option)
745 746 747
        if(${EXTENSION_NAME_CMAKE}_INSTALL_ALL_HEADERS)
            export_headers(${${EXTENSION_NAME_CMAKE}_HEADERS} COMPONENT ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} GROUP ${TYPE_EXTENSION}s)
        endif()
748

749
        # TESTDATA INSTALLATION
750
        if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/testdata")
751 752
            # Check test data dir directory
            if (NOT EXISTS ${CAMITK_BUILD_TESTDATA_DIR})
753
                 make_directory( ${CAMITK_BUILD_TESTDATA_DIR} )
754
            endif()
755

756
            # copy the files to test data directory
757
            execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory testdata ${CAMITK_BUILD_TESTDATA_DIR}
758
                            WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
759
                           )
promayon's avatar
promayon committed
760

761 762 763 764 765 766 767 768 769 770
            # during installation, copy the files to install directory
            set (TESTDATA_DEST_DIR share/${CAMITK_SHORT_VERSION_STRING}/testdata)
            install(DIRECTORY testdata/
                  #DESTINATION share/testdata
                  #DESTINATION share/${CAMITK_SHORT_VERSION_STRING}/testdata
                  DESTINATION ${TESTDATA_DEST_DIR}
                  # COMPONENT ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
                  PATTERN ".svn" EXCLUDE
                  PATTERN "*~" EXCLUDE
            )
promayon's avatar
promayon committed
771
        endif()
772

773
        #########################################################################
774 775 776
        #                                                                       #
        #   CDASH SUBPROJECT DESCRIPTION                                        #
        #                                                                       #
777 778
        #   * Update the XML description of the subprojects dependencies        #
        #     for CDash.                                                        #
779
        #                                                                       #
780
        #########################################################################
781
        # CDASH XML SUBPROJECTS DESCRIPTION UPDATE
782
        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})
783 784 785



786 787 788 789 790 791 792 793 794 795 796 797 798
        #########################################################################
        #                                                                       #
        #   PACKAGING CATEGORIZATION                                            #
        #                                                                       #
        #   * On Windows, when building a package (win32 installer), the        #
        #     install shield wizard proposes you to select which component      #
        #     to install.                                                       #
        #   * Each component to install has a short description following its   #
        #     name to understand its role.                                      #
        #   * This section deals with the categorization and the description    #
        #     of the component in this installer.                               #
        #                                                                       #
        #########################################################################
799

800 801 802 803 804 805 806 807 808 809
        # WINDOWS INSTALLER CATEGORIZATION
        if(${EXTENSION_NAME_CMAKE}_CEP_NAME)
            if (${EXTENSION_NAME_CMAKE}_CEP_NAME MATCHES "SDK")
                # The default SDK extensions are categorized as "required" and are not "unselectable" by the user at installation time
                cpack_add_component(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
                                    DISPLAY_NAME ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
                                    DESCRIPTION ${${EXTENSION_NAME_CMAKE}_DESCRIPTION}
                                    REQUIRED
                                    GROUP SDK
                                    )
810

811
            else()
812 813 814 815 816 817
                # Extension is selectable for installation in the wizard of the installer
                cpack_add_component(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
                                    DISPLAY_NAME ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
                                    DESCRIPTION ${${EXTENSION_NAME_CMAKE}_DESCRIPTION}
                                    GROUP ${${EXTENSION_NAME_CMAKE}_CEP_NAME}
                                    )
818
            endif()
819
        else()
820
            # Extension if not categorized for packaging presentation
821 822 823 824 825
            cpack_add_component(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
                                DISPLAY_NAME ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
                                DESCRIPTION ${${EXTENSION_NAME_CMAKE}_DESCRIPTION}
                                )
        endif()
826

827

828 829 830 831 832 833 834 835
        #####################################################################################
        #                                                                                   #
        #   TRANSLATION                                                                     #
        #                                                                                   #
        #   * CAMITK_TRANSLATIONS contains the list of language to translate                #
        #    the QString to.                                                                #
        #                                                                                   #
        #   * Create the translate.pro file which contains 4 sections:                      #
836
        #        - HEADERS:      list of .h/.hpp files to look for tr("") QString           #
837
        #        - SOURCES:      list of .cpp files to look for tr("") QString              #
838
        #        - FORMS:        list of .ui files to look for tr("") QString               #
839 840 841 842 843 844 845 846 847 848 849 850 851 852
        #        - TRANSLATIONS: list of .ts files which use CAMITK_TRANSLATIONS            #
        #            to define each .ts file                                                #
        #                                                                                   #
        #    * Execute lupdate program to update the .ts files with new QString             #
        #          found.                                                                   #
        #                                                                                   #
        #   * Execute lrelease program to create .qm files (binary equivalent of            #
        #       .ts files                                                                   #
        #                                                                                   #
        #   * Create translate.qrc which contains the list of .qm files.                    #
        #   * Create the flags.qrc file which contains the list of .png flags               #
        #         images                                                                    #
        #                                                                                   #
        #####################################################################################
853 854 855 856 857 858 859 860
        if(CAMITK_TRANSLATE)
            if(${EXTENSION_NAME_CMAKE}_EXTRA_TRANSLATE_LANGUAGE)
                if(${EXTENSION_NAME} STREQUAL "application")
                    camitk_translate(USE_FLAGS
                                     EXTRA_LANGUAGE ${${EXTENSION_NAME_CMAKE}_EXTRA_TRANSLATE_LANGUAGE})
                else()
                    camitk_translate(EXTRA_LANGUAGE ${${EXTENSION_NAME_CMAKE}_EXTRA_TRANSLATE_LANGUAGE})
                endif()
861
            else()
862 863 864 865 866
                if(${EXTENSION_NAME} STREQUAL "application")
                    camitk_translate(USE_FLAGS)
                else()
                    camitk_translate()
                endif()
867 868 869 870 871
            endif()
        endif()



872 873
        #########################################################################
        #                                                                       #
874
        #   CTEST - COMPONENT TESTS DESCRIPTION                                 #
875 876
        #                                                                       #
        #########################################################################
877

878
        # if auto test possible and required
879
        if (NOT PACKAGING_NSIS AND BUILD_TESTING AND ${EXTENSION_NAME_CMAKE}_ENABLE_AUTO_TEST)
880
            if(${EXTENSION_NAME_CMAKE}_COMPONENT_EXTENSION)
881
                camitk_init_test( camitk-testcomponents )
882

883 884 885 886 887 888 889 890 891
                camitk_parse_test_add_separator(EXTENSION_TYPE ${TYPE_EXTENSION} EXTENSION_NAME ${EXTENSION_NAME})

                # Retrieve the files in testdata directory - a test will be applied for each of these files
                # or use only the given files
                if (${EXTENSION_NAME_CMAKE}_TEST_FILES)
                    # add testdata dir to filename
                    set(TESTFILES)
                    foreach(COMPONENT_TESTDATA_FILE ${${EXTENSION_NAME_CMAKE}_TEST_FILES})
                        list(APPEND TESTFILES ${CMAKE_CURRENT_SOURCE_DIR}/${COMPONENT_TESTDATA_FILE})
892
                    endforeach()
893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909
                else()
                    get_subdirectoryfiles( ${CMAKE_CURRENT_SOURCE_DIR}/testdata TESTFILES )
                endif()

                if (NOT ${EXTENSION_NAME_CMAKE}_AUTO_TEST_LEVEL)
                    # default
                    set(TESTLEVEL 3)
                else()
                    set(TESTLEVEL ${${EXTENSION_NAME_CMAKE}_AUTO_TEST_LEVEL})
                    if (NOT ${TESTLEVEL} MATCHES "^[1-3]")
                        # default
                        message(WARNING "AUTO_TEST_LEVEL set to 3 (${TESTLEVEL} is not a valid level)")
                        set(TESTLEVEL 3)
                    else()
                        set(TESTLEVEL ${${EXTENSION_NAME_CMAKE}_AUTO_TEST_LEVEL})
                    endif()
                endif()
910

911
                # Different the test level are done automatically:
912 913 914 915
                # - level 1: load component extension, open & close test data
                # - level 2: load component extension, open & close test data, save as
                # - level 3: load component extension, open & close test data, save as and compare input with output
                # disable some tests accordingly to options defined in camitk_extension macro arguments
916 917 918 919
                if(${TESTLEVEL} STREQUAL "1")
                    set(TEST_DESCRIPTION "Test loading the extension, opening and closing the component.")
                elseif(${TESTLEVEL} STREQUAL "2")
                    set(TEST_DESCRIPTION "Test loading the extension, opening the component and saving it as a file.")
920
                else()
921 922 923
                    # level 3
                    set(TEST_DESCRIPTION "Test loading the extension, opening, saving and closing the component and comparing saved with input component.")
                endif()