Computer Assisted Medical Intervention Tool Kit  version 5.2
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  if(${DEFAULT_LIBRARY_NAME_CMAKE}_NEEDS_CEP_LIBRARIES)
385  set(CEP_LIBRARIES "")
386  set(LIBRARIES_DEPENDENCY_LIST "") #use for generating the project.xml file
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  include_directories(${CMAKE_CURRENT_BINARY_DIR}/../../libraries/${CEP_LIBRARY_NEEDED})
392  # file dependency
393  if (MSVC)
394  list(APPEND CEP_LIBRARIES debug ${CEP_LIBRARY_NEEDED}${CAMITK_DEBUG_POSTFIX}.lib
395  optimized ${CEP_LIBRARY_NEEDED}
396  )
397  else()
398  list(APPEND CEP_LIBRARIES ${CEP_LIBRARY_NEEDED})
399  endif()
400  # CMake / CDash dependencies
401  if(PACKAGING_NSIS)
402  if (EXISTS ${CAMITK_BUILD_INCLUDE_DIR}/libraries/${CEP_LIBRARY_NEEDED} AND NOT TARGET library_${CEP_LIBRARY_NEEDED})
403  message(STATUS "Importing target library_${CEP_LIBRARY_NEEDED}")
404  add_library(library_${CEP_LIBRARY_NEEDED} INTERFACE IMPORTED)
405  endif()
406  # now add the dependency
407  add_dependencies(${LIBRARY_TARGET_NAME} library_${CEP_LIBRARY_NEEDED})
408  else()
409  if (NOT TARGET library-${CEP_LIBRARY_NEEDED})
410  message(STATUS "Importing target library-${CEP_LIBRARY_NEEDED}")
411  add_library(library-${CEP_LIBRARY_NEEDED} INTERFACE IMPORTED)
412  endif()
413  add_dependencies(${LIBRARY_TARGET_NAME} library-${CEP_LIBRARY_NEEDED})
414  list(APPEND LIBRARIES_DEPENDENCY_LIST library-${CEP_LIBRARY_NEEDED})
415  endif()
416  endforeach()
417  endif()
418 
419 
420 
421  #########################################################################
422  # #
423  # LINKING #
424  # #
425  # * Linking is the last stage of compilation #
426  # * Indicate what libraries to use for linking the target #
427  # #
428  #########################################################################
429  # LINKING LIBRARIES
430  target_link_libraries(${LIBRARY_TARGET_NAME} ${CAMITK_LIBRARIES_DEPENDENCIES} ${CEP_LIBRARIES} ${LINKER_EXTERNAL_LIBRARIES} ${LIBXML2_LIBRARY} ${CAMITK_ITK_LIBRARIES} ${XERCESC_LIBRARIES})
431 
432 
433 
434  #########################################################################
435  # #
436  # OUTPUT #
437  # #
438  # * Define the output directory (location and name) #
439  # * Define the output name of the library #
440  # * Add ${CAMITK_DEBUG_POSTFIX} suffix to Debug MSVC built libraries #
441  # #
442  #########################################################################
443 
444  # OUTPUT DIRECTORY LOCATION and NAME depending on the type of the library (PUBLIC or PRIVATE)
445  # DEBGUG POSTFIX FOR MSVC
446  if (${DEFAULT_LIBRARY_NAME_CMAKE}_PUBLIC) # Public library => build in the bin folder
447  if (MSVC)
448  # With Visual Studio, public libraries are built in build\bin directory, else it's in build\lib
449  set_target_properties(${LIBRARY_TARGET_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CAMITK_BUILD_BIN_DIR}
450  LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CAMITK_BUILD_BIN_DIR}
451  LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CAMITK_BUILD_BIN_DIR}
452  )
453  set_target_properties(${LIBRARY_TARGET_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CAMITK_BUILD_BIN_DIR}
454  RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CAMITK_BUILD_BIN_DIR}
455  RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CAMITK_BUILD_BIN_DIR}
456  )
457  set_target_properties(${LIBRARY_TARGET_NAME} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CAMITK_BUILD_BIN_DIR}
458  ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CAMITK_BUILD_BIN_DIR}
459  ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CAMITK_BUILD_BIN_DIR}
460  )
461  set_target_properties(${LIBRARY_TARGET_NAME} PROPERTIES DEBUG_POSTFIX ${CAMITK_DEBUG_POSTFIX})
462  else()
463  # for xcode generation, the <CONFIG> postfix should also be used, but "a la" UNIX (lib in /lib etc...)
464  # no need to check the generator with if(CMAKE_GENERATOR STREQUAL Xcode), as the <CONFIG> postfix should
465  # not affect the other unix generators
466  set_target_properties(${LIBRARY_TARGET_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CAMITK_BUILD_PUBLIC_LIB_DIR}
467  LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CAMITK_BUILD_PUBLIC_LIB_DIR}
468  LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CAMITK_BUILD_PUBLIC_LIB_DIR}
469  )
470  set_target_properties(${LIBRARY_TARGET_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CAMITK_BUILD_PUBLIC_LIB_DIR}
471  RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CAMITK_BUILD_PUBLIC_LIB_DIR}
472  RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CAMITK_BUILD_PUBLIC_LIB_DIR}
473  )
474  set_target_properties(${LIBRARY_TARGET_NAME} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CAMITK_BUILD_PUBLIC_LIB_DIR}
475  ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CAMITK_BUILD_PUBLIC_LIB_DIR}
476  ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CAMITK_BUILD_PUBLIC_LIB_DIR}
477  )
478  endif()
479  else() # Private library => build in lib folder
480  if (MSVC)
481  set_target_properties(${LIBRARY_TARGET_NAME} PROPERTIES DEBUG_POSTFIX ${CAMITK_DEBUG_POSTFIX})
482  endif()
483  set_target_properties(${LIBRARY_TARGET_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CAMITK_BUILD_PRIVATE_LIB_DIR}
484  LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CAMITK_BUILD_PRIVATE_LIB_DIR}
485  LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CAMITK_BUILD_PRIVATE_LIB_DIR}
486  )
487  set_target_properties(${LIBRARY_TARGET_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CAMITK_BUILD_PRIVATE_LIB_DIR}
488  RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CAMITK_BUILD_PRIVATE_LIB_DIR}
489  RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CAMITK_BUILD_PRIVATE_LIB_DIR}
490  )
491  set_target_properties(${LIBRARY_TARGET_NAME} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CAMITK_BUILD_PRIVATE_LIB_DIR}
492  ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CAMITK_BUILD_PRIVATE_LIB_DIR}
493  ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CAMITK_BUILD_PRIVATE_LIB_DIR}
494  )
495  endif()
496 
497  # OUTPUT LIBRARY NAME (without the prefix "library-").
498  string(REGEX REPLACE "^library_|^library-" "" LIBRARY_NAME "${LIBRARY_TARGET_NAME}")
499  set_target_properties(${LIBRARY_TARGET_NAME}
500  PROPERTIES OUTPUT_NAME ${LIBRARY_NAME}
501  )
502 
503 
504 
505  #########################################################################
506  # #
507  # COMPILATION FLAG #
508  # #
509  # * Flags are options to give to the compiler #
510  # * Add user input flags #
511  # * Add platform specific flags #
512  # #
513  #########################################################################
514 
515  # USER INPUT COMPILER FLAG
516  if(${DEFAULT_LIBRARY_NAME_CMAKE}_DEFINES)
517  foreach (FLAG ${${DEFAULT_LIBRARY_NAME_CMAKE}_DEFINES})
518  add_definitions(-D${FLAG})
519  endforeach()
520  endif()
521 
522  # USER INPUT CUSTOM COMPILER FLAG
523  if(${DEFAULT_LIBRARY_NAME_CMAKE}_CXX_FLAGS)
524  foreach (FLAG ${${DEFAULT_LIBRARY_NAME_CMAKE}_CXX_FLAGS})
525  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAG}")
526  endforeach()
527  endif()
528 
529  # PLATFORM SPECIFIC COMPILER FLAG
530  # 64bits and other platform with relocation needs -fPIC
531  include(TestCXXAcceptsFlag)
532  check_cxx_accepts_flag(-fPIC FPIC_FLAG_ACCEPTED)
533  # no need to add -fPIC on mingw, otherwise it generates a warning: -fPIC ignored for target (all code is position independent) [enabled by default]
534  # msvc is also accepting the flag, but then produce warning D9002 : ignoring unknown option '-fPIC' cl
535  if(FPIC_FLAG_ACCEPTED AND NOT WIN32)
536  set_property(TARGET ${LIBRARY_TARGET_NAME} APPEND PROPERTY COMPILE_FLAGS -fPIC)
537  endif()
538 
539 
540 
541  #########################################################################
542  # #
543  # INSTALLATION #
544  # #
545  # * When installing the project, header files (.h) and test data are #
546  # copied into an installation folder to determine. #
547  # * Indicate in this section, where to install your project and which #
548  # files to copy into that folder (during local/global installation) #
549  # #
550  #########################################################################
551 
552  # FOLDER INSTALLATION
553  # Indicate where to install the library, dependending on its property (public / private)
554  message(STATUS "Installing library ${LIBRARY_TARGET_NAME} in ${CMAKE_INSTALL_LIBDIR}")
555  if (${DEFAULT_LIBRARY_NAME_CMAKE}_PUBLIC) # public library
556  if(WIN32)
557  # public library -> install in bin folder
558  install(TARGETS ${LIBRARY_TARGET_NAME}
559  RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
560  LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
561  ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/${CAMITK_SHORT_VERSION_STRING}
562  COMPONENT ${LIBRARY_NAME_INSTALL}
563  )
564  else()
565  # other public libraries -> install in lib folder
566  install(TARGETS ${LIBRARY_TARGET_NAME}
567  RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}
568  LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
569  ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
570  COMPONENT ${LIBRARY_NAME_INSTALL}
571  )
572  endif()
573  else()
574  # private library -> install in lib/camitk-version folder
575  install(TARGETS ${LIBRARY_TARGET_NAME}
576  RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}/${CAMITK_SHORT_VERSION_STRING}
577  LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/${CAMITK_SHORT_VERSION_STRING}
578  ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/${CAMITK_SHORT_VERSION_STRING}
579  COMPONENT ${LIBRARY_NAME_INSTALL}
580  )
581  endif()
582 
583  # HEADER FILES (.h) INSTALLATION
584  if(${DEFAULT_LIBRARY_NAME_CMAKE}_HEADERS_TO_INSTALL)
585  # If headers information provided for installation => install them
586  export_headers(${${DEFAULT_LIBRARY_NAME_CMAKE}_HEADERS_TO_INSTALL} COMPONENT ${LIBRARY_TARGET_NAME} GROUP libraries)
587  else()
588  # By default, install all headers and keep include directories structure
589  camitk_install_all_headers(COMPONENT ${LIBRARY_TARGET_NAME} GROUP libraries)
590  endif()
591 
592  #########################################################################
593  # #
594  # CDASH SUBPROJECT DESCRIPTION #
595  # #
596  # * Update the XML descriton of the subprojects dependencies #
597  # for CDash. #
598  # #
599  #########################################################################
600  # CDASH XML SUBPROJECTS DESCRIPTION UPDATE
601  if(LIBRARY_TARGET_NAME STREQUAL "library-qtpropertybrowser")
602  # library-qtpropertybrowser is a corelib as library-camitkcore depends on it
603  camitk_register_subproject(CORELIB ${LIBRARY_TARGET_NAME} DEPENDENCIES ${LIBRARIES_DEPENDENCY_LIST})
604  else()
605  camitk_register_subproject(CEP_LIBRARY ${LIBRARY_TARGET_NAME} DEPENDENCIES ${LIBRARIES_DEPENDENCY_LIST})
606  endif()
607 
608 
609 
610  #####################################################################################
611  # #
612  # TRANSLATION #
613  # #
614  # * CAMITK_TRANSLATIONS contains the list of language to translate #
615  # the QString to. #
616  # #
617  # * Create the translate.pro file which contains 4 sections: #
618  # - HEADERS: list of .h/.hpp files to look for tr("") QString #
619  # - SOURCES: list of .cpp files to look for tr("") QString #
620  # - FORMS: list of .ui files to look for tr("") QString #
621  # - TRANSLATIONS: list of .ts files which use CAMITK_TRANSLATIONS #
622  # to define each .ts file #
623  # #
624  # * Execute lupdate program to update the .ts files with new QString #
625  # found. #
626  # #
627  # * Execute lrelease program to create .qm files (binary equivalent of #
628  # .ts files #
629  # #
630  # * Create translate.qrc which contains the list of .qm files. #
631  # * Create the flags.qrc file which contains the list of .png flags #
632  # images #
633  # #
634  #####################################################################################
635  if(CAMITK_TRANSLATE)
636  if(${DEFAULT_LIBRARY_NAME_CMAKE}_EXTRA_TRANSLATE_LANGUAGE)
637  camitk_translate(EXTRA_LANGUAGE ${${DEFAULT_LIBRARY_NAME_CMAKE}_EXTRA_TRANSLATE_LANGUAGE})
638  else()
639  camitk_translate()
640  endif()
641  endif()
642 
643 
644 
645  #########################################################################
646  # #
647  # PACKAGING CATEGORIZATION #
648  # #
649  # * On Windows, when building a package (win32 installer), the #
650  # install shield wizard proposes you to select which component #
651  # to install. #
652  # * Each component to install has a short description following its #
653  # name to understand its role. #
654  # * This section deals with the categorization and the description #
655  # of the component in this installer. #
656  # #
657  #########################################################################
658 
659  # WINDOWS INSTALLER CATEGORIZATION
660  if(${DEFAULT_LIBRARY_NAME_CMAKE}_CEP_NAME) # This input variable describes the category
661  if (${DEFAULT_LIBRARY_NAME_CMAKE}_CEP_NAME MATCHES "SDK")
662  # The default SDK extensions are categorized as "required" and are not "unselectable" by the user at installation time
663  cpack_add_component(${LIBRARY_TARGET_NAME}
664  DISPLAY_NAME ${LIBRARY_TARGET_NAME}
665  DESCRIPTION ${${DEFAULT_LIBRARY_NAME_CMAKE}_DESCRIPTION}
666  REQUIRED
667  GROUP SDK
668  )
669 
670  else()
671  # Extension is selectable for installation in the wizard of the installer
672  cpack_add_component(${LIBRARY_TARGET_NAME}
673  DISPLAY_NAME ${LIBRARY_TARGET_NAME}
674  DESCRIPTION ${${DEFAULT_LIBRARY_NAME_CMAKE}_DESCRIPTION}
675  GROUP ${${DEFAULT_LIBRARY_NAME_CMAKE}_CEP_NAME}
676  )
677  endif()
678  else()
679  # Extension if not categorized for packaging presentation
680  cpack_add_component(${LIBRARY_TARGET_NAME}
681  DISPLAY_NAME ${LIBRARY_TARGET_NAME}
682  DESCRIPTION ${${DEFAULT_LIBRARY_NAME_CMAKE}_DESCRIPTION}
683  )
684 
685  endif()
686 
687 end(){)
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
cmake modules macros camitk test endif() add_custom_target(camitk-ce-iwyu COMMAND $
Definition: CamiTKIncludeWhatYouUse.h:37
#define a
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
static void include(QRect &r, const QRect &rect)
Definition: canvas_typed/qtcanvas.cpp:98
camitk_library()
macro camitk_library simplifies the declaration of a library inside CamiTK and is to be used for all ...
Definition: CamiTKLibrary.h:75
get_directory_name()
macro get_directory_name set the variable VariableName to the name of the last directory of FullPathD...
Definition: GetDirectoryName.h:14
Definition: itkImageToVTKImageFilter.h:39