CamiTKApplication.cmake 38.7 KB
Newer Older
promayon's avatar
promayon committed
1
#!
2
#! @ingroup group_sdk_cmake_camitk
promayon's avatar
promayon committed
3
4
5
6
7
8
#!
#! macro camitk_application simplify writing a CMakeLists.txt for CamiTK application extension
#!
#! The name of the application is automatically the name of the directory from where this macro
#! is called prefixed with "camitk-"
#!
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#! On Unix additional system resources can also be automatically installed or configured: man pages,
#! desktop file and XPM icons.
#! - Man pages should be resources/camitk-appdirname.1 or resources/camitk-appdirname.1.in (in this
#! case, it will be configured first).
#! - Desktop file should be in resources/camitk-appdirname.desktop (refer to
#!    http://standards.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html and
#!    http://standards.freedesktop.org/menu-spec/1.0/apa.html for valid category details)
#! - XPM icons should be found in resources/camitk-appdirname.xpm (an icon can also be used in
#!   to set the application icon (use setWindowIcon(QIcon(":/resources/camitk-appdirname.xpm")) as well)
#!
#! To write a simple man page, please refer to SDK application examples. If you need to
#! generate a simple manpage or analyze the command line arguments, the CamiTK team recommands
#! to use Code Synthesis CLI configuration (see http://codesynthesis.com/projects/cli)
#! 
promayon's avatar
promayon committed
23
24
25
26
27
#! usage:
#! \code
#! camitk_application(
#!              [DISABLED]
#!              [NEEDS_ITK]
28
#!              [NEEDS_PYTHON]
promayon's avatar
promayon committed
29
30
31
#!              [NEEDS_CEP_LIBRARIES CEPLib1 CEPLib12 ...]
#!              [NEEDS_COMPONENT_EXTENSION component1 component2 ...]
#!              [NEEDS_ACTION_EXTENSION ation1 action2 ...]
32
#!              [DEFINES flag1 flag2 ...]
33
#!              [CXX_FLAGS flag1 flag2 ...]
promayon's avatar
promayon committed
34
#!              [ADDITIONAL_SOURCES source.cxx source.cpp ...]
35
#!              [INCLUDE_DIRECTORIES dir1 dir2 ...]
36
#!              [EXTERNAL_LIBRARIES lib1 lib2 ...]
37
#!              [EXTRA_TRANSLATE_LANGUAGE]
promayon's avatar
promayon committed
38
39
40
41
42
43
44
45
#!     )
#! \endcode
#!
#! \param DISABLED                      means this is a default application is NOT to be compiled automatically
#! \param NEEDS_ITK                     means this application requires ITK to be compiled / run.
#! \param NEEDS_CEP_LIBRARIES           list of needed camitk CEP libraries
#! \param NEEDS_COMPONENT_EXTENSION     list of needed component extensions
#! \param NEEDS_ACTION_EXTENSION        list of needed component extensions
46
#! \param DEFINES                       list of define flags to add at compilation time
47
#! \param CXX_FLAGS                     list of compiler flags to add (such as warning levels (-Wall ...)).
promayon's avatar
promayon committed
48
#! \param ADDITIONAL_SOURCES            list of additional sources (that cannot be automatically found by gather_headers_and_sources macro)
49
50
51
52
#! \param CEP_NAME                      specify the CEP_NAME, which is used to categorized the application for packaging purpose
#!                                      No CEP_NAME provided will result in default categorization (generic application).
#! \param DESCRIPTION                   Simple description of the application. Used for packaging presentation for instance.
#! \param INCLUDE_DIRECTORIES           additional include directories
53
#! \param EXTERNAL_LIBRARIES            external libraries to add to the link command
54
#! \param EXTRA_TRANSLATE_LANGUAGE      Additionnal extra language to translate the application
promayon's avatar
promayon committed
55
56
macro(camitk_application)

57
58
59
    # Instruct CMake to run moc automatically when needed.
    set(CMAKE_AUTOMOC ON)
    
60
61
62
63
64
65
66
67
    #########################################################################
    #                                                                       #
    #   ARGUMENTS PARSING                                                   #
    #                                                                       #
    #   * Use a macro to create the CMAKE variables according to the        #
    #     provided options as input.                                        #
    #                                                                       #
    #########################################################################
promayon's avatar
promayon committed
68

69
    get_directory_name(${CMAKE_CURRENT_SOURCE_DIR} APPLICATION_NAME)
promayon's avatar
promayon committed
70

