CamiTKLibrary.cmake 37.4 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
9
10
11
12
13
14
15
16
#!
#! macro camitk_library simplifies the declaration of a library inside CamiTK
#! and is to be used for all inner project libraries
#!
#! The name of the CEP library is deduced from the name of the directory, unless LIBNAME is provided
#!
#! If the library is compiled as shared, it adds the needed library properties
#! If it needs relocation flag fPIC (on some plateforms), this macro should determine
#! if this is the case and specify this flag
#!
#! usage:
#! \code
#! camitk_library(
#!     SHARED|STATIC
17
#!     SOURCES source1.cpp source1.h...
18
19
20
#!     [LIBNAME libname]
#!     [PUBLIC]
#!     [NEEDS_CEP_LIBRARIES lib1 lib2...]
21
#!     [NEEDS_ITK]
promayon's avatar
promayon committed
22
23
24
#!     [NEEDS_LIBXML2]
#!     [NEEDS_XERCESC]
#!     [NEEDS_XSD]
25
#!     [NEEDS_QT]
26
#!     [DEFINES flag1 flag2 ...]
27
28
#!     [EXTERNAL_LIBRARIES lib1 lib2... ]
#!     [INCLUDE_DIRECTORIES dir1 dir2...]
promayon's avatar
promayon committed
29
#!     [LINK_DIRECTORIES dir1 dir2...]
30
31
32
#!     [HEADERS_TO_INSTALL]
#!     [CEP_NAME]
#!     [DESCRIPTION]
33
#!     [EXTRA_TRANSLATE_LANGUAGE]
34
#!     [CXX_FLAGS flag1 flag2 ...]
35
#!
promayon's avatar
promayon committed
36
37
38
39
40
41
#! )
#! \endcode
#!
#! \param SHARED                        optional, if the library should be compiled as shared
#! \param SOURCES                       all sources to be included in the library
#! \param INCLUDE_DIRECTORIES           all needed include directories (${CMAKE_CURRENT_SOURCE_DIR} and ${CMAKE_CURRENT_BINARY_DIR} are automatically added)
42
43
#! \param EXTERNAL_LIBRARIES            all the libraries to be used during the link (shared or static)
#! \param NEEDS_CEP_LIBRARIES           all the libraries to be used during the link (shared or static)
44
#! \param NEEDS_ITK                     add this if your component needs ITK.
promayon's avatar
promayon committed
45
46
47
#! \param NEEDS_LIBXML2                 add this if the CEP library needs libxml2
#! \param NEEDS_XERCESC                 add this if your action / component needs XercesC library
#! \param NEEDS_XSD                     add this if your action needs Codesynthesis xsd cxx (xml schema compiler)
48
#! \param NEEDS_QT                      add this if your library depends on Qt 5.x
promayon's avatar
promayon committed
49
50
#! \param LIBNAME                       force the CEP library name to be different from the directory it is in
#! \param LINK_DIRECTORIES              additional directories to use in link_directories(...)
51
#! \param DEFINES                       list of define flags to add at compilation time
promayon's avatar
promayon committed
52
53
54
#! \param PUBLIC                        The library is a public library that has to be loaded directly by the operating system.
#!                                      It is generally only needed for SDK library. A public library should not be installed in the
#!                                      lib/${CAMITK_SHORT_VERSION_STRING} but directly in lib/ (on Unix/MacOS) or bin/ (on windows)
55
56
57
#! \param HEADERS_TO_INSTALL            list of header files to install. File would be copied at build and installation time
#!                                      in the ./include/libraries/library-name subdirectory.
#!                                      Note that, if no header files are provided, all header files (*.h) will be install.
58
59
60
#! \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.
61
#! \param EXTRA_TRANSLATE_LANGUAGE      Additionnal extra language to translate the application
62
#! \param CXX_FLAGS                 = list of compiler flags to add (such as warning levels (-Wall ...)).
63

promayon's avatar
promayon committed
64
macro(camitk_library)
65

66
67
68
69
70
71
72
73
    #########################################################################
    #                                                                       #
    #   ARGUMENTS PARSING                                                   #
    #                                                                       #
    #   * Use a macro to create the CMAKE variables according to the        #
    #     provided options as input.                                        #
    #                                                                       #
    #########################################################################
74

75
    get_directory_name(${CMAKE_CURRENT_SOURCE_DIR} DEFAULT_LIBRARY_NAME)
promayon's avatar
promayon committed
76

