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