71
    parse_arguments(${APPLICATION_NAME_CMAKE}
72
        "NEEDS_CEP_LIBRARIES;NEEDS_TOOL;NEEDS_COMPONENT_EXTENSION;NEEDS_ACTION_EXTENSION;DEFINES;CXX_FLAGS;ADDITIONAL_SOURCES;CEP_NAME;DESCRIPTION;EXTERNAL_LIBRARIES;INCLUDE_DIRECTORIES;EXTRA_TRANSLATE_LANGUAGE"  # possible lists
73
74
75
76
77
78
79
        "DISABLED;NEEDS_QT_MODULES;NEEDS_ITK;NEEDS_QTXML;NEEDS_XSD;NEEDS_XERCESC;NEEDS_PYTHON" # possible options
        ${ARGN}
    )
    
    
    
    #########################################################################
80
81
82
    #                                                                       #
    #   CREATE CMAKE VARIABLES                                              #
    #                                                                       #
83
    #   * Create required and useful CMake variables for the macro         #
84
85
    #                                                                       #
    #########################################################################
promayon's avatar
promayon committed
86

87
88
89
90
91
    # CMAKE CACHE VARIABLE
    # if it is the first cmake run, create the application variable with a correct initial value    
    if(NOT APPLICATION_${APPLICATION_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
saubatn's avatar
saubatn committed
92
        # or by passing the flag -D${TYPE_EXTENSION_CMAKE}_${APPLICATION_NAME_CMAKE}_DISABLED:BOOL=TRUE
93
94
95
96
97
98
99
100
101
        if(${APPLICATION_NAME_CMAKE}_DISABLED)
            set(APPLICATION_${APPLICATION_NAME_CMAKE}_ENABLED FALSE)
        else()
            set(APPLICATION_${APPLICATION_NAME_CMAKE}_ENABLED TRUE)
        endif()
        set(APPLICATION_${APPLICATION_NAME_CMAKE} ${APPLICATION_${APPLICATION_NAME_CMAKE}_ENABLED} CACHE BOOL "Build application ${APPLICATION_NAME}")
        set(APPLICATION_${APPLICATION_NAME_CMAKE}_INTERNAL TRUE CACHE INTERNAL "Is variable APPLICATION_${APPLICATION_NAME} already created?")
    endif()
    
saubatn's avatar
saubatn committed
102
103
104
105
106
107
108
109
110
    # APPLICATION TARGET NAME
    if (PACKAGING_NSIS)
        # NSIS requires that cpack component names do not feature space or "-" characters
        set(APPLICATION_TARGET_NAME application_${APPLICATION_NAME})
    else()
        set(APPLICATION_TARGET_NAME application-${APPLICATION_NAME})
    endif()
        
  
111
  
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
    # if this extension is enabled, do everything needed
    # otherwise... do nothing
    if (APPLICATION_${APPLICATION_NAME_CMAKE})
    
        message(STATUS "Building application ${APPLICATION_NAME}")
        
        
        
        #########################################################################
        #                                                                       #
        #   INCLUDE DIRECTORIES                                                 #
        #                                                                       #
        #   * Include basic directories where to look header files              #
        #   * Include also additional user provided directories                 #
        #   * These directories are used for compilation step                   #
        #                                                                       #
        #########################################################################
129
        # BASIC DIRECTORIES
130
131
        include_directories(${CAMITK_INCLUDE_DIRECTORIES}) 
        include_directories(${CMAKE_CURRENT_BINARY_DIR})
132
        include_directories(${CMAKE_CURRENT_SOURCE_DIR})
133
134
135
136
137
        
        # USER INPUT DIRECTORIES
        include_directories(${${APPLICATION_NAME_CMAKE}_INCLUDE_DIRECTORIES})
        
        
138
    
139
140
141
142
143
144
        #########################################################################
        #                                                                       #
        #   GATHER RESSOURCES                                                   #
        #                                                                       #
        #   * get all the headers (.h) and source files (.cpp) of the project   #
        #   * create the needed Qt files (using moc and uic)                    #
145
146
        #   * On Windows, Visual Studio, group .moc and .ui files               #
        #     in subdirectories                                                 # 
147
148
149
150
151
152
153
        #                                                                       #
        #########################################################################
        
        # get all headers, sources and do what is needed for Qt
        # 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(${APPLICATION_NAME})
154
       
155
                
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
       
        #########################################################################
        #                                                                       #
        #   TARGET COMPILATION  DEFINITION                                      #
        #                                                                       #
        #   * Additional sources files to consider at compilation (.cpp)        #
        #   * CMake project target definition                                   #
        #                                                                       #
        #########################################################################
        # EXTERNAL SOURCES
        set(${APPLICATION_NAME}_SOURCES ${${APPLICATION_NAME}_SOURCES} ${${APPLICATION_NAME_CMAKE}_ADDITIONAL_SOURCES})
        
        # APPLE BUNDLE DEFINITIONS
        if(APPLE)
            set(MACOSX_BUNDLE_INFO_STRING "${APPLICATION_TARGET_NAME} ${CAMITK_SHORT_VERSION_STRING}")
            set(MACOSX_BUNDLE_BUNDLE_VERSION "${APPLICATION_TARGET_NAME} ${CAMITK_SHORT_VERSION_STRING}")
            set(MACOSX_BUNDLE_LONG_VERSION_STRING "${APPLICATION_TARGET_NAME} ${CAMITK_SHORT_VERSION_STRING}")
            set(MACOSX_BUNDLE_SHORT_VERSION_STRING "${CAMITK_SHORT_VERSION_STRING}")
            set(MACOSX_BUNDLE_COPYRIGHT "2014 UJF")
            set(MACOSX_BUNDLE_ICON_FILE "${CMAKE_CURRENT_SOURCE_DIR}/resources/camitk-${APPLICATION_NAME}.icns")
            set(MACOSX_BUNDLE_BUNDLE_NAME "${APPLICATION_TARGET_NAME}")

            set(MACOSX_BUNDLE_RESOURCES "${CMAKE_CURRENT_BINARY_DIR}/${APPLICATION_TARGET_NAME}.app/Contents/Resources")
            set(MACOSX_BUNDLE_ICON "${MACOSX_BUNDLE_ICON_FILE}")
            execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${MACOSX_BUNDLE_RESOURCES})
            execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different ${MACOSX_BUNDLE_ICON} ${MACOSX_BUNDLE_RESOURCES})
        endif()
         