77
    parse_arguments(${DEFAULT_LIBRARY_NAME_CMAKE}
78
        "SOURCES;NEEDS_CEP_LIBRARIES;EXTERNAL_LIBRARIES;INCLUDE_DIRECTORIES;LIBNAME;DEFINES;LINK_DIRECTORIES;HEADERS_TO_INSTALL;CEP_NAME;DESCRIPTION;EXTRA_TRANSLATE_LANGUAGE;CXX_FLAGS"  # possible lists
79
        "SHARED;STATIC;NEEDS_ITK;NEEDS_LIBXML2;NEEDS_XERCESC;NEEDS_XSD;NEEDS_QT;PUBLIC" # possible options
80
81
        ${ARGN}
    )
82

83
84
85
86
87
88
89
90
91
92
	
	#########################################################################
    #                                                                       #
    #   Consider moc sources files                                          #
    #                                                                       #
    #   * if you use Q_OBJECT in your classes                               #
    #                                                                       #
    #########################################################################
	file(GLOB_RECURSE MOC_SRCS ${CMAKE_CURRENT_BINARY_DIR}/moc_*.cxx)
	set(${DEFAULT_LIBRARY_NAME_CMAKE}_SOURCES ${${DEFAULT_LIBRARY_NAME_CMAKE}_SOURCES} ${MOC_SRCS})
93
94


95
    #########################################################################
96
97
98
    #                                                                       #
    #   CREATE CMAKE VARIABLES                                              #
    #                                                                       #
99
    #   * Create required and useful CMake variables for the macro         #
100
101
    #                                                                       #
    #########################################################################
102

103
    # TARGET NAME
saubatn's avatar
saubatn committed
104
    # The target name is composed of the following: library-name
105
106
    # * library is the suffix
    # * name is deduced from the input folder containing the calling CMakeLists.txt file of the extension.
107
    # "-" is replaced by "_" if configuring for packaging with NSIS, the program to create a Windows installer.
108
109
    if (PACKAGING_NSIS)
        if ("${${DEFAULT_LIBRARY_NAME_CMAKE}_LIBNAME}" STREQUAL "")
110
            set(LIBRARY_TARGET_NAME library_${DEFAULT_LIBRARY_NAME})
111
        else()
112
            set(LIBRARY_TARGET_NAME library_${${DEFAULT_LIBRARY_NAME_CMAKE}_LIBNAME})
113
114
115
        endif()
    else()
        if ("${${DEFAULT_LIBRARY_NAME_CMAKE}_LIBNAME}" STREQUAL "")
116
            set(LIBRARY_TARGET_NAME library-${DEFAULT_LIBRARY_NAME})
117
        else()
118
            set(LIBRARY_TARGET_NAME library-${${DEFAULT_LIBRARY_NAME_CMAKE}_LIBNAME})
119
120
        endif()
    endif()
121
122


promayon's avatar
promayon committed
123

124
125
126
127
128
129
130
131
132
    #########################################################################
    #                                                                       #
    #   INCLUDE DIRECTORIES                                                 #
    #                                                                       #
    #   * Include library directories where to look for header files        #
    #   * Include also additional user provided directories                 #
    #   * These directories are used for compilation step                   #
    #                                                                       #
    #########################################################################
133

134
    # BASIC DIRECTORIES
135
    include_directories(${CAMITK_INCLUDE_DIRECTORIES})
136
137
138
    include_directories(${CMAKE_CURRENT_SOURCE_DIR})
    include_directories(${CMAKE_CURRENT_BINARY_DIR})

139
    # USER PROVIDED ADDITIONAL DIRECTORIEs
140
    include_directories(${${DEFAULT_LIBRARY_NAME_CMAKE}_INCLUDE_DIRECTORIES})
141
142
143
144
145
146
147
148
149
150
151
152
153
    
    
    
    #########################################################################
    #                                                                       #
    #   GROUP RESOURCES                                                     #
    #                                                                       #
    #   * On Windows, Visual Studio, group .moc and .ui files               #
    #     in subdirectories                                                 # 
    #                                                                       #
    #########################################################################
    if(MSVC)
        source_group("Source Files\\Moc Files" "moc_*")
154
155
        source_group("Source Files\\CLI Files" "CommandLineOptions.*")
        source_group("Header Files\\UI Files" "ui_*.h")
156
157
        source_group("Source Files\\Resources Files" "qrc_*")
        source_group("Source Files\\Resources Files" "*.qrc")
