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