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