158
        source_group("UI Files" "*.ui")
159
    endif()
160
161


saubatn's avatar
saubatn committed
162

163
164
165
166
167
168
169
170
171
172
    #########################################################################
    #                                                                       #
    #   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 #
    #                                                                       #
    #########################################################################
173

174
175
176
177
    # Looking for ITK
    set(ITK_LIBRARIES "")
    if(${DEFAULT_LIBRARY_NAME_CMAKE}_NEEDS_ITK)
        find_package(ITK REQUIRED)
178
179
180
181
182
183
184
185
186
            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
                set(CAMITK_ITK_VERSION ${ITK_VERSION_MAJOR}.${ITK_VERSION_MINOR})
                message(STATUS "${${DEFAULT_LIBRARY_NAME_CMAKE}_TARGET_NAME}: Found ITK version ${ITK_VERSION}")

                if ((${ITK_VERSION} VERSION_GREATER "4") AND (${ITK_VERSION} VERSION_LESS "5")) # ITK 4.9 on Windows, maybe a lesser version for Linux.
                    if(MSVC)
                        set(ITK_DIR ${ITK_DIR}/../..)
187
                        # Construct list of ITK libraries for linking = CAMITK_ITK_LIBRARIES
188
189
                        foreach(ITK_LIBRARY ${ITK_LIBRARIES})
                        string(SUBSTRING ${ITK_LIBRARY} 0 3 ${ITK_LIBRARY}_PREFIX)
190
                            # Some libraries have not the expected 'itk' prefix. Add it then
191
192
193
194
195
196
197
198
199
200
201
202
                            if((NOT ${${ITK_LIBRARY}_PREFIX} STREQUAL "itk") AND (NOT ${${ITK_LIBRARY}_PREFIX} STREQUAL "ITK"))
                                set(ITK_LIBRARY itk${ITK_LIBRARY})
                            endif()
                            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()
                    elseif(UNIX)
                        set(CAMITK_ITK_LIBRARIES ${ITK_LIBRARIES})
                    elseif(APPLE)
                        message(WARNING "CamiTKExtension.cmake: ITK LIBRARY NOT SET FOR APPLE")
                    endif()
                else()
                    message(FATAL_ERROR "Wrong version of ITK : ${ITK_VERSION}. Required is at least 4.x to 4.9")
203
                endif()
204
205
            else()
                message(FATAL_ERROR "ITK not found but required for ${${DEFAULT_LIBRARY_NAME_CMAKE}_TARGET_NAME}")
206
            endif()
207
    endif()
208

209
    # LIBXML2
210
    set(LIBXML2_LIBRARY "")
211
212
213
214
215
216
    if(${DEFAULT_LIBRARY_NAME_CMAKE}_NEEDS_LIBXML2)
        # LibXml2 is required
        find_package(Xml2)
        if (LIBXML2_FOUND)
            add_definitions(${LIBXML2_DEFINITIONS})
            include_directories(${LIBXML2_INCLUDE_DIR})
217
            set(LIBXML2_LIBRARY ${LIBXML2_LIBRARIES})
218
219
        else()
            # most probably win32 or crosscompiling
220
            message(WARNING "${LIBRARY_TARGET_NAME}: libxml2 required")
221
        endif()
promayon's avatar
promayon committed
222
223
    endif()

224
    # XERCES-C
225
226
227
228
229
230
    set(XERCESC_LIBRARIES)
    if(${DEFAULT_LIBRARY_NAME_CMAKE}_NEEDS_XERCESC)
        # XercesC is required
        find_package(XercesC REQUIRED)
        if (XERCESC_FOUND)
            include_directories(${XERCESC_INCLUDE_DIR})
231
            set(XERCESC_LIBRARIES ${XERCESC_LIBRARY})
232
233
        else()
            # most probably win32 or crosscompiling
saubatn's avatar
saubatn committed
234
            message(FATAL_ERROR "${DEFAULT_LIBRARY_NAME}: xerces-c required. Please provide Xerces-C path.")
235
236
        endif()
    endif()
promayon's avatar
promayon committed
237

238
    # XSD
239
240
241
242
243
    if(${DEFAULT_LIBRARY_NAME_CMAKE}_NEEDS_XSD)
        # XercesC is required
        find_package(XercesC REQUIRED)
        if (XERCESC_FOUND)
            include_directories(${XERCESC_INCLUDE_DIR})
