Computer Assited Medical Intervention Tool Kit  version 4.0
CamiTKLibrary.h
Go to the documentation of this file.
1 
65 
66  #########################################################################
67  # #
68  # ARGUMENTS PARSING #
69  # #
70  # * Use a macro to create the CMAKE variables according to the #
71  # provided options as input. #
72  # #
73  #########################################################################
74 
75  get_directory_name(${CMAKE_CURRENT_SOURCE_DIR} DEFAULT_LIBRARY_NAME)
76 
77  parse_arguments(${DEFAULT_LIBRARY_NAME_CMAKE}
78  "SOURCESNEEDS_CEP_LIBRARIESEXTERNAL_LIBRARIESINCLUDE_DIRECTORIESLIBNAMEDEFINESLINK_DIRECTORIESHEADERS_TO_INSTALLCEP_NAMEDESCRIPTIONEXTRA_TRANSLATE_LANGUAGECXX_FLAGS" # possible lists
79  "SHAREDSTATICNEEDS_ITKNEEDS_LIBXML2NEEDS_XERCESCNEEDS_XSDNEEDS_QTPUBLIC" # possible options
80  ${ARGN}
81  )
82 
83 
84  #########################################################################
85  # #
86  # Consider moc sources files #
87  # #
88  # * if you use Q_OBJECT in your classes #
89  # #
90  #########################################################################
91  file(GLOB_RECURSE MOC_SRCS ${CMAKE_CURRENT_BINARY_DIR}/moc_*.cxx)
92  set(${DEFAULT_LIBRARY_NAME_CMAKE}_SOURCES ${${DEFAULT_LIBRARY_NAME_CMAKE}_SOURCES} ${MOC_SRCS})
93 
94 
95  #########################################################################
96  # #
97  # CREATE CMAKE VARIABLES #
98  # #
99  # * Create required and useful CMake variables for the macro #
100  # #
101  #########################################################################
102 
103  # TARGET NAME
104  # The target name is composed of the following: library-name
105  # * library is the suffix
106  # * 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  if (PACKAGING_NSIS)
109  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  endif()
114  else()
115  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  endif()
120  endif()
121 
122 
123 
124  #########################################################################
125  # #
126  # INCLUDE DIRECTORIES #
127  # #
128  # * Include library directories where to look for header files #
129  # * Include also additional user provided directories #
130  # * These directories are used for compilation step #
131  # #
132  #########################################################################
133 
134  # BASIC DIRECTORIES
135  include_directories(${CAMITK_INCLUDE_DIRECTORIES})
136  include_directories(${CMAKE_CURRENT_SOURCE_DIR})
137  include_directories(${CMAKE_CURRENT_BINARY_DIR})
138 
139  # USER PROVIDED ADDITIONAL DIRECTORIEs
140  include_directories(${${DEFAULT_LIBRARY_NAME_CMAKE}_INCLUDE_DIRECTORIES})
141 
142 
143 
144  #########################################################################
145  # #
146  # GROUP RESOURCES #
147  # #
148  # * On Windows, Visual Studio, group .moc and .ui files #
149  # in subdirectories #
150  # #
151  #########################################################################
152  if(MSVC)
153  source_group("Source Files\\Moc Files" "moc_*")
154  source_group("Source Files\\CLI Files" "CommandLineOptions.*")
155  source_group("Header Files\\UI Files" "ui_*.h")
156  source_group("Source Files\\Resources Files" "qrc_*")
157  source_group("Source Files\\Resources Files" "*.qrc")
158  source_group("UI Files" "*.ui")
159  endif()
160 
161 
162 
163  #########################################################################
164  # #
165  # ADDITIONAL KNOWN LIBRARY DEPENDENCIES #
166  # #
167  # * Look for specific library needed #
168  # * Specific libraries are specified as option with the #
169  # NEEDS_LIBRARY syntax (see macro syntax for more options) #
170  # * Backward compatibility : Warn user if using old NEEDS_TOOL syntax #
171  # #
172  #########################################################################
173 
174  # Looking for ITK
175  set(ITK_LIBRARIES "")
176  if(${DEFAULT_LIBRARY_NAME_CMAKE}_NEEDS_ITK)
177  find_package(ITK REQUIRED)
178  if(ITK_FOUND)
179  include(${ITK_USE_FILE})
180  set(ITK_VERSION ${ITK_VERSION_MAJOR}.${ITK_VERSION_MINOR}.${ITK_VERSION_PATCH}) #ITK_VERSION is not always set
181  set(CAMITK_ITK_VERSION ${ITK_VERSION_MAJOR}.${ITK_VERSION_MINOR})
182  message(STATUS "${${DEFAULT_LIBRARY_NAME_CMAKE}_TARGET_NAME}: Found ITK version ${ITK_VERSION}")
183 
184  if ((${ITK_VERSION} VERSION_GREATER "4") AND (${ITK_VERSION} VERSION_LESS "5")) # ITK 4.9 on Windows, maybe a lesser version for Linux.
185  if(MSVC)
186  set(ITK_DIR ${ITK_DIR}/../..)
187  # Construct list of ITK libraries for linking = CAMITK_ITK_LIBRARIES
188  foreach(ITK_LIBRARY ${ITK_LIBRARIES})
189  string(SUBSTRING ${ITK_LIBRARY} 0 3 ${ITK_LIBRARY}_PREFIX)
190  # Some libraries have not the expected 'itk' prefix. Add it then
191  if((NOT ${${ITK_LIBRARY}_PREFIX} STREQUAL "itk") AND (NOT ${${ITK_LIBRARY}_PREFIX} STREQUAL "ITK"))
192  set(ITK_LIBRARY itk${ITK_LIBRARY})
193  endif()
194  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)
195  endforeach()
196  elseif(UNIX)
197  set(CAMITK_ITK_LIBRARIES ${ITK_LIBRARIES})
198  elseif(APPLE)
199  message(WARNING "CamiTKExtension.cmake: ITK LIBRARY NOT SET FOR APPLE")
200  endif()
201  else()
202  message(FATAL_ERROR "Wrong version of ITK : ${ITK_VERSION}. Required is at least 4.x to 4.9")
203  endif()
204  else()
205  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  if(${DEFAULT_LIBRARY_NAME_CMAKE}_NEEDS_LIBXML2)
212  # LibXml2 is required
213  find_package(Xml2)
214  if (LIBXML2_FOUND)
215  add_definitions(${LIBXML2_DEFINITIONS})
216  include_directories(${LIBXML2_INCLUDE_DIR})
217  set(LIBXML2_LIBRARY ${LIBXML2_LIBRARIES})
218  else()
219  # most probably win32 or crosscompiling
220  message(WARNING "${LIBRARY_TARGET_NAME}: libxml2 required")
221  endif()
222  endif()
223 
224  # XERCES-C
225  set(XERCESC_LIBRARIES)
226  if(${DEFAULT_LIBRARY_NAME_CMAKE}_NEEDS_XERCESC)
227  # XercesC is required
228  find_package(XercesC REQUIRED)
229  if (XERCESC_FOUND)
230  include_directories(${XERCESC_INCLUDE_DIR})
231  set(XERCESC_LIBRARIES ${XERCESC_LIBRARY})
232  else()
233  # most probably win32 or crosscompiling
234  message(FATAL_ERROR "${DEFAULT_LIBRARY_NAME}: xerces-c required. Please provide Xerces-C path.")
235  endif()
236  endif()
237 
238  # XSD
239  if(${DEFAULT_LIBRARY_NAME_CMAKE}_NEEDS_XSD)
240  # XercesC is required
241  find_package(XercesC REQUIRED)
242  if (XERCESC_FOUND)
243  include_directories(${XERCESC_INCLUDE_DIR})
244  set(XERCESC_LIBRARIES ${XERCESC_LIBRARY})
245  find_package(XSD REQUIRED)
246  include_directories(${XSD_INCLUDE_DIR})
247  else()
248  # 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  endif()
251  endif()
252 
253  # QT
254  if(${DEFAULT_LIBRARY_NAME_CMAKE}_NEEDS_QT)
255  # Instruct CMake to run moc automatically when needed.
256  set(CMAKE_AUTOMOC ON)
257 
258  set(QT_COMPONENTS Core Gui Xml XmlPatterns Widgets Help UiTools OpenGL OpenGLExtensions)
259  find_package(Qt5 COMPONENTS ${QT_COMPONENTS} REQUIRED)
260  if (Qt5_FOUND)
261  # cmake_policy(SET CMP0020 NEW) # policy for Qt core linking to qtmain.lib
262  message(STATUS "${LIBRARY_TARGET_NAME}: found Qt ${Qt5_VERSION}.")
263  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})
264  include_directories(${QT_INCLUDE_DIRS})
265  else()
266  message(SEND_ERROR "${LIBRARY_TARGET_NAME}: Failed to find Qt 5.x. This is needed by ${LIBRARY_TARGET_NAME}.")
267  endif()
268  endif()
269 
270  # EXTERNAL DEPENDENCIES
271  set(LINKER_EXTERNAL_LIBRARIES)
272  if(${DEFAULT_LIBRARY_NAME_CMAKE}_EXTERNAL_LIBRARIES)
273  foreach(EXTERNAL_LIBRARY ${${DEFAULT_LIBRARY_NAME_CMAKE}_EXTERNAL_LIBRARIES})
274  if (MSVC)
275  set(LINKER_EXTERNAL_LIBRARIES ${LINKER_EXTERNAL_LIBRARIES}
276  debug ${EXTERNAL_LIBRARY}${CAMITK_DEBUG_POSTFIX}.lib
277  optimized ${EXTERNAL_LIBRARY}
278  )
279  message(STATUS "LINKER_EXTERNAL_LIBRARIES = ${LINKER_EXTERNAL_LIBRARIES}")
280  else()
281  set(LINKER_EXTERNAL_LIBRARIES ${LINKER_EXTERNAL_LIBRARIES} ${EXTERNAL_LIBRARY})
282  endif()
283  endforeach()
284  endif()
285 
286 
287 
288  #########################################################################
289  # #
290  # LINK DIRECTORIES #
291  # #
292  # * Link directories are used to indicate the compiler where #
293  # to look for folder containing libraries to link with. #
294  # * Additional link directories provided by the user #
295  # #
296  #########################################################################
297  # CAMITK BASIC LIB DIRECTORIES
298  link_directories(${CAMITK_LINK_DIRECTORIES})
299 
300  # ADDITIONAL LINK DIRECTORIES
301  if (NOT "${${DEFAULT_LIBRARY_NAME_CMAKE}_LINK_DIRECTORIES}" STREQUAL "")
302  link_directories(${${DEFAULT_LIBRARY_NAME_CMAKE}_LINK_DIRECTORIES})
303  endif()
304 
305 
306 
307  #########################################################################
308  # #
309  # TARGET COMPILATION DEFINITION #
310  # #
311  # * Additional sources files to consider at compilation (.cpp) #
312  # * CMake project target definition depending on library type #
313  # public / private #
314  # #
315  #########################################################################
316  # CMAKE TARGET DEFINITION DEPENDENDING ON THE LIBRARY TYPE (SHARED or STATIC)
317  if (${DEFAULT_LIBRARY_NAME_CMAKE}_SHARED) # shared library
318  message(STATUS "Building shared library: ${LIBRARY_TARGET_NAME}")
319  add_library(${LIBRARY_TARGET_NAME} SHARED ${${DEFAULT_LIBRARY_NAME_CMAKE}_SOURCES})
320  # prepare the library specific info (SONAME...)
321  set(${LIBRARY_TARGET_NAME}_LIBRARY_PROPERTIES ${${LIBRARY_TARGET_NAME}_LIBRARY_PROPERTIES}
322  VERSION "${CAMITK_VERSION_MAJOR}.${CAMITK_VERSION_MINOR}.${CAMITK_VERSION_PATCH}"
323  SOVERSION "${CAMITK_VERSION_MAJOR}"
324  )
325  #
326  set_target_properties(${LIBRARY_TARGET_NAME} PROPERTIES ${${LIBRARY_TARGET_NAME}_LIBRARY_PROPERTIES} LINK_INTERFACE_LIBRARIES "")
327  elseif (${DEFAULT_LIBRARY_NAME_CMAKE}_STATIC) # static library
328  message(STATUS "Building static library: ${LIBRARY_TARGET_NAME}")
329  add_library(${LIBRARY_TARGET_NAME} STATIC ${${DEFAULT_LIBRARY_NAME_CMAKE}_SOURCES})
330  else()
331  message(FATAL_ERROR "In adding static library ${LIBRARY_TARGET_NAME}.\n Please specify the library type: SHARED or STATIC")
332  endif()
333 
334 
335 
336  #########################################################################
337  # #
338  # QT LINKING LIBRARIES #
339  # #
340  # * Set at linking the Qt5 libraries #
341  # #
342  #########################################################################
343  if(${DEFAULT_LIBRARY_NAME_CMAKE}_NEEDS_QT)
344  qt5_use_modules(${LIBRARY_TARGET_NAME} ${QT_COMPONENTS})
345  endif()
346 
347 
348 
349 
350  #########################################################################
351  # #
352  # CAMITK LIBRARIES DEPENDENCIES #
353  # #
354  # * Add in this section library dependencies to other camitk libraies #
355  # to keep a correct build order (NEEDS_CEP_LIBRARIES). #
356  # #
357  #########################################################################
358 
359  # CEP LIBRARIES DEPENDENCIES
360  set(CEP_LIBRARIES)
361  set(LIBRARIES_DEPENDENCY_LIST "") #use for generating the project.xml file
362  if(${DEFAULT_LIBRARY_NAME_CMAKE}_NEEDS_CEP_LIBRARIES)
363  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  # file dependency
368  if (MSVC)
369  set(CEP_LIBRARIES ${CEP_LIBRARIES} debug ${CEP_LIBRARY_NEEDED}${CAMITK_DEBUG_POSTFIX}.lib
370  optimized ${CEP_LIBRARY_NEEDED}
371  )
372  else()
373  if(PACKAGING_NSIS)
374  set(CEP_LIBRARIES ${CEP_LIBRARIES} ${CEP_LIBRARY_NEEDED})
375  else()
376  set(CEP_LIBRARIES ${CEP_LIBRARIES} ${CEP_LIBRARY_NEEDED})
377  endif()
378  endif()
379  # CMake / CDash dependencies
380  if(PACKAGING_NSIS)
381  add_dependencies(${LIBRARY_TARGET_NAME} library_${CEP_LIBRARY_NEEDED})
382  # add the dependency to the library automoc target
383  set_property(TARGET ${LIBRARY_TARGET_NAME} APPEND PROPERTY AUTOGEN_TARGET_DEPENDS library_${CEP_LIBRARY_NEEDED})
384  else()
385  add_dependencies(${LIBRARY_TARGET_NAME} library-${CEP_LIBRARY_NEEDED})
386  set(LIBRARIES_DEPENDENCY_LIST ${LIBRARIES_DEPENDENCY_LIST} library-${CEP_LIBRARY_NEEDED})
387  # add the dependency to the library automoc target
388  set_property(TARGET ${LIBRARY_TARGET_NAME} APPEND PROPERTY AUTOGEN_TARGET_DEPENDS library-${CEP_LIBRARY_NEEDED})
389  endif()
390  endforeach()
391  endif()
392 
393 
394 
395  #########################################################################
396  # #
397  # LINKING #
398  # #
399  # * Linking is the last stage of compilation #
400  # * Indicate what libraries to use for linking the target #
401  # #
402  #########################################################################
403  # LINKING LIBRARIES
404  target_link_libraries(${LIBRARY_TARGET_NAME} ${CEP_LIBRARIES} ${LINKER_EXTERNAL_LIBRARIES} ${LIBXML2_LIBRARY} ${CAMITK_ITK_LIBRARIES} ${XERCESC_LIBRARIES})
405 
406 
407 
408  #########################################################################
409  # #
410  # OUTPUT #
411  # #
412  # * Define the output directory (location and name) #
413  # * Define the output name of the library #
414  # * Add ${CAMITK_DEBUG_POSTFIX} suffix to Debug MSVC built libraries #
415  # #
416  #########################################################################
417 
418  # OUTPUT DIRECTORY LOCATION and NAME depending on the type of the library (PUBLIC or PRIVATE)
419  # DEBGUG POSTFIX FOR MSVC
420  if (${DEFAULT_LIBRARY_NAME_CMAKE}_PUBLIC) # Public library => build in the bin folder
421  if (MSVC)
422  # With Visual Studio, public libraries are built in build\bin directory, else it's in build\lib
423  set_target_properties(${LIBRARY_TARGET_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CAMITK_BUILD_BIN_DIR}
424  LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CAMITK_BUILD_BIN_DIR}
425  LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CAMITK_BUILD_BIN_DIR}
426  )
427  set_target_properties(${LIBRARY_TARGET_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CAMITK_BUILD_BIN_DIR}
428  RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CAMITK_BUILD_BIN_DIR}
429  RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CAMITK_BUILD_BIN_DIR}
430  )
431  set_target_properties(${LIBRARY_TARGET_NAME} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CAMITK_BUILD_BIN_DIR}
432  ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CAMITK_BUILD_BIN_DIR}
433  ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CAMITK_BUILD_BIN_DIR}
434  )
435  set_target_properties(${LIBRARY_TARGET_NAME} PROPERTIES DEBUG_POSTFIX ${CAMITK_DEBUG_POSTFIX})
436  else()
437  # for xcode generation, the <CONFIG> postfix should also be used, but "a la" UNIX (lib in /lib etc...)
438  # no need to check the generator with if(CMAKE_GENERATOR STREQUAL Xcode), as the <CONFIG> postfix should
439  # not affect the other unix generators
440  set_target_properties(${LIBRARY_TARGET_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CAMITK_BUILD_PUBLIC_LIB_DIR}
441  LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CAMITK_BUILD_PUBLIC_LIB_DIR}
442  LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CAMITK_BUILD_PUBLIC_LIB_DIR}
443  )
444  set_target_properties(${LIBRARY_TARGET_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CAMITK_BUILD_PUBLIC_LIB_DIR}
445  RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CAMITK_BUILD_PUBLIC_LIB_DIR}
446  RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CAMITK_BUILD_PUBLIC_LIB_DIR}
447  )
448  set_target_properties(${LIBRARY_TARGET_NAME} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CAMITK_BUILD_PUBLIC_LIB_DIR}
449  ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CAMITK_BUILD_PUBLIC_LIB_DIR}
450  ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CAMITK_BUILD_PUBLIC_LIB_DIR}
451  )
452  endif()
453  else() # Private library => build in lib folder
454  if (MSVC)
455  set_target_properties(${LIBRARY_TARGET_NAME} PROPERTIES DEBUG_POSTFIX ${CAMITK_DEBUG_POSTFIX})
456  endif()
457  set_target_properties(${LIBRARY_TARGET_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CAMITK_BUILD_PRIVATE_LIB_DIR}
458  LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CAMITK_BUILD_PRIVATE_LIB_DIR}
459  LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CAMITK_BUILD_PRIVATE_LIB_DIR}
460  )
461  set_target_properties(${LIBRARY_TARGET_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CAMITK_BUILD_PRIVATE_LIB_DIR}
462  RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CAMITK_BUILD_PRIVATE_LIB_DIR}
463  RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CAMITK_BUILD_PRIVATE_LIB_DIR}
464  )
465  set_target_properties(${LIBRARY_TARGET_NAME} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CAMITK_BUILD_PRIVATE_LIB_DIR}
466  ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CAMITK_BUILD_PRIVATE_LIB_DIR}
467  ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CAMITK_BUILD_PRIVATE_LIB_DIR}
468  )
469  endif()
470 
471  # OUTUPUT LIBRARY NAME (without the prefix "library-").
472  string(REGEX REPLACE "^library_|^library-" "" LIBRARY_NAME ${LIBRARY_TARGET_NAME})
473  set_target_properties(${LIBRARY_TARGET_NAME}
474  PROPERTIES OUTPUT_NAME ${LIBRARY_NAME}
475  )
476 
477 
478 
479  #########################################################################
480  # #
481  # COMPILATION FLAG #
482  # #
483  # * Flags are options to give to the compiler #
484  # * Add user input flags #
485  # * Add platform specific flags #
486  # #
487  #########################################################################
488 
489  # USER INPUT COMPILER FLAG
490  if(${DEFAULT_LIBRARY_NAME_CMAKE}_DEFINES)
491  foreach (FLAG ${${DEFAULT_LIBRARY_NAME_CMAKE}_DEFINES})
492  add_definitions(-D${FLAG})
493  endforeach()
494  endif()
495 
496  # USER INPUT CUSTOM COMPILER FLAG
497  if(${DEFAULT_LIBRARY_NAME_CMAKE}_CXX_FLAGS)
498  foreach (FLAG ${${DEFAULT_LIBRARY_NAME_CMAKE}_CXX_FLAGS})
499  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAG}")
500  endforeach()
501  endif()
502 
503  # PLATFORM SPECIFIC COMPILER FLAG
504  # 64bits and other platform with relocation needs -fPIC
505  include(TestCXXAcceptsFlag)
506  check_cxx_accepts_flag(-fPIC FPIC_FLAG_ACCEPTED)
507  # no need to add -fPIC on mingw, otherwise it generates a warning: -fPIC ignored for target (all code is position independent) [enabled by default]
508  # msvc is also accepting the flag, but then produce warning D9002 : ignoring unknown option '-fPIC' cl
509  if(FPIC_FLAG_ACCEPTED AND NOT WIN32)
510  set_property(TARGET ${LIBRARY_TARGET_NAME} APPEND PROPERTY COMPILE_FLAGS -fPIC)
511  endif()
512 
513 
514 
515  #########################################################################
516  # #
517  # INSTALLATION #
518  # #
519  # * When installing the project, header files (.h) and test data are #
520  # copied into an installation folder to determine. #
521  # * Indicate in this section, where to install your project and which #
522  # files to copy into that folder (during local/global installation) #
523  # #
524  #########################################################################
525 
526  # FOLDER INSTALLATION
527  # Indicate where to install the library, dependending on its property (public / private)
528  if (${DEFAULT_LIBRARY_NAME_CMAKE}_PUBLIC) # public library
529  if(WIN32)
530  # public library -> install in bin folder
531  install(TARGETS ${LIBRARY_TARGET_NAME}
532  RUNTIME DESTINATION bin
533  LIBRARY DESTINATION lib
534  ARCHIVE DESTINATION lib/${CAMITK_SHORT_VERSION_STRING}
535  COMPONENT ${LIBRARY_NAME_INSTALL}
536  )
537  else()
538  # other public libraries -> install in lib folder
539  install(TARGETS ${LIBRARY_TARGET_NAME}
540  RUNTIME DESTINATION lib
541  LIBRARY DESTINATION lib
542  ARCHIVE DESTINATION lib
543  COMPONENT ${LIBRARY_NAME_INSTALL}
544  )
545  endif()
546  else()
547  # private library -> install in lib/camitk-version folder
548  install(TARGETS ${LIBRARY_TARGET_NAME}
549  RUNTIME DESTINATION lib/${CAMITK_SHORT_VERSION_STRING}
550  LIBRARY DESTINATION lib/${CAMITK_SHORT_VERSION_STRING}
551  ARCHIVE DESTINATION lib/${CAMITK_SHORT_VERSION_STRING}
552  COMPONENT ${LIBRARY_NAME_INSTALL}
553  )
554  endif()
555 
556  # HEADER FILES (.h) INSTALLATION
557  if(${DEFAULT_LIBRARY_NAME_CMAKE}_HEADERS_TO_INSTALL)
558  # If headers information provided for installation => install them
559  export_headers(${${DEFAULT_LIBRARY_NAME_CMAKE}_HEADERS_TO_INSTALL} COMPONENT ${LIBRARY_TARGET_NAME} GROUP libraries)
560  else()
561  # By default, install all headers and keep include directories structure
562  camitk_install_all_headers(COMPONENT ${LIBRARY_TARGET_NAME} GROUP libraries)
563  endif()
564 
565 
566 
567  #########################################################################
568  # #
569  # CDASH SUBPROJECT DESCRIPTION #
570  # #
571  # * Update the XML descriton of the subprojects dependencies #
572  # for CDash. #
573  # #
574  #########################################################################
575  # CDASH XML SUBPROJECTS DESCRIPTION UPDATE
576  if(LIBRARY_TARGET_NAME STREQUAL "library-qtpropertybrowser")
577  # library-qtpropertybrowser is a corelib as library-camitkcore depends on it
578  camitk_sub_project_add(CORELIB ${LIBRARY_TARGET_NAME} DEPENDENCIES ${LIBRARIES_DEPENDENCY_LIST})
579  else()
580  camitk_sub_project_add(CEP_LIBRARY ${LIBRARY_TARGET_NAME} DEPENDENCIES ${LIBRARIES_DEPENDENCY_LIST})
581  endif()
582 
583 
584 
585  #####################################################################################
586  # #
587  # TRANSLATION #
588  # #
589  # * CAMITK_TRANSLATIONS contains the list of language to translate #
590  # the QString to. #
591  # #
592  # * Create the translate.pro file which contains 4 sections: #
593  # - HEADERS: list of .h/.hpp files to look for tr("") QString #
594  # - SOURCES: list of .cpp files to look for tr("") QString #
595  # - FORMS: list of .ui files to look for tr("") QString #
596  # - TRANSLATIONS: list of .ts files which use CAMITK_TRANSLATIONS #
597  # to define each .ts file #
598  # #
599  # * Execute lupdate program to update the .ts files with new QString #
600  # found. #
601  # #
602  # * Execute lrelease program to create .qm files (binary equivalent of #
603  # .ts files #
604  # #
605  # * Create translate.qrc which contains the list of .qm files. #
606  # * Create the flags.qrc file which contains the list of .png flags #
607  # images #
608  # #
609  #####################################################################################
610  if(CAMITK_TRANSLATE)
611  if(${DEFAULT_LIBRARY_NAME_CMAKE}_EXTRA_TRANSLATE_LANGUAGE)
612  camitk_translate(EXTRA_LANGUAGE ${${DEFAULT_LIBRARY_NAME_CMAKE}_EXTRA_TRANSLATE_LANGUAGE})
613  else()
615  endif()
616  endif()
617 
618 
619 
620  #########################################################################
621  # #
622  # PACKAGING CATEGORIZATION #
623  # #
624  # * On Windows, when building a package (win32 installer), the #
625  # install shield wizard proposes you to select which component #
626  # to install. #
627  # * Each component to install has a short description following its #
628  # name to understand its role. #
629  # * This section deals with the categorization and the description #
630  # of the component in this installer. #
631  # #
632  #########################################################################
633 
634  # WINDOWS INSTALLER CATEGORIZATION
635  if(${DEFAULT_LIBRARY_NAME_CMAKE}_CEP_NAME) # This input variable describes the category
636  if (${DEFAULT_LIBRARY_NAME_CMAKE}_CEP_NAME MATCHES "SDK")
637  # The default SDK extensions are categorized as "required" and are not "unselectable" by the user at installation time
638  cpack_add_component(${LIBRARY_TARGET_NAME}
639  DISPLAY_NAME ${LIBRARY_TARGET_NAME}
640  DESCRIPTION ${${DEFAULT_LIBRARY_NAME_CMAKE}_DESCRIPTION}
641  REQUIRED
642  GROUP SDK
643  )
644 
645  else()
646  # Extension is selectable for installation in the wizard of the installer
647  cpack_add_component(${LIBRARY_TARGET_NAME}
648  DISPLAY_NAME ${LIBRARY_TARGET_NAME}
649  DESCRIPTION ${${DEFAULT_LIBRARY_NAME_CMAKE}_DESCRIPTION}
650  GROUP ${${DEFAULT_LIBRARY_NAME_CMAKE}_CEP_NAME}
651  )
652  endif()
653  else()
654  # Extension if not categorized for packaging presentation
655  cpack_add_component(${LIBRARY_TARGET_NAME}
656  DISPLAY_NAME ${LIBRARY_TARGET_NAME}
657  DESCRIPTION ${${DEFAULT_LIBRARY_NAME_CMAKE}_DESCRIPTION}
658  )
659 
660  endif()
661 
662 end(){)
663 
664 # Old macro to configure a tool
665 # Use camitk_library macro instead
666 # TODO CAMITK_DEPRECATED. This macro is marked as deprecated. It is to be removed in CamiTK 4.0
667 camitk_tool(){)
668  message(WARNING "Warning: ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt: camitk_tool macro is deprecated, please usecamitk_library(...) instead (use the same parameters).")
669 # string(REPLACE "NEEDS_TOOL" "NEEDS_CEP_LIBRARIES" OBSOLETE_ARGN ${ARGN})
670 # message(STATUS "**************************************** ${ARGN} ===>>> ${OBSOLETE_ARGN} ")
671  camitk_library(${OBSOLETE_ARGN})
672 end(){)
A pseudo-namespace used to group CMake macros and functions.
Definition: itkImageToVTKImageFilter.h:39
get_directory_name()
macro get_directory_name set the variable VariableName to the name of the last directory of FullPathD...
Definition: GetDirectoryName.h:14
camitk_translate()
macro camitk_translate allows to perform the translation of any project (action, component, application and libraries) in several languages.
Definition: CamiTKTranslate.h:16
Definition: Action.cpp:40
export_headers()
export_headers is a macro that install header files at build and install time
Definition: ExportHeaders.h:40
parse_arguments()
macro parse_arguments is a fork from CMakeMacroParseArguments see http://www.cmake.org/Wiki/CMakeMacroParseArguments for more information
Definition: ParseArguments.h:13
camitk_install_all_headers()
camitk_install_all_headers is a macro that install all header files of a project at build and install...
Definition: CamiTKInstallAllHeaders.h:42
camitk_library()
macro camitk_library simplifies the declaration of a library inside CamiTK and is to be used for all ...
Definition: CamiTKLibrary.h:64
camitk_sub_project_add()
macro camitk_sub_project_add adds a subproject definition from targets and its dependencies (if any) ...
Definition: CamiTKSubProjectAdd.h:17
static void include(QRect &r, const QRect &rect)
Definition: canvas_typed/qtcanvas.cpp:98