184
185

         
186
187
188
189
190
191
192
193
194
195
196
        #########################################################################
        #                                                                       #
        #   ADDITIONAL KNOWN LIBRARY DEPENDENCIES                               #
        #                                                                       #
        #   * 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 #
        #                                                                       #
        #########################################################################
        
197
        # Looking for ITK
198
        set(ITK_LIBRARIES "")
199
200
201
202
203
        if(${APPLICATION_NAME_CMAKE}_NEEDS_ITK)
            find_package(ITK REQUIRED)
            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
204
                set(CAMITK_ITK_VERSION ${ITK_VERSION_MAJOR}.${ITK_VERSION_MINOR})
205
                message(STATUS "${APPLICATION_TARGET_NAME}: Found ITK version ${ITK_VERSION}")
206
207

                if ((${ITK_VERSION} VERSION_GREATER "4") AND (${ITK_VERSION} VERSION_LESS "5")) # ITK 4.9 on Windows, maybe a lesser version for Linux.
208
                    if(MSVC)
209
210
                        set(ITK_DIR ${ITK_DIR}/../..)
                        # Construct list of ITK libraries for linking
211
                        foreach(ITK_LIBRARY ${ITK_LIBRARIES})
212
213
214
215
                        string(SUBSTRING ${ITK_LIBRARY} 0 3 ${ITK_LIBRARY}_PREFIX)
                            if((NOT ${${ITK_LIBRARY}_PREFIX} STREQUAL "itk") AND (NOT ${${ITK_LIBRARY}_PREFIX} STREQUAL "ITK"))
                                set(ITK_LIBRARY itk${ITK_LIBRARY})
                            endif()
216
217
                            set(CAMITK_ITK_LIBRARIES ${CAMITK_ITK_LIBRARIES} debug ${ITK_DIR}/${ITK_LIBRARY}-${CAMITK_ITK_VERSION}${CAMITK_DEBUG_POSTFIX}.lib optimized ${ITK_DIR}/${ITK_LIBRARY}-${CAMITK_ITK_VERSION}.lib)
                        endforeach()
218
219
                    elseif(UNIX)
                        set(CAMITK_ITK_LIBRARIES ${ITK_LIBRARIES})
220
                    elseif(APPLE)
221
                        message(WARNING "CamiTKExtension.cmake: ITK LIBRARY NOT SET FOR APPLE")
222
                    endif()
223
224
                else()
                    message(FATAL_ERROR "Wrong version of ITK : ${ITK_VERSION}. Required is at least 4.x to 4.9")
225
                endif()
226
227
            else()
                message(FATAL_ERROR "ITK not found but required for ${APPLICATION_TARGET_NAME}")
228
            endif()
229
        endif()
promayon's avatar
promayon committed
230