244
            set(XERCESC_LIBRARIES ${XERCESC_LIBRARY})
245
246
247
248
            find_package(XSD REQUIRED)
            include_directories(${XSD_INCLUDE_DIR})
        else()
            # most probably win32 or crosscompiling
249
            message(FATAL_ERROR "${LIBRARY_TARGET_NAME}: xerces-c required because of XSD cxx, please set XERCESC_INCLUDE_DIR")
250
251
        endif()
    endif()
252

253
254
    # QT
    if(${DEFAULT_LIBRARY_NAME_CMAKE}_NEEDS_QT)
255
256
257
        # Instruct CMake to run moc automatically when needed.
        set(CMAKE_AUTOMOC ON)
    
258
259
260
        set(QT_COMPONENTS Core Gui Xml XmlPatterns Widgets Help UiTools OpenGL OpenGLExtensions)
        find_package(Qt5 COMPONENTS ${QT_COMPONENTS} REQUIRED)
        if (Qt5_FOUND)
261
            # cmake_policy(SET CMP0020 NEW) # policy for Qt core linking to qtmain.lib
262
263
264
265
266
267
268
            message(STATUS "${LIBRARY_TARGET_NAME}: found Qt ${Qt5_VERSION}.")
            set(QT_INCLUDE_DIRS ${Qt5Widgets_INCLUDE_DIRS} ${Qt5Core_INCLUDE_DIRS} ${Qt5Gui_INCLUDE_DIRS} ${Qt5Xml_INCLUDE_DIRS} ${Qt5XmlPatterns_INCLUDE_DIRS} ${Qt5Declarative_INCLUDE_DIRS} ${Qt5Help_INCLUDE_DIRS} ${Qt5UiTools_INCLUDE_DIRS} ${Qt5OpenGL_INCLUDE_DIRS} ${Qt5OpenGLExtensions_INCLUDE_DIRS})
            include_directories(${QT_INCLUDE_DIRS})
        else()
            message(SEND_ERROR "${LIBRARY_TARGET_NAME}: Failed to find Qt 5.x. This is needed by ${LIBRARY_TARGET_NAME}.")
        endif()
    endif()
269

270
    # EXTERNAL DEPENDENCIES
271
    set(LINKER_EXTERNAL_LIBRARIES)
272
273
    if(${DEFAULT_LIBRARY_NAME_CMAKE}_EXTERNAL_LIBRARIES)
        foreach(EXTERNAL_LIBRARY ${${DEFAULT_LIBRARY_NAME_CMAKE}_EXTERNAL_LIBRARIES})
saubatn's avatar
saubatn committed
274
            if (MSVC)
275
                set(LINKER_EXTERNAL_LIBRARIES ${LINKER_EXTERNAL_LIBRARIES}
276
                                       debug ${EXTERNAL_LIBRARY}${CAMITK_DEBUG_POSTFIX}.lib
saubatn's avatar
saubatn committed
277
278
                                       optimized ${EXTERNAL_LIBRARY}
                )
279
                message(STATUS "LINKER_EXTERNAL_LIBRARIES = ${LINKER_EXTERNAL_LIBRARIES}")
saubatn's avatar
saubatn committed
280
            else()
281
                set(LINKER_EXTERNAL_LIBRARIES ${LINKER_EXTERNAL_LIBRARIES} ${EXTERNAL_LIBRARY})
saubatn's avatar
saubatn committed
282
283
284
            endif()
        endforeach()
    endif()
285
286
287



288
289
290
291
292
293
294
295
296
297
298
    #########################################################################
    #                                                                       #
    #   LINK DIRECTORIES                                                    #
    #                                                                       #
    #   * Link directories are used to indicate the compiler where          #
    #     to look for folder containing libraries to link with.             #
    #   * Additional link directories provided by the user                  #
    #                                                                       #
    #########################################################################
    # CAMITK BASIC LIB DIRECTORIES
    link_directories(${CAMITK_LINK_DIRECTORIES})
promayon's avatar
promayon committed
299

300
301
302
303
    # ADDITIONAL LINK DIRECTORIES
    if (NOT "${${DEFAULT_LIBRARY_NAME_CMAKE}_LINK_DIRECTORIES}" STREQUAL "")
        link_directories(${${DEFAULT_LIBRARY_NAME_CMAKE}_LINK_DIRECTORIES})
    endif()
promayon's avatar
promayon committed
304

305
306