231
232
233
234
235
236
237
        # XERCES-C
        set(XERCESC_LIBRARIES)
        if(${APPLICATION_NAME_CMAKE}_NEEDS_XERCESC)
          # XercesC is required
          find_package(XercesC REQUIRED)
          if (XERCESC_FOUND)
            include_directories(${XERCESC_INCLUDE_DIR})
238
            set(XERCESC_LIBRARIES ${XERCESC_LIBRARY})
239
240
          else()
            # most probably win32 or crosscompiling
241
            message(FATAL_ERROR "${APPLICATION_NAME}: xerces-c required. Please provide Xerces-C path.")
242
243
          endif()
        endif()
promayon's avatar
promayon committed
244

245
246
247
248
249
250
        # XSD
        if(${APPLICATION_NAME_CMAKE}_NEEDS_XSD)
            # XercesC is required
            find_package(XercesC REQUIRED)
            if (XERCESC_FOUND)
                include_directories(${XERCESC_INCLUDE_DIR})
251
                set(XERCESC_LIBRARIES ${XERCESC_LIBRARY})
252
253
254
255
                find_package(XSD REQUIRED)
                include_directories(${XSD_INCLUDE_DIR})
            else()
                # most probably win32 or crosscompiling
256
                message(FATAL_ERROR "${APPLICATION_NAME}: xerces-c required because of XSD cxx, please set XERCESC_INCLUDE_DIR")
257
258
            endif()
        endif()
promayon's avatar
promayon committed
259

260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
        # PYTHON
        set(PYTHON_LIBRARIES "")
        if(${APPLICATION_NAME_CMAKE}_NEEDS_PYTHON)
            message(STATUS "Python needed by ${APPLICATION_NAME}")
            find_package(PythonLibs 2.7 REQUIRED)
            if(PYTHONLIBS_FOUND)
                message(STATUS "Python found (needed by ${APPLICATION_NAME})")
                include_directories(${PYTHON_INCLUDE_DIRS})
                # PYTHON_LIRARIES is automatically and correctly set by find_package
            else()
                message(FATAL_ERROR "Python (2.7 or above) is required by ${APPLICATION_NAME} : please add your python installation dir to your PATH environment variable")
            endif()
        endif()
        
        # EXTERNAL LIBRARIES
        set(EXTERNAL_LIBRARIES)
        if(${APPLICATION_NAME_CMAKE}_EXTERNAL_LIBRARIES)
            foreach(EXTERNAL_LIBRARY ${${APPLICATION_NAME_CMAKE}_EXTERNAL_LIBRARIES})
saubatn's avatar
saubatn committed
278
                if (MSVC) # TODO We have to decide how to handle debug version of external libraries
279
                    set(EXTERNAL_LIBRARIES ${EXTERNAL_LIBRARIES} 
280
                                           debug ${EXTERNAL_LIBRARY}${CAMITK_DEBUG_POSTFIX}.lib
281
282
283
284
285
286
287
288
289
290
                                           optimized ${EXTERNAL_LIBRARY}
                    )
                else()
                    set(EXTERNAL_LIBRARIES ${EXTERNAL_LIBRARIES} ${EXTERNAL_LIBRARY})
                endif()
            endforeach()
        endif()
        
        # BACKWARD COMPATIBILITY
        # NEEDS_TOOLS option
291
292
293
        # TODO CAMITK_DEPRECATED. This option is marked as deprecated. It is to be removed in CamiTK 4.0
        # check deprecated (and warn)
        # TODO CAMITK_DEPRECATED. This option is marked as deprecated. It is to be removed in CamiTK 4.0
294
295
296
297
298
299
300
        if(${APPLICATION_NAME_CMAKE}_NEEDS_TOOL)
            message(WARNING "Warning: ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt: camitk_application macro option NEEDS_TOOL is deprecated, please use NEEDS_CEP_LIBRARIES instead..")
            set(CEP_LIBRARIES ${CEP_LIBRARIES} ${${APPLICATION_NAME_CMAKE}_NEEDS_TOOL})
        endif()
        
        
        
301
302
303
304
305
306
307
308
309
310
311
312
        #########################################################################
        #                                                                       #
        #   LINK DIRECTORIES                                                    #
        #                                                                       #
        #   * Link directories are used to indicate the compiler where          #
        #     to look for folder containing libraries to link with.             #
        #                                                                       #
        #########################################################################
        # CAMITK BASIC LIB DIRECTORIES
        link_directories(${CAMITK_LINK_DIRECTORIES})
        
        