307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
    #########################################################################
    #                                                                       #
    #   TARGET COMPILATION  DEFINITION                                      #
    #                                                                       #
    #   * Additional sources files to consider at compilation (.cpp)        #
    #   * CMake project target definition  depending on library type        #
    #     public / private                                                  #
    #                                                                       #
    #########################################################################
    # CMAKE TARGET DEFINITION DEPENDENDING ON THE LIBRARY TYPE (SHARED or STATIC)
    if (${DEFAULT_LIBRARY_NAME_CMAKE}_SHARED) # shared library
        message(STATUS "Building shared library: ${LIBRARY_TARGET_NAME}")
        add_library(${LIBRARY_TARGET_NAME} SHARED ${${DEFAULT_LIBRARY_NAME_CMAKE}_SOURCES})
        # prepare the library specific info (SONAME...)
        set(${LIBRARY_TARGET_NAME}_LIBRARY_PROPERTIES ${${LIBRARY_TARGET_NAME}_LIBRARY_PROPERTIES}
            VERSION   "${CAMITK_VERSION_MAJOR}.${CAMITK_VERSION_MINOR}.${CAMITK_VERSION_PATCH}"
            SOVERSION "${CAMITK_VERSION_MAJOR}"
        )
        # 
        set_target_properties(${LIBRARY_TARGET_NAME} PROPERTIES ${${LIBRARY_TARGET_NAME}_LIBRARY_PROPERTIES} LINK_INTERFACE_LIBRARIES "")
    elseif (${DEFAULT_LIBRARY_NAME_CMAKE}_STATIC) # static library
        message(STATUS "Building static library: ${LIBRARY_TARGET_NAME}")
        add_library(${LIBRARY_TARGET_NAME} STATIC ${${DEFAULT_LIBRARY_NAME_CMAKE}_SOURCES})        
    else()
        message(FATAL_ERROR "In adding static library ${LIBRARY_TARGET_NAME}.\n   Please specify the library type: SHARED or STATIC")
    endif()
                   
    
    
    #########################################################################
    #                                                                       #
    #   QT LINKING LIBRARIES                                                #
    #                                                                       #
    #   * Set at linking the Qt5 libraries                                  #
    #                                                                       #
    #########################################################################
    if(${DEFAULT_LIBRARY_NAME_CMAKE}_NEEDS_QT)
        qt5_use_modules(${LIBRARY_TARGET_NAME} ${QT_COMPONENTS})
    endif()
        
        
        
        
350
351
352
353
354
355
356
357
    #########################################################################
    #                                                                       #
    #   CAMITK LIBRARIES DEPENDENCIES                                       #
    #                                                                       #
    #   * Add in this section library dependencies to other camitk libraies #
    #     to keep a correct build order (NEEDS_CEP_LIBRARIES).              #
    #                                                                       #
    #########################################################################
358

359
360
361
362
363
    # CEP LIBRARIES DEPENDENCIES
    set(CEP_LIBRARIES)
    set(LIBRARIES_DEPENDENCY_LIST "") #use for generating the project.xml file
    if(${DEFAULT_LIBRARY_NAME_CMAKE}_NEEDS_CEP_LIBRARIES)
        foreach(CEP_LIBRARY_NEEDED ${${DEFAULT_LIBRARY_NAME_CMAKE}_NEEDS_CEP_LIBRARIES})
364
             # include directories from build, camitk (local or global install).
365
            include_directories(${CAMITK_BUILD_INCLUDE_DIR}/libraries/${CEP_LIBRARY_NEEDED})
366
            include_directories(${CAMITK_INCLUDE_DIR}/libraries/${CEP_LIBRARY_NEEDED})
367
368
            # file dependency
            if (MSVC)