313
314
315
316
317
318
319
320
321
322
323
324
325
        
        #########################################################################
        #                                                                       #
        #   TARGET COMPILATION DEFINITION                                       #
        #                                                                       #
        #   * Additional sources files to consider at compilation (.cpp)        #
        #   * CMake project target definition                                   #
        #                                                                       #
        #########################################################################
        # CMAKE TARGET DEFINITION
        add_executable(${APPLICATION_TARGET_NAME} ${${APPLICATION_NAME}_SOURCES})
        
        
326

327
328
329
330
331
332
333
334
335
336
337
        #########################################################################
        #                                                                       #
        #   QT LINKING LIBRARIES                                                #
        #                                                                       #
        #   * Set at linking the Qt5 libraries                                  #
        #                                                                       #
        #########################################################################
        qt5_use_modules(${APPLICATION_TARGET_NAME} ${CAMITK_QT_COMPONENTS})
        
        
        
338
339
        #########################################################################
        #                                                                       #
340
        #   CAMITK ACTION / COMPONENT / LIBRARIES DEPENDENCIES                  #
341
        #                                                                       #
342
343
344
345
346
        #   * 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            #
        #     action/component if test are runned on it                         #                                                                                       
347
348
349
        #                                                                       #
        #########################################################################
        
350
351
352
353
        # 1st CAMITKCORE LIBRARY DEPENDENCY
        add_dependencies(${APPLICATION_TARGET_NAME} ${CAMITK_CORE_TARGET_LIB_NAME})

        # 2nd COMPONENTS DEPENDENCIES
354
        if(${APPLICATION_NAME_CMAKE}_NEEDS_COMPONENT_EXTENSION)
355
            set(COMPONENTS_DEPENDENCY_LIST "") #use for generating the project.xml file
356
            foreach(COMPONENT_NEEDED ${${APPLICATION_NAME_CMAKE}_NEEDS_COMPONENT_EXTENSION})
357
                # include directories from build, camitk (local or global install).
358
359
360
                include_directories(${CAMITK_BUILD_INCLUDE_DIR}/components/${COMPONENT_NEEDED})
                include_directories(${CAMITK_INCLUDE_DIR}/components/${COMPONENT_NEEDED})
                # file dependency
361
362
                if (MSVC)
                    set(COMPONENT_EXTENSION_LIBRARIES ${COMPONENT_EXTENSION_LIBRARIES}
363
                                                    debug ${CAMITK_BUILD_PRIVATE_LIB_DIR}/components/${COMPONENT_NEEDED}${CAMITK_DEBUG_POSTFIX}.lib
364
365
366
367
368
                                                    optimized ${COMPONENT_NEEDED}
                    )
                else()
                    set(COMPONENT_EXTENSION_LIBRARIES ${COMPONENT_EXTENSION_LIBRARIES} ${COMPONENT_NEEDED})
                endif()
369
                # CMake / CDash dependencies
370
                if(PACKAGING_NSIS)
371
                    add_dependencies(${APPLICATION_TARGET_NAME} component_${COMPONENT_NEEDED})
372
                else()
373
                    add_dependencies(${APPLICATION_TARGET_NAME} component-${COMPONENT_NEEDED})
374
                    set(COMPONENTS_DEPENDENCY_LIST ${COMPONENTS_DEPENDENCY_LIST} component-${COMPONENT_NEEDED})
375
                endif()
376
377
            endforeach()
        endif()
378
379

        # 3rd ACTIONS DEPENDENCIES
380
        if(${APPLICATION_NAME_CMAKE}_NEEDS_ACTION_EXTENSION)
381
            set(ACTIONS_DEPENDENCY_LIST "") #use for generating the project.xml file
382
            foreach(ACTION_NEEDED ${${APPLICATION_NAME_CMAKE}_NEEDS_ACTION_EXTENSION})
383
                # include directories from build, camitk (local or global install).
384
                include_directories(${CAMITK_BUILD_INCLUDE_DIR}/actions/${ACTION_NEEDED})
385
                include_directories(${CAMITK_INCLUDE_DIR}/actions/${ACTION_NEEDED})
386
                # file dependency
387
388
                if (MSVC)
                    set(ACTION_EXTENSION_LIBRARIES ${ACTION_EXTENSION_LIBRARIES}
389
                                                   debug ${CAMITK_BUILD_PRIVATE_LIB_DIR}/actions/${ACTION_NEEDED}${CAMITK_DEBUG_POSTFIX}.lib
390
391
392
393
394
                                                   optimized ${ACTION_NEEDED}
                    )
                else()
                    set(ACTION_EXTENSION_LIBRARIES ${ACTION_EXTENSION_LIBRARIES} ${ACTION_NEEDED})
                endif()