369
                    set(CEP_LIBRARIES ${CEP_LIBRARIES} debug  ${CEP_LIBRARY_NEEDED}${CAMITK_DEBUG_POSTFIX}.lib
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
                                                       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(${LIBRARY_TARGET_NAME} library_${CEP_LIBRARY_NEEDED})
            else()
                add_dependencies(${LIBRARY_TARGET_NAME} library-${CEP_LIBRARY_NEEDED})
                set(LIBRARIES_DEPENDENCY_LIST ${LIBRARIES_DEPENDENCY_LIST} library-${CEP_LIBRARY_NEEDED})
            endif()
        endforeach()
    endif()
388
389
390



391
392
393
394
395
396
397
398
399
    #########################################################################
    #                                                                       #
    #   LINKING                                                             #
    #                                                                       #
    #   * Linking is the last stage of compilation                          #
    #   * Indicate what libraries to use for linking the target             #
    #                                                                       #
    #########################################################################
    # LINKING LIBRARIES
400
    target_link_libraries(${LIBRARY_TARGET_NAME} ${CEP_LIBRARIES} ${LINKER_EXTERNAL_LIBRARIES} ${LIBXML2_LIBRARY} ${CAMITK_ITK_LIBRARIES} ${XERCESC_LIBRARIES})
401
402
403



404
405
406
407
408
409
410
411
    #########################################################################
    #                                                                       #
    #   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  #
    #                                                                       #
412
413
    #########################################################################

414
415
    # OUTPUT DIRECTORY LOCATION and NAME depending on the type of the library (PUBLIC or PRIVATE)
    # DEBGUG POSTFIX FOR MSVC
416
417
    if (${DEFAULT_LIBRARY_NAME_CMAKE}_PUBLIC) # Public library => build in the bin folder
        if (MSVC)
418
            # With Visual Studio, public libraries are built in build\bin directory, else it's in build\lib
419
            set_target_properties(${LIBRARY_TARGET_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CAMITK_BUILD_BIN_DIR}
420
421
                                                                    LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CAMITK_BUILD_BIN_DIR}
                                                                    LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CAMITK_BUILD_BIN_DIR}
422
            )
423
            set_target_properties(${LIBRARY_TARGET_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CAMITK_BUILD_BIN_DIR}
424
425
                                                                    RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CAMITK_BUILD_BIN_DIR}
                                                                    RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CAMITK_BUILD_BIN_DIR}
426
            )
427
            set_target_properties(${LIBRARY_TARGET_NAME} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CAMITK_BUILD_BIN_DIR}
428
429
                                                                    ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CAMITK_BUILD_BIN_DIR}
                                                                    ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CAMITK_BUILD_BIN_DIR}
430
            )
431
            set_target_properties(${LIBRARY_TARGET_NAME} PROPERTIES DEBUG_POSTFIX ${CAMITK_DEBUG_POSTFIX})
promayon's avatar
promayon committed
432
        else()
433
434
435
436
437
438
            # for xcode generation, the <CONFIG> postfix should also be used, but "a la" UNIX (lib in /lib etc...)
            # no need to check the generator with if(CMAKE_GENERATOR STREQUAL Xcode), as the <CONFIG> postfix should
            # not affect the other unix generators
            set_target_properties(${LIBRARY_TARGET_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CAMITK_BUILD_PUBLIC_LIB_DIR}
                                                                    LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CAMITK_BUILD_PUBLIC_LIB_DIR}
                                                                    LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CAMITK_BUILD_PUBLIC_LIB_DIR}
439
            )
440
441
442
            set_target_properties(${LIBRARY_TARGET_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CAMITK_BUILD_PUBLIC_LIB_DIR}
                                                                    RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CAMITK_BUILD_PUBLIC_LIB_DIR}
                                                                    RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CAMITK_BUILD_PUBLIC_LIB_DIR}
443
            )
444
445
446
            set_target_properties(${LIBRARY_TARGET_NAME} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CAMITK_BUILD_PUBLIC_LIB_DIR}
                                                                    ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CAMITK_BUILD_PUBLIC_LIB_DIR}
                                                                    ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CAMITK_BUILD_PUBLIC_LIB_DIR}
447
            )
448
449
450
        endif()
    else() # Private library => build in lib folder
        if (MSVC)
451
            set_target_properties(${LIBRARY_TARGET_NAME} PROPERTIES DEBUG_POSTFIX ${CAMITK_DEBUG_POSTFIX})
452
        endif()
453
454
455
456
457
458
459
460
461
462
463
464
        set_target_properties(${LIBRARY_TARGET_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CAMITK_BUILD_PRIVATE_LIB_DIR}
                                                                LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CAMITK_BUILD_PRIVATE_LIB_DIR}
                                                                LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CAMITK_BUILD_PRIVATE_LIB_DIR}
        )
        set_target_properties(${LIBRARY_TARGET_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CAMITK_BUILD_PRIVATE_LIB_DIR}
                                                                RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CAMITK_BUILD_PRIVATE_LIB_DIR}
                                                                RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CAMITK_BUILD_PRIVATE_LIB_DIR}
        )
        set_target_properties(${LIBRARY_TARGET_NAME} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CAMITK_BUILD_PRIVATE_LIB_DIR}
                                                                ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CAMITK_BUILD_PRIVATE_LIB_DIR}
                                                                ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CAMITK_BUILD_PRIVATE_LIB_DIR}
        )