395
396
                # CMake / CDash dependencies
                if (PACKAGING_NSIS)
397
                    add_dependencies(${APPLICATION_TARGET_NAME} action_${ACTION_NEEDED})
398
                else()
399
                    add_dependencies(${APPLICATION_TARGET_NAME} action-${ACTION_NEEDED})
400
401
402
403
404
405
406
407
408
                    set(ACTIONS_DEPENDENCY_LIST ${ACTIONS_DEPENDENCY_LIST} action-${ACTION_NEEDED})
                endif()
            endforeach()
        endif()

        # 4th CEP LIBRARIES DEPENDENCIES
        if(${APPLICATION_NAME_CMAKE}_NEEDS_CEP_LIBRARIES)
            set(CEP_LIBRARIES_DEPENDENCY_LIST "") #use for generating the project.xml file
            foreach(CEP_LIBRARY_NEEDED ${${APPLICATION_NAME_CMAKE}_NEEDS_CEP_LIBRARIES})
409
                 # include directories from build, camitk (local or global install).
410
411
412
413
                include_directories(${CAMITK_BUILD_INCLUDE_DIR}/libraries/${CEP_LIBRARY_NEEDED})
                include_directories(${CAMITK_INCLUDE_DIR}/libraries/${CEP_LIBRARY_NEEDED})
                # file dependency
                if (MSVC)
414
                        set(CEP_LIBRARIES ${CEP_LIBRARIES}  debug ${CEP_LIBRARY_NEEDED}${CAMITK_DEBUG_POSTFIX}.lib
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
                                                            optimized ${CEP_LIBRARY_NEEDED}
                        )
                else()
                    if(PACKAGING_NSIS)
                        set(CEP_LIBRARIES ${CEP_LIBRARIES} ${CEP_LIBRARY_NEEDED})
                    else()
                        set(CEP_LIBRARIES ${CEP_LIBRARIES} ${CEP_LIBRARY_NEEDED})
                    endif()
                endif()
                # CMake / CDash dependencies
                if (PACKAGING_NSIS)
                    add_dependencies(${APPLICATION_TARGET_NAME} library_${CEP_LIBRARY_NEEDED})
                else()
                    add_dependencies(${APPLICATION_TARGET_NAME} library-${CEP_LIBRARY_NEEDED})
                    set(CEP_LIBRARIES_DEPENDENCY_LIST ${CEP_LIBRARIES_DEPENDENCY_LIST} library-${CEP_LIBRARY_NEEDED})
430
                endif()
431
432
433
434
            endforeach()
        endif()
            
        
435

436
        #########################################################################
saubatn's avatar
saubatn committed
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
        #                                                                       #
        #   COMPILATION FLAG                                                    #
        #                                                                       #
        #   * Flags are options to give to the compiler                         #
        #   * Add user input flags                                              #
        #   * Add platform specific flags                                       #
        #                                                                       #
        #########################################################################

        # USER INPUT COMPILER FLAG
        if(${APPLICATION_NAME_CMAKE}_DEFINES)
          foreach (FLAG ${${APPLICATION_NAME_CMAKE}_DEFINES})
            add_definitions(-D${FLAG})
          endforeach()
        endif()
452
453
454
455
456
457
458
        
        # USER INPUT CUSTOM COMPILER FLAG
        if(${APPLICATION_NAME_CMAKE}_CXX_FLAGS)
          foreach (FLAG ${${APPLICATION_NAME_CMAKE}_CXX_FLAGS})
            set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAG}")
          endforeach()
        endif()
saubatn's avatar
saubatn committed
459
460
461
       
        
        
462
463
464
465
466
467
468
469
470
        #########################################################################
        #                                                                       #
        #   LINKING                                                             #
        #                                                                       #
        #   * Linking is the last stage of compilation                          #
        #   * Indicate what libraries to use for linking the target             #
        #                                                                       #
        #########################################################################
        # LINKING LIBRARIES
471
        target_link_libraries(${APPLICATION_TARGET_NAME} ${CAMITK_CORE_LIBRARIES} ${CAMITK_LIBRARIES}  ${COMPONENT_EXTENSION_LIBRARIES} ${ACTION_EXTENSION_LIBRARIES} ${CEP_LIBRARIES} ${XERCESC_LIBRARY} ${CAMITK_ITK_LIBRARIES} ${PYTHON_LIBRARIES} ${EXTERNAL_LIBRARIES})
promayon's avatar
promayon committed
472

473
        
promayon's avatar
promayon committed
474

475
476
477
478
479
480
481
482
483
        #########################################################################
        #                                                                       #
        #   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  #
        #                                                                       #
        #########################################################################