promayon's avatar
promayon committed
465
    endif()
466

467
    # OUTUPUT LIBRARY NAME (without the prefix "library-").
468
    string(REGEX REPLACE "^library_|^library-" "" LIBRARY_NAME ${LIBRARY_TARGET_NAME})
469
470
471
    set_target_properties(${LIBRARY_TARGET_NAME}
                           PROPERTIES OUTPUT_NAME ${LIBRARY_NAME}
    )
472
473
474



475
476
477
478
479
480
481
482
483
    #########################################################################
    #                                                                       #
    #   COMPILATION FLAG                                                    #
    #                                                                       #
    #   * Flags are options to give to the compiler                         #
    #   * Add user input flags                                              #
    #   * Add platform specific flags                                       #
    #                                                                       #
    #########################################################################
promayon's avatar
promayon committed
484

485
486
487
488
489
490
    # USER INPUT COMPILER FLAG
    if(${DEFAULT_LIBRARY_NAME_CMAKE}_DEFINES)
      foreach (FLAG ${${DEFAULT_LIBRARY_NAME_CMAKE}_DEFINES})
        add_definitions(-D${FLAG})
      endforeach()
    endif()
491

492
493
494
495
496
497
498
    # USER INPUT CUSTOM COMPILER FLAG
    if(${DEFAULT_LIBRARY_NAME_CMAKE}_CXX_FLAGS)
      foreach (FLAG ${${DEFAULT_LIBRARY_NAME_CMAKE}_CXX_FLAGS})
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAG}")
      endforeach()
    endif()

499
    # PLATFORM SPECIFIC COMPILER FLAG
500
501
502
503
504
505
    # 64bits and other platform with relocation needs -fPIC
    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)
506
        set_property(TARGET ${LIBRARY_TARGET_NAME} APPEND PROPERTY COMPILE_FLAGS -fPIC)
507
    endif()
508
509
510



511
512
513
514
515
    #########################################################################
    #                                                                       #
    #   INSTALLATION                                                        #
    #                                                                       #
    #   * When installing the project, header files (.h) and test data are  #
516
    #     copied into an installation folder to determine.                  #
517
518
519
520
    #   * Indicate in this section, where to install your project and which #
    #     files to copy into that folder (during local/global installation) #
    #                                                                       #
    #########################################################################
521

522
523
    # FOLDER INSTALLATION
    # Indicate where to install the library, dependending on its property (public / private)
524
525
526
527
528
529
530
531
532
533
    if (${DEFAULT_LIBRARY_NAME_CMAKE}_PUBLIC) # public library
        if(WIN32)
            # public library -> install in bin folder
            install(TARGETS ${LIBRARY_TARGET_NAME}
                    RUNTIME DESTINATION bin
                    LIBRARY DESTINATION lib
                    ARCHIVE DESTINATION lib/${CAMITK_SHORT_VERSION_STRING}
                    COMPONENT ${LIBRARY_NAME_INSTALL}
                    )
        else()
534
            # other public libraries -> install in lib folder
535
536
537
538
539
540
541
            install(TARGETS ${LIBRARY_TARGET_NAME}
                    RUNTIME DESTINATION lib
                    LIBRARY DESTINATION lib
                    ARCHIVE DESTINATION lib
                    COMPONENT ${LIBRARY_NAME_INSTALL}
                    )
        endif()
542
    else()
543
544
         # private library -> install in lib/camitk-version folder
            install(TARGETS ${LIBRARY_TARGET_NAME}
545
546
547
                RUNTIME DESTINATION lib/${CAMITK_SHORT_VERSION_STRING}
                LIBRARY DESTINATION lib/${CAMITK_SHORT_VERSION_STRING}
                ARCHIVE DESTINATION lib/${CAMITK_SHORT_VERSION_STRING}
548
                COMPONENT ${LIBRARY_NAME_INSTALL}
549
550
                )
    endif()
551

552
    # HEADER FILES (.h) INSTALLATION
553
    if(${DEFAULT_LIBRARY_NAME_CMAKE}_HEADERS_TO_INSTALL)
554
        # If headers information provided for installation => install them
555
        export_headers(${${DEFAULT_LIBRARY_NAME_CMAKE}_HEADERS_TO_INSTALL} COMPONENT ${LIBRARY_TARGET_NAME} GROUP libraries)
556
    else()
557
558
        # By default, install all headers and keep include directories structure
        camitk_install_all_headers(COMPONENT ${LIBRARY_TARGET_NAME} GROUP libraries)
559
    endif()
560
561
562



563
564
565
566
    #########################################################################
    #                                                                       #
    #   CDASH SUBPROJECT DESCRIPTION                                        #
    #                                                                       #
567
    #   * Update the XML descriton of the subprojects dependencies          #
568
569
    #     for CDash.                                                        #
    #                                                                       #
570
    #########################################################################
571
    # CDASH XML SUBPROJECTS DESCRIPTION UPDATE
572
573
574
575
576
577
    if(LIBRARY_TARGET_NAME STREQUAL "library-qtpropertybrowser")
        # library-qtpropertybrowser is a corelib as library-camitkcore depends on it
        camitk_sub_project_add(CORELIB ${LIBRARY_TARGET_NAME} DEPENDENCIES ${LIBRARIES_DEPENDENCY_LIST})
    else()
        camitk_sub_project_add(CEP_LIBRARY ${LIBRARY_TARGET_NAME} DEPENDENCIES ${LIBRARIES_DEPENDENCY_LIST})
    endif()
578
579
580



581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
    #####################################################################################
    #                                                                                   #
    #   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                                                                    #
    #                                                                                   #
    #####################################################################################
606
607
608
609
610
611
    if(CAMITK_TRANSLATE)
        if(${DEFAULT_LIBRARY_NAME_CMAKE}_EXTRA_TRANSLATE_LANGUAGE)
            camitk_translate(EXTRA_LANGUAGE ${${DEFAULT_LIBRARY_NAME_CMAKE}_EXTRA_TRANSLATE_LANGUAGE})
        else()
            camitk_translate()
        endif()
612
613
614
615
    endif()
    
    
    
616
617
618
619
620
621
622
623
624
625
626
627
628
    #########################################################################
    #                                                                       #
    #   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.                               #
    #                                                                       #
    #########################################################################
629

630
    # WINDOWS INSTALLER CATEGORIZATION
631
    if(${DEFAULT_LIBRARY_NAME_CMAKE}_CEP_NAME) # This input variable describes the category
632
633
634
635
636
637
638
639
        if (${DEFAULT_LIBRARY_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(${LIBRARY_TARGET_NAME}
                                DISPLAY_NAME ${LIBRARY_TARGET_NAME}
                                DESCRIPTION ${${DEFAULT_LIBRARY_NAME_CMAKE}_DESCRIPTION}
                                REQUIRED
                                GROUP SDK
                                )
640

641
642
643
644
645
646
647
648
649
650
651
652
653
654
        else()
            # Extension is selectable for installation in the wizard of the installer
            cpack_add_component(${LIBRARY_TARGET_NAME}
                                DISPLAY_NAME ${LIBRARY_TARGET_NAME}
                                DESCRIPTION ${${DEFAULT_LIBRARY_NAME_CMAKE}_DESCRIPTION}
                                GROUP ${${DEFAULT_LIBRARY_NAME_CMAKE}_CEP_NAME}
                                )
        endif()
    else()
        # Extension if not categorized for packaging presentation
        cpack_add_component(${LIBRARY_TARGET_NAME}
                            DISPLAY_NAME ${LIBRARY_TARGET_NAME}
                            DESCRIPTION ${${DEFAULT_LIBRARY_NAME_CMAKE}_DESCRIPTION}
                            )
655

656
    endif()
657

promayon's avatar
promayon committed
658
659
660
661
endmacro()

# Old macro to configure a tool
# Use camitk_library macro instead
662
# TODO CAMITK_DEPRECATED. This macro is marked as deprecated. It is to be removed in CamiTK 4.0
promayon's avatar
promayon committed
663
664
665
666
667
668
macro(camitk_tool)
        message(WARNING "Warning: ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt: camitk_tool macro is deprecated, please usecamitk_library(...) instead (use the same parameters).")
#         string(REPLACE "NEEDS_TOOL" "NEEDS_CEP_LIBRARIES" OBSOLETE_ARGN ${ARGN})
#         message(STATUS "**************************************** ${ARGN} ===>>> ${OBSOLETE_ARGN} ")
        camitk_library(${OBSOLETE_ARGN})
endmacro()