484
      
485
486
487
488
489
490
491
492
493
494
495
        # OUTPUT NAME
        if (MSVC)
            set_target_properties(${APPLICATION_TARGET_NAME}
                                  PROPERTIES OUTPUT_NAME camitk-${APPLICATION_NAME}
                                  DEBUG_POSTFIX ${CAMITK_DEBUG_POSTFIX}
            )
        else()
            set_target_properties(${APPLICATION_TARGET_NAME}
                                  PROPERTIES OUTPUT_NAME camitk-${APPLICATION_NAME}
            )
        endif()
promayon's avatar
promayon committed
496

497
498
499
500
501
        # OUTPUT DIRECTORY LOCATION
        # always in bin folder
        set_target_properties(${APPLICATION_TARGET_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CAMITK_BUILD_BIN_DIR}
                                                                    RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CAMITK_BUILD_BIN_DIR}
                                                                    RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CAMITK_BUILD_BIN_DIR}
502
        )    
503
504
505
506
507
508
509
510
511
512
513
    
        #########################################################################
        #                                                                       #
        #   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) #
        #                                                                       #
        #########################################################################
promayon's avatar
promayon committed
514

515
516
        # FOLDER INSTALLATION
        # Indicate where to install the application
517
#		if (NOT APPLE)
518
519
520
521
			install(TARGETS ${APPLICATION_TARGET_NAME}
            		RUNTIME DESTINATION bin
               		COMPONENT ${APPLICATION_TARGET_NAME}
        	)
522
523
524
525
526
 #   	else ()
#		set (PLUGINS QtCore QtGui QtXml QtXmlPatterns)
#		    include(DeployQt4)
#		    install_qt4_executable("bin/camitk-${APPLICATION_NAME}.app" "${PLUGINS}")
#		endif()
527
528
529
530
    
        
        
        #########################################################################
531
532
533
        #                                                                       #
        #   CDASH SUBPROJECT DESCRIPTION                                        #
        #                                                                       #
534
535
        #   * Update the XML descriton of the subprojects dependenicies         #
        #     for CDash.                                                        #
536
        #                                                                       #
537
        #########################################################################       
538
        # CDASH XML SUBPROJECTS DESCRIPTION UPDATE
539
540
541
542
543
        if(NOT ((APPLICATION_TARGET_NAME STREQUAL "application-testactions") OR (APPLICATION_TARGET_NAME STREQUAL "application-testcomponents")))
            # We will add manually the CDash dependencies of the testing applications
            # See CamiTKSubProjectValidate.cmake
            camitk_sub_project_add(APPLICATION ${APPLICATION_TARGET_NAME} DEPENDENCIES library-camitkcore ${COMPONENTS_DEPENDENCY_LIST} ${ACTIONS_DEPENDENCY_LIST} ${CEP_LIBRARIES_DEPENDENCY_LIST})
        endif()
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
        #####################################################################################
        #                                                                                   #
        #   TRANSLATION                                                                     #
        #                                                                                   #
        #   * CAMITK_TRANSLATIONS contains the list of language to translate                #
        #    the QString to.                                                                #
        #                                                                                   #
        #   * Create the translate.pro file which contains 4 sections:                      #
        #        - HEADERS:      list of .h/.hpp files to look for tr("") QString           #     
        #        - SOURCES:      list of .cpp files to look for tr("") QString              #
        #        - FORMS:        list of .ui files to look for tr("") QString               #            
        #        - 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                                                                    #
        #                                                                                   #
        #####################################################################################
570
571
572
573
574
575
        if(CAMITK_TRANSLATE)
            if(${APPLICATION_NAME_CMAKE}_EXTRA_TRANSLATE_LANGUAGE)
                camitk_translate(EXTRA_LANGUAGE ${${APPLICATION_NAME_CMAKE}_EXTRA_TRANSLATE_LANGUAGE})
            else()
                camitk_translate()
            endif()
576
577
578
        endif()
        
            
579
580
581
582
583
584
585
586
587
588
589
590
591
        #########################################################################
        #                                                                       #
        #   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.                               #
        #                                                                       #
        #########################################################################
592
    
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
        # WINDOWS INSTALLER CATEGORIZATION
        if(${APPLICATION_NAME_CMAKE}_CEP_NAME)
            if (${APPLICATION_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(${APPLICATION_TARGET_NAME}
                                    DISPLAY_NAME ${APPLICATION_TARGET_NAME}
                                    DESCRIPTION ${${APPLICATION_NAME_CMAKE}_DESCRIPTION}
                                    REQUIRED
                                    GROUP SDK
                                    )
            
            else()
                # Extension is selectable for installation in the wizard of the installer
                cpack_add_component(${APPLICATION_TARGET_NAME}
                                    DISPLAY_NAME ${APPLICATION_TARGET_NAME}
                                    DESCRIPTION ${${APPLICATION_NAME_CMAKE}_DESCRIPTION}
                                    GROUP ${${APPLICATION_NAME_CMAKE}_CEP_NAME}
                                    )
            endif()
        else()
            # Extension if not categorized for packaging presentation
            cpack_add_component(${APPLICATION_TARGET_NAME}
                                DISPLAY_NAME ${APPLICATION_TARGET_NAME}
                                DESCRIPTION ${${APPLICATION_NAME_CMAKE}_DESCRIPTION}
                                )
        
        endif()
promayon's avatar
promayon committed
620

621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
        # additional unix system files/resources
        if(UNIX)
            # Man page installation
            set(${APPLICATION_NAME_CMAKE}_MAN_PAGE ${CMAKE_CURRENT_SOURCE_DIR}/resources/camitk-${APPLICATION_NAME}.1)
            if (EXISTS ${${APPLICATION_NAME_CMAKE}_MAN_PAGE})
                message(STATUS "Found man page for ${APPLICATION_TARGET_NAME}")
                install(FILES ${${APPLICATION_NAME_CMAKE}_MAN_PAGE}
                        DESTINATION ${CAMITK_APPLICATION_MAN_INSTALL_DIR}
                )
            else()
                # check if .in exists
                if (EXISTS ${${APPLICATION_NAME_CMAKE}_MAN_PAGE}.in)
                    message(STATUS "Found man page configuration file for ${APPLICATION_TARGET_NAME}")
                    install(CODE "message(STATUS \"Updating ${APPLICATION_NAME} man page (version ${CAMITK_VERSION_MAJOR}.${CAMITK_VERSION_MINOR} as of ${CURRENT_DATE})\")")
                    # set variable in sub-cmake shell
                    install(CODE "set(APPLICATION_NAME ${APPLICATION_NAME})")
                    install(CODE "set(CURRENT_DATE ${CURRENT_DATE})")
                    install(CODE "set(CAMITK_VERSION_MAJOR ${CAMITK_VERSION_MAJOR})")
                    install(CODE "set(CAMITK_VERSION_MINOR ${CAMITK_VERSION_MINOR})")
                    # remove previous version
                    install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E remove -f ${CMAKE_CURRENT_BINARY_DIR}/camitk-${APPLICATION_NAME}.1)")
                    # configure current version
                    install(CODE "configure_file(${CMAKE_CURRENT_SOURCE_DIR}/resources/camitk-${APPLICATION_NAME}.1.in ${CMAKE_CURRENT_BINARY_DIR}/camitk-${APPLICATION_NAME}.1 @ONLY)")
                    # install file
                    install(FILES ${CMAKE_CURRENT_BINARY_DIR}/camitk-${APPLICATION_NAME}.1 DESTINATION ${CAMITK_APPLICATION_MAN_INSTALL_DIR})
                endif()
            endif()
648

649
650
651
652
653
654
            # Desktop file
            set(${APPLICATION_NAME_CMAKE}_DESKTOP ${CMAKE_CURRENT_SOURCE_DIR}/resources/camitk-${APPLICATION_NAME}.desktop)
            if (EXISTS ${${APPLICATION_NAME_CMAKE}_DESKTOP})
                message(STATUS "Found desktop file for ${APPLICATION_TARGET_NAME}")
                install(FILES ${${APPLICATION_NAME_CMAKE}_DESKTOP} DESTINATION ${CAMITK_APPLICATION_DESKTOP_INSTALL_DIR})
            endif()
655

656
657
658
659
660
661
662
663
            # application pixmap
            set(${APPLICATION_NAME_CMAKE}_PIXMAP ${CMAKE_CURRENT_SOURCE_DIR}/resources/camitk-${APPLICATION_NAME}.xpm)
            if (EXISTS ${${APPLICATION_NAME_CMAKE}_PIXMAP})
                message(STATUS "Found pixmap for ${APPLICATION_TARGET_NAME}")
                install(FILES ${${APPLICATION_NAME_CMAKE}_PIXMAP} DESTINATION ${CAMITK_APPLICATION_PIXMAP_INSTALL_DIR})
            endif()
            
        endif()
664

665
    endif() #APPLICATION_${APPLICATION_NAME_CMAKE}
promayon's avatar
promayon committed
666
667

endmacro()