1 # possible values : ACTION_EXTENSION or COMPONENT_EXTENSION. 93 # Instruct
CMake to run moc automatically when needed.
98 ######################################################################### 100 # ARGUMENTS PARSING # 102 # * Use a macro to create the CMAKE variables according to the # 103 # provided options as input. # 105 ######################################################################### 109 set(options ACTION_EXTENSION COMPONENT_EXTENSION DISABLED NEEDS_XERCESC NEEDS_ITK NEEDS_LIBXML2 NEEDS_XSD NEEDS_OPENCV NEEDS_IGSTK INSTALL_ALL_HEADERS NEEDS_GDCM ENABLE_AUTO_TEST ENABLE_INTEGRATION_TEST)
110 set(oneValueArgs TARGET_NAME CEP_NAME DESCRIPTION AUTO_TEST_LEVEL)
111 set(multiValueArgs NEEDS_TOOL NEEDS_CEP_LIBRARIES NEEDS_COMPONENT_EXTENSION NEEDS_ACTION_EXTENSION INCLUDE_DIRECTORIES EXTERNAL_LIBRARIES HEADERS_TO_INSTALL DEFINES CXX_FLAGS EXTERNAL_SOURCES EXTRA_TRANSLATE_LANGUAGE TEST_FILES)
112 cmake_parse_arguments(${EXTENSION_NAME_CMAKE}
"${options}" "${oneValueArgs}" 113 "${multiValueArgs}" ${ARGN} )
115 #########################################################################
117 # CREATE CMAKE VARIABLES #
119 # * Create required and useful
CMake variables
for the macro #
121 #########################################################################
123 # TYPE EXTENSION : ACTION or COMPONENT
124 if (${EXTENSION_NAME_CMAKE}_ACTION_EXTENSION)
125 set(TYPE_EXTENSION
"action")
126 string(TOUPPER ${TYPE_EXTENSION} TYPE_EXTENSION_CMAKE)
127 elseif(${EXTENSION_NAME_CMAKE}_COMPONENT_EXTENSION)
128 set(TYPE_EXTENSION
"component")
129 string(TOUPPER ${TYPE_EXTENSION} TYPE_EXTENSION_CMAKE)
132 # CMAKE CACHE VARIABLE 133 # if it is the first cmake run, create the extension variable with a correct initial value 134 if(NOT ${TYPE_EXTENSION_CMAKE}_${EXTENSION_NAME_CMAKE}_INTERNAL)
135 # add option to enable/disable
this extension and
set it to
true by
default 136 # Building the extension can be disabled by giving the argument DISABLED to the macro
137 # or by passing the flag -D${TYPE_EXTENSION_CMAKE}_${EXTENSION_NAME_CMAKE}_DISABLED:BOOL=TRUE
138 if(${EXTENSION_NAME_CMAKE}_DISABLED)
139 set(${TYPE_EXTENSION_CMAKE}_${EXTENSION_NAME_CMAKE}_ENABLED FALSE)
141 set(${TYPE_EXTENSION_CMAKE}_${EXTENSION_NAME_CMAKE}_ENABLED TRUE)
143 set(${TYPE_EXTENSION_CMAKE}_${EXTENSION_NAME_CMAKE} ${${TYPE_EXTENSION_CMAKE}_${EXTENSION_NAME_CMAKE}_ENABLED} CACHE BOOL
"Build extension ${EXTENSION_NAME}")
144 set(${TYPE_EXTENSION_CMAKE}_${EXTENSION_NAME_CMAKE}_INTERNAL TRUE CACHE INTERNAL
"Is variable ${TYPE_EXTENSION_CMAKE}_${EXTENSION_NAME} already created?")
147 # if this extension is enabled, do everything needed 148 # otherwise... do nothing 149 if (${TYPE_EXTENSION_CMAKE}_${EXTENSION_NAME_CMAKE})
152 # The target name is composed of the following: [action / component]-name
153 # * action / component is the type of extension as prefix
154 # * name is deduced from the input folder containing the calling CMakeLists.txt file of the extension.
155 if (${EXTENSION_NAME_CMAKE}_TARGET_NAME)
156 set(${TYPE_EXTENSION_CMAKE}_OUTPUT_NAME ${${EXTENSION_NAME_CMAKE}_TARGET_NAME})
158 set(${TYPE_EXTENSION_CMAKE}_OUTPUT_NAME ${EXTENSION_NAME})
160 # replace "-" by "_" if the extension is being packaged with NSIS, the program to create a Windows installer. 162 # NSIS requires that cpack component names do not feature space or "-" characters 163 set(${TYPE_EXTENSION_CMAKE}_TARGET_NAME ${TYPE_EXTENSION}_${${TYPE_EXTENSION_CMAKE}_OUTPUT_NAME})
165 set(${TYPE_EXTENSION_CMAKE}_TARGET_NAME ${TYPE_EXTENSION}-${${TYPE_EXTENSION_CMAKE}_OUTPUT_NAME})
168 message(STATUS
"Building extension ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}")
170 # EXTENSION_PLUGIN_FILE 171 # determine the extension full file name depending on the plateform 172 set(EXTENSION_PLUGIN_FILE
"${CAMITK_BUILD_PRIVATE_LIB_DIR}/${TYPE_EXTENSION}s")
174 set(EXTENSION_PLUGIN_FILE ${EXTENSION_PLUGIN_FILE}/${${TYPE_EXTENSION_CMAKE}_OUTPUT_NAME}${CAMITK_DEBUG_POSTFIX}.dll)
176 set(EXTENSION_PLUGIN_FILE ${EXTENSION_PLUGIN_FILE}/lib${${TYPE_EXTENSION_CMAKE}_OUTPUT_NAME}.dylib)
179 set(EXTENSION_PLUGIN_FILE ${EXTENSION_PLUGIN_FILE}/lib${${TYPE_EXTENSION_CMAKE}_OUTPUT_NAME}.so)
182 ######################################################################### 184 # INCLUDE DIRECTORIES # 186 # * Include basic directories where to look header files # 187 # * Include also additional user provided directories # 188 # * These directories are used for compilation step # 190 ######################################################################### 193 include_directories(${CAMITK_INCLUDE_DIRECTORIES})
194 include_directories(${CMAKE_CURRENT_BINARY_DIR})
195 include_directories(${CMAKE_CURRENT_SOURCE_DIR})
197 # USER INPUT DIRECTORIES
198 include_directories(${${EXTENSION_NAME_CMAKE}_INCLUDE_DIRECTORIES})
202 #########################################################################
204 # GATHER RESSOURCES #
206 # * Get all the headers (.h) and source files (.cpp) of the project #
207 # * Create the needed Qt files (using moc and uic) # 208 # * On Windows, Visual Studio, group .moc and .ui files # 209 # in subdirectories # 211 ######################################################################### 213 # get all headers, sources and do what is needed for Qt 214 # one need to do this just before the add_library so that all defines, include directories and link directories 215 # are set properly (gather_headers_and_sources include the call to Qt moc and uic) 220 #########################################################################
222 # ADDITIONAL KNOWN EXTERNAL LIBRARY DEPENDENCIES #
224 # * Look
for specific library needed #
225 # * Specific libraries are specified as option with the #
226 # NEEDS_LIBRARY syntax (see macro syntax
for more options)
# 227 # * Backward compatibility : Warn user if using old NEEDS_TOOL syntax # 229 ######################################################################### 232 set(ITK_LIBRARIES
"")
233 if(${EXTENSION_NAME_CMAKE}_NEEDS_ITK)
234 find_package(ITK REQUIRED PATHS /usr/lib/InsightToolkit)
237 set(ITK_VERSION ${ITK_VERSION_MAJOR}.${ITK_VERSION_MINOR}.${ITK_VERSION_PATCH}) #ITK_VERSION is not always
set 238 set(CAMITK_ITK_VERSION ${ITK_VERSION_MAJOR}.${ITK_VERSION_MINOR})
239 message(STATUS
"${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}: Found ITK version ${ITK_VERSION}")
241 if ((${ITK_VERSION} VERSION_GREATER
"4") AND (${ITK_VERSION} VERSION_LESS
"5")) # ITK 4.9 on Windows, maybe
a lesser version
for Linux.
243 set(ITK_DIR ${ITK_DIR}/../..)
244 # Construct list of ITK libraries
for linking = CAMITK_ITK_LIBRARIES
245 foreach(ITK_LIBRARY ${ITK_LIBRARIES})
246 string(SUBSTRING ${ITK_LIBRARY} 0 3 ${ITK_LIBRARY}_PREFIX)
247 # Some libraries have not the expected
'itk' prefix. Add it then
248 if((NOT ${${ITK_LIBRARY}_PREFIX} STREQUAL
"itk") AND (NOT ${${ITK_LIBRARY}_PREFIX} STREQUAL
"ITK"))
249 set(ITK_LIBRARY
itk${ITK_LIBRARY})
251 list(APPEND CAMITK_ITK_LIBRARIES debug ${ITK_DIR}/${ITK_LIBRARY}-${CAMITK_ITK_VERSION}${CAMITK_DEBUG_POSTFIX}.lib optimized ${ITK_DIR}/${ITK_LIBRARY}-${CAMITK_ITK_VERSION}.lib)
254 set(CAMITK_ITK_LIBRARIES ${ITK_LIBRARIES})
256 message(WARNING
"CamiTKExtension.cmake: ITK LIBRARY NOT SET FOR APPLE")
259 message(FATAL_ERROR "Wrong version of ITK : ${ITK_VERSION}. Required is at least 4.x to 4.9
") 262 message(FATAL_ERROR "ITK not found but required
for ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
") 267 set(LIBXML2_LIBRARY "") 268 if(${EXTENSION_NAME_CMAKE}_NEEDS_LIBXML2) 269 # LibXml2 is required 272 add_definitions(${LIBXML2_DEFINITIONS}) 273 include_directories(${LIBXML2_INCLUDE_DIR}) 274 set(LIBXML2_LIBRARY ${LIBXML2_LIBRARIES}) 276 # most probably win32 or crosscompiling 277 message(STATUS "${EXTENSION_NAME}: libxml2 required
") 282 set(OpenCV_LIBRARIES "") 283 if(${EXTENSION_NAME_CMAKE}_NEEDS_OPENCV) 285 find_package( OpenCV REQUIRED ) 287 set(OpenCV_LIBRARIES "") 291 set(IGSTK_LIBRARIES "") 292 if(${EXTENSION_NAME_CMAKE}_NEEDS_IGSTK) 293 find_package(IGSTK REQUIRED) 294 include(${IGSTK_USE_FILE}) 296 set(IGSTK_LIBRARIES "") 300 set(XERCESC_LIBRARIES) 301 if(${EXTENSION_NAME_CMAKE}_NEEDS_XERCESC) 302 # XercesC is required 303 if (NOT XERCESC_LIBRARY) 304 find_package(XercesC REQUIRED) 307 include_directories(${XERCESC_INCLUDE_DIR}) 308 set(XERCESC_LIBRARIES ${XERCESC_LIBRARY}) 310 # most probably win32 or crosscompiling 311 message(FATAL_ERROR "${EXTENSION_NAME}: xerces-c required. Please provide Xerces-C path.
") 316 if(${EXTENSION_NAME_CMAKE}_NEEDS_XSD) 317 # XercesC is required 318 if (NOT XERCESC_LIBRARY) 319 find_package(XercesC REQUIRED) 321 find_package(XercesC REQUIRED) 323 include_directories(${XERCESC_INCLUDE_DIR}) 324 set(XERCESC_LIBRARIES ${XERCESC_LIBRARY}) 325 find_package(XSD REQUIRED) 326 include_directories(${XSD_INCLUDE_DIR}) 328 # most probably win32 or crosscompiling 329 message(FATAL_ERROR "${EXTENSION_NAME}: xerces-c required because of XSD cxx, please
set XERCESC_INCLUDE_DIR
") 335 if(${EXTENSION_NAME_CMAKE}_NEEDS_GDCM) 337 # Look for GDCM library only if not found (for instance, ITK has already search for it) 338 # Calling find_package(GDCM ..) more than once creates CMake errors. 339 find_package(GDCM 2.0 REQUIRED) 342 include(${GDCM_USE_FILE}) 345 debug ${GDCM_DIR}/../gdcmcharls${CAMITK_DEBUG_POSTFIX}.lib 346 debug ${GDCM_DIR}/../gdcmCommon${CAMITK_DEBUG_POSTFIX}.lib 347 debug ${GDCM_DIR}/../gdcmDICT${CAMITK_DEBUG_POSTFIX}.lib 348 debug ${GDCM_DIR}/../gdcmDSED${CAMITK_DEBUG_POSTFIX}.lib 349 debug ${GDCM_DIR}/../gdcmexpat${CAMITK_DEBUG_POSTFIX}.lib 350 debug ${GDCM_DIR}/../gdcmgetopt${CAMITK_DEBUG_POSTFIX}.lib 351 debug ${GDCM_DIR}/../gdcmIOD${CAMITK_DEBUG_POSTFIX}.lib 352 debug ${GDCM_DIR}/../gdcmjpeg8${CAMITK_DEBUG_POSTFIX}.lib 353 debug ${GDCM_DIR}/../gdcmjpeg12${CAMITK_DEBUG_POSTFIX}.lib 354 debug ${GDCM_DIR}/../gdcmjpeg16${CAMITK_DEBUG_POSTFIX}.lib 355 debug ${GDCM_DIR}/../gdcmMEXD${CAMITK_DEBUG_POSTFIX}.lib 356 debug ${GDCM_DIR}/../gdcmMSFF${CAMITK_DEBUG_POSTFIX}.lib 357 debug ${GDCM_DIR}/../gdcmopenjpeg${CAMITK_DEBUG_POSTFIX}.lib 358 debug ${GDCM_DIR}/../gdcmzlib${CAMITK_DEBUG_POSTFIX}.lib 359 debug ${GDCM_DIR}/../socketxx${CAMITK_DEBUG_POSTFIX}.lib 360 debug ${GDCM_DIR}/../vtkgdcm${CAMITK_DEBUG_POSTFIX}.lib 361 debug ${GDCM_DIR}/../gdcmDSED${CAMITK_DEBUG_POSTFIX}.lib 362 optimized gdcmcharls gdcmCommon gdcmDICT gdcmDSED gdcmexpat 363 optimized gdcmgetopt gdcmIOD gdcmjpeg8 gdcmjpeg12 gdcmjpeg16 364 optimized gdcmMEXD gdcmMSFF gdcmopenjpeg gdcmzlib socketxx vtkgdcm 368 set(GDCM_LIBRARIES gdcmCommon gdcmDICT gdcmDSED gdcmMEXD gdcmMSFF vtkgdcm) 371 message(ERROR "${EXTENSION_NAME}: GDCM 2.x library required. Please install GDCM.
") 376 set(EXTERNAL_LIBRARIES) 377 if(${EXTENSION_NAME_CMAKE}_EXTERNAL_LIBRARIES) 378 foreach(EXTERNAL_LIBRARY ${${EXTENSION_NAME_CMAKE}_EXTERNAL_LIBRARIES}) 380 list(APPEND EXTERNAL_LIBRARIES ${EXTERNAL_LIBRARIES} 381 debug ${EXTERNAL_LIBRARY}${CAMITK_DEBUG_POSTFIX}.lib 382 optimized ${EXTERNAL_LIBRARY}.lib 385 list(APPEND EXTERNAL_LIBRARIES ${EXTERNAL_LIBRARY}) 392 ######################################################################### 396 # * Link directories are used to indicate the compiler where # 397 # to look for folder containing libraries to link with. # 398 # * Must be done BEFORE creating the CMake target with add_library # 400 ######################################################################### 402 # CAMITK BASIC LIB DIRECTORIES 403 link_directories(${CAMITK_LINK_DIRECTORIES}) 407 ######################################################################### 409 # TARGET COMPILATION DEFINITION # 411 # * Additional sources files to consider at compilation (.cpp) # 412 # * CMake project target definition # 414 ######################################################################### 416 set(${EXTENSION_NAME_CMAKE}_SOURCES ${${EXTENSION_NAME_CMAKE}_SOURCES} ${${EXTENSION_NAME_CMAKE}_EXTERNAL_SOURCES}) 418 # CMAKE TARGET DEFINITION 419 add_library(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} SHARED ${${EXTENSION_NAME_CMAKE}_SOURCES}) 423 ######################################################################### 425 # QT LINKING LIBRARIES # 427 # * Set at linking the Qt5 libraries # 429 ######################################################################### 430 qt5_use_modules(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} ${CAMITK_QT_COMPONENTS}) 434 ######################################################################### 436 # CAMITK ACTION / COMPONENT / LIBRARIES DEPENDENCIES # 438 # * Look for action / component / libraries dependencies # 439 # * Specific actions / components / libraries are specified as option # 440 # with the NEEDS_ACTION/COMPONENT_EXTENSION/CEP_LIBRARIES syntax # 441 # * Add dependencies to library-camitkcore and the testing # 442 # action/component if test are runned on it # 444 ######################################################################### 446 # 1st CAMITKCORE LIBRARY DEPENDENCY 447 # add_dependencies(..) is only needed to enable parallel build during SDK build 448 # but generates an error for external CEP, where this target does not 450 # Using target_link_libraries(..) is enough to link the extension to the CamiTK core library 451 if(CAMITK_COMMUNITY_EDITION_BUILD) 452 add_dependencies(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} ${CAMITK_CORE_TARGET_LIB_NAME}) 453 # add the dependency to the core automoc target only if inside a SDK build 454 set_property(TARGET ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} APPEND PROPERTY AUTOGEN_TARGET_DEPENDS ${CAMITK_CORE_TARGET_LIB_NAME}) 458 # 2nd COMPONENTS DEPENDENCIES 459 if(${EXTENSION_NAME_CMAKE}_NEEDS_COMPONENT_EXTENSION) 460 set(COMPONENTS_DEPENDENCY_LIST "") #use for generating the project.xml file 461 foreach(COMPONENT_NEEDED ${${EXTENSION_NAME_CMAKE}_NEEDS_COMPONENT_EXTENSION}) 462 # include directories from build, camitk (local or global install). 463 include_directories(${CAMITK_BUILD_INCLUDE_DIR}/components/${COMPONENT_NEEDED}) 464 include_directories(${CAMITK_INCLUDE_DIR}/components/${COMPONENT_NEEDED}) 467 list(APPEND COMPONENT_EXTENSION_LIBRARIES debug ${CAMITK_BUILD_PRIVATE_LIB_DIR}/components/${COMPONENT_NEEDED}${CAMITK_DEBUG_POSTFIX}.lib 468 optimized ${COMPONENT_NEEDED} 471 list(APPEND COMPONENT_EXTENSION_LIBRARIES ${COMPONENT_NEEDED}) 473 # CMake / CDash dependencies 475 add_dependencies(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} component_${COMPONENT_NEEDED}) 476 # add the dependency to the component automoc target only if compiling SDK 477 if(CAMITK_COMMUNITY_EDITION_BUILD) 478 set_property(TARGET ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} APPEND PROPERTY AUTOGEN_TARGET_DEPENDS component_${COMPONENT_NEEDED}) 481 add_dependencies(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} component-${COMPONENT_NEEDED}) 482 list(APPEND COMPONENTS_DEPENDENCY_LIST component-${COMPONENT_NEEDED}) 483 # add the dependency to the component automoc target only if compiling SDK 484 if(CAMITK_COMMUNITY_EDITION_BUILD) 485 set_property(TARGET ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} APPEND PROPERTY AUTOGEN_TARGET_DEPENDS component-${COMPONENT_NEEDED}) 491 # 3rd ACTIONS DEPENDENCIES 492 if(${EXTENSION_NAME_CMAKE}_NEEDS_ACTION_EXTENSION) 493 set(ACTIONS_DEPENDENCY_LIST "") #use for generating the project.xml file 494 foreach(ACTION_NEEDED ${${EXTENSION_NAME_CMAKE}_NEEDS_ACTION_EXTENSION}) 495 # include directories from build, camitk (local or global install). 496 include_directories(${CAMITK_BUILD_INCLUDE_DIR}/actions/${ACTION_NEEDED}) 497 include_directories(${CAMITK_INCLUDE_DIR}/actions/${ACTION_NEEDED}) 500 list(APPEND ACTION_EXTENSION_LIBRARIES debug ${CAMITK_BUILD_PRIVATE_LIB_DIR}/actions/${ACTION_NEEDED}${CAMITK_DEBUG_POSTFIX}.lib 501 optimized ${ACTION_NEEDED} 504 list(APPEND ACTION_EXTENSION_LIBRARIES ${ACTION_NEEDED}) 506 # CMake / CDash dependencies 508 add_dependencies(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} action_${ACTION_NEEDED}) 509 # add the dependency to the component automoc target only if compiling SDK 510 if(CAMITK_COMMUNITY_EDITION_BUILD) 511 set_property(TARGET ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} APPEND PROPERTY AUTOGEN_TARGET_DEPENDS action_${ACTION_NEEDED}) 514 add_dependencies(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} action-${ACTION_NEEDED}) 515 list(APPEND ACTIONS_DEPENDENCY_LIST action-${ACTION_NEEDED}) 516 # add the dependency to the component automoc target only if compiling SDK 517 if(CAMITK_COMMUNITY_EDITION_BUILD) 518 set_property(TARGET ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} APPEND PROPERTY AUTOGEN_TARGET_DEPENDS action-${ACTION_NEEDED}) 524 # 4th CEP LIBRARIES DEPENDENCIES 525 if(${EXTENSION_NAME_CMAKE}_NEEDS_CEP_LIBRARIES) 526 set(CEP_LIBRARIES_DEPENDENCY_LIST "") #use for generating the project.xml file 527 foreach(CEP_LIBRARY_NEEDED ${${EXTENSION_NAME_CMAKE}_NEEDS_CEP_LIBRARIES}) 528 # include directories from build, camitk (local or global install). 529 include_directories(${CAMITK_BUILD_INCLUDE_DIR}/libraries/${CEP_LIBRARY_NEEDED}) 530 include_directories(${CAMITK_INCLUDE_DIR}/libraries/${CEP_LIBRARY_NEEDED}) 533 list(APPEND CEP_LIBRARIES debug ${CEP_LIBRARY_NEEDED}${CAMITK_DEBUG_POSTFIX}.lib 534 optimized ${CEP_LIBRARY_NEEDED} 537 list(APPEND CEP_LIBRARIES ${CEP_LIBRARY_NEEDED}) 539 # CMake / CDash dependencies 541 add_dependencies(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} library_${CEP_LIBRARY_NEEDED}) 542 # add the dependency to the component automoc target only if compiling SDK 543 if(CAMITK_COMMUNITY_EDITION_BUILD) 544 set_property(TARGET ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} APPEND PROPERTY AUTOGEN_TARGET_DEPENDS library_${CEP_LIBRARY_NEEDED}) 547 add_dependencies(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} library-${CEP_LIBRARY_NEEDED}) 548 list(APPEND CEP_LIBRARIES_DEPENDENCY_LIST ${CEP_LIBRARY_NEEDED} library-${CEP_LIBRARY_NEEDED}) 549 # add the dependency to the component automoc target only if compiling SDK 550 if(CAMITK_COMMUNITY_EDITION_BUILD) 551 set_property(TARGET ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} APPEND PROPERTY AUTOGEN_TARGET_DEPENDS library-${CEP_LIBRARY_NEEDED}) 557 ######################################################################### 561 # * Flags are options to give to the compiler # 562 # * Add user input flags # 563 # * Add platform specific flags # 565 ######################################################################### 567 # USER INPUT DEFINES COMPILER FLAG 568 if(${EXTENSION_NAME_CMAKE}_DEFINES) 569 foreach (FLAG ${${EXTENSION_NAME_CMAKE}_DEFINES}) 570 add_definitions(-D${FLAG}) 574 # USER INPUT CUSTOM COMPILER FLAG 575 if(${EXTENSION_NAME_CMAKE}_CXX_FLAGS) 576 foreach (FLAG ${${EXTENSION_NAME_CMAKE}_CXX_FLAGS}) 577 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAG}
") 581 # PLATFORM SPECIFIC COMPILER FLAG 582 # 64bits and other platform with relocation needs -fPIC 583 include(TestCXXAcceptsFlag) 584 check_cxx_accepts_flag(-fPIC FPIC_FLAG_ACCEPTED) 585 # no need to add -fPIC on mingw, otherwise it generates a warning: -fPIC ignored for target (all code is position independent) [enabled by default] 586 # msvc is also accepting the flag, but then produce warning D9002 : ignoring unknown option '-fPIC' cl 587 if(FPIC_FLAG_ACCEPTED AND NOT WIN32) 588 set_property(TARGET ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} APPEND PROPERTY COMPILE_FLAGS -fPIC) 593 ######################################################################### 597 # * Linking is the last stage of compilation # 598 # * Indicate what libraries to use for linking the target # 600 ######################################################################### 602 # Any component or action has to be linked with ${CAMITK_CORE_LIBRARIES} and with all its dependencies 603 target_link_libraries(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} ${CAMITK_CORE_LIBRARIES} ${CAMITK_LIBRARIES} ${COMPONENT_EXTENSION_LIBRARIES} ${ACTION_EXTENSION_LIBRARIES} ${CEP_LIBRARIES} ${CAMITK_ITK_LIBRARIES} ${LIBXML2_LIBRARY} ${OpenCV_LIBRARIES} ${IGSTK_LIBRARIES} ${XERCESC_LIBRARIES} ${GDCM_LIBRARIES} ${EXTERNAL_LIBRARIES}) 607 ######################################################################### 611 # * Define the output directory (location and name) # 612 # * Define the output name of the library # 613 # * Add ${CAMITK_DEBUG_POSTFIX} suffix to Debug MSVC built libraries # 614 # * Additional Linux .so files information # 616 ######################################################################### 618 # OUTPUT LIBRARY NAME 619 set_target_properties(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} 620 PROPERTIES OUTPUT_NAME ${${TYPE_EXTENSION_CMAKE}_OUTPUT_NAME} 623 # OUTPUT DIRECTORY LOCATION AND NAME 624 # Output directory (all extensions are private) 625 set_target_properties(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CAMITK_BUILD_PRIVATE_LIB_DIR}/${TYPE_EXTENSION}s 626 LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CAMITK_BUILD_PRIVATE_LIB_DIR}/${TYPE_EXTENSION}s 627 LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CAMITK_BUILD_PRIVATE_LIB_DIR}/${TYPE_EXTENSION}s 629 # Output directory (for dll plateform, this is still the same, extensions are private) 630 set_target_properties(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CAMITK_BUILD_PRIVATE_LIB_DIR}/${TYPE_EXTENSION}s 631 RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CAMITK_BUILD_PRIVATE_LIB_DIR}/${TYPE_EXTENSION}s 632 RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CAMITK_BUILD_PRIVATE_LIB_DIR}/${TYPE_EXTENSION}s 634 # Output directory (for dll plateform, this is still the same, extensions are private) 635 set_target_properties(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CAMITK_BUILD_PRIVATE_LIB_DIR}/${TYPE_EXTENSION}s 636 ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CAMITK_BUILD_PRIVATE_LIB_DIR}/${TYPE_EXTENSION}s 637 ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CAMITK_BUILD_PRIVATE_LIB_DIR}/${TYPE_EXTENSION}s 640 # OUTPUT LIBRARY NAME MSVC in DEBUG mode 642 set_target_properties(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} PROPERTIES DEBUG_POSTFIX ${CAMITK_DEBUG_POSTFIX}) 645 # ADDITIONAL LINUX .so FILE INFORMATION 646 set(${TYPE_EXTENSION_CMAKE}_LIBRARY_PROPERTIES ${${TYPE_EXTENSION_CMAKE}_LIBRARY_PROPERTIES} 647 VERSION "${CAMITK_VERSION_MAJOR}.${CAMITK_VERSION_MINOR}.${CAMITK_VERSION_PATCH}
" 648 SOVERSION "${CAMITK_VERSION_MAJOR}
" 650 # set the library specific info (SONAME...) 651 set_target_properties(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} PROPERTIES ${${TYPE_EXTENSION_CMAKE}_LIBRARY_PROPERTIES} LINK_INTERFACE_LIBRARIES "") 653 # see http://www.cmake.org/pipermail/cmake/2012-April/049889.html 654 # target properties (outputname and remove soname) 655 # set_property(TARGET ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} PROPERTY NO_SONAME 1) 656 # in CEP the version patch might not have been set 657 if (NOT CAMITK_VERSION_PATCH) 658 set(CAMITK_VERSION_PATCH 0) 663 ######################################################################### 667 # * When installing the project, header files (.h) and test data are # 668 # copied into a installation folder to determine. # 669 # * Indicate in this section, where to install your project and which # 670 # files to copy into that folder (during local/global installation) # 672 ######################################################################### 674 # FOLDER INSTALLATION 675 # Indicate where to install the action/component 676 install(TARGETS ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} 677 # TODO always use private lib, even for runtime 678 RUNTIME DESTINATION lib/${CAMITK_SHORT_VERSION_STRING}/${TYPE_EXTENSION}s 679 LIBRARY DESTINATION lib/${CAMITK_SHORT_VERSION_STRING}/${TYPE_EXTENSION}s 680 ARCHIVE DESTINATION lib/${CAMITK_SHORT_VERSION_STRING}/${TYPE_EXTENSION}s 681 COMPONENT ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} 684 # HEADERS INSTALLATION 685 # Build target to install provided headers to install (with HEADERS_TO_INSTALL option) 686 if(${EXTENSION_NAME_CMAKE}_HEADERS_TO_INSTALL) 687 export_headers(${${EXTENSION_NAME_CMAKE}_HEADERS_TO_INSTALL} COMPONENT ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} GROUP ${TYPE_EXTENSION}s) 690 # Build target to install all header files(with INSTALL_ALL_HEADERS option) 691 if(${EXTENSION_NAME_CMAKE}_INSTALL_ALL_HEADERS) 692 export_headers(${${EXTENSION_NAME_CMAKE}_HEADERS} COMPONENT ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} GROUP ${TYPE_EXTENSION}s) 695 # TESTDATA INSTALLATION 696 if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/testdata
") 697 # Check test data dir directory 698 if (NOT EXISTS ${CAMITK_BUILD_TESTDATA_DIR}) 699 make_directory( ${CAMITK_BUILD_TESTDATA_DIR} ) 702 # copy the files to test data directory 703 execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory testdata ${CAMITK_BUILD_TESTDATA_DIR} 704 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} 707 # during installation, copy the files to install directory 708 set (TESTDATA_DEST_DIR share/${CAMITK_SHORT_VERSION_STRING}/testdata) 709 install(DIRECTORY testdata/ 710 #DESTINATION share/testdata 711 #DESTINATION share/${CAMITK_SHORT_VERSION_STRING}/testdata 712 DESTINATION ${TESTDATA_DEST_DIR} 713 # COMPONENT ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} 714 PATTERN ".svn
" EXCLUDE 719 ######################################################################### 721 # CDASH SUBPROJECT DESCRIPTION # 723 # * Update the XML description of the subprojects dependencies # 726 ######################################################################### 727 # CDASH XML SUBPROJECTS DESCRIPTION UPDATE 728 camitk_register_subproject(${TYPE_EXTENSION_CMAKE} ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} DEPENDENCIES library-camitkcore ${COMPONENTS_DEPENDENCY_LIST} ${ACTIONS_DEPENDENCY_LIST} ${CEP_LIBRARIES_DEPENDENCY_LIST}) 732 ######################################################################### 734 # PACKAGING CATEGORIZATION # 736 # * On Windows, when building a package (win32 installer), the # 737 # install shield wizard proposes you to select which component # 739 # * Each component to install has a short description following its # 740 # name to understand its role. # 741 # * This section deals with the categorization and the description # 742 # of the component in this installer. # 744 ######################################################################### 746 # WINDOWS INSTALLER CATEGORIZATION 747 if(${EXTENSION_NAME_CMAKE}_CEP_NAME) 748 if (${EXTENSION_NAME_CMAKE}_CEP_NAME MATCHES "SDK
") 749 # The default SDK extensions are categorized as "required
" and are not "unselectable
" by the user at installation time 750 cpack_add_component(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} 751 DISPLAY_NAME ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} 752 DESCRIPTION ${${EXTENSION_NAME_CMAKE}_DESCRIPTION} 758 # Extension is selectable for installation in the wizard of the installer 759 cpack_add_component(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} 760 DISPLAY_NAME ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} 761 DESCRIPTION ${${EXTENSION_NAME_CMAKE}_DESCRIPTION} 762 GROUP ${${EXTENSION_NAME_CMAKE}_CEP_NAME} 766 # Extension if not categorized for packaging presentation 767 cpack_add_component(${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} 768 DISPLAY_NAME ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} 769 DESCRIPTION ${${EXTENSION_NAME_CMAKE}_DESCRIPTION} 774 ##################################################################################### 778 # * CAMITK_TRANSLATIONS contains the list of language to translate # 781 # * Create the translate.pro file which contains 4 sections: # 782 # - HEADERS: list of .h/.hpp files to look for tr("") QString # 783 # - SOURCES: list of .cpp files to look for tr("") QString # 784 # - FORMS: list of .ui files to look for tr("") QString # 785 # - TRANSLATIONS: list of .ts files which use CAMITK_TRANSLATIONS # 786 # to define each .ts file # 788 # * Execute lupdate program to update the .ts files with new QString # 791 # * Execute lrelease program to create .qm files (binary equivalent of # 794 # * Create translate.qrc which contains the list of .qm files. # 795 # * Create the flags.qrc file which contains the list of .png flags # 798 ##################################################################################### 800 if(${EXTENSION_NAME_CMAKE}_EXTRA_TRANSLATE_LANGUAGE) 801 if(${EXTENSION_NAME} STREQUAL "application
") 802 camitk_translate(USE_FLAGS 803 EXTRA_LANGUAGE ${${EXTENSION_NAME_CMAKE}_EXTRA_TRANSLATE_LANGUAGE}) 805 camitk_translate(EXTRA_LANGUAGE ${${EXTENSION_NAME_CMAKE}_EXTRA_TRANSLATE_LANGUAGE}) 808 if(${EXTENSION_NAME} STREQUAL "application
") 809 camitk_translate(USE_FLAGS) 818 ######################################################################### 820 # CTEST - COMPONENT TESTS DESCRIPTION # 822 ######################################################################### 824 # if auto test possible and required 825 if (NOT PACKAGING_NSIS AND BUILD_TESTING AND ${EXTENSION_NAME_CMAKE}_ENABLE_AUTO_TEST) 826 if(${EXTENSION_NAME_CMAKE}_COMPONENT_EXTENSION) 827 camitk_init_test( camitk-testcomponents ) 829 camitk_parse_test_add_separator(EXTENSION_TYPE ${TYPE_EXTENSION} EXTENSION_NAME ${EXTENSION_NAME}) 831 # Retrieve the files in testdata directory - a test will be applied for each of these files 832 # or use only the given files 833 if (${EXTENSION_NAME_CMAKE}_TEST_FILES) 834 # add testdata dir to filename 836 foreach(COMPONENT_TESTDATA_FILE ${${EXTENSION_NAME_CMAKE}_TEST_FILES}) 837 list(APPEND TESTFILES ${CMAKE_CURRENT_SOURCE_DIR}/${COMPONENT_TESTDATA_FILE}) 840 get_subdirectoryfiles( ${CMAKE_CURRENT_SOURCE_DIR}/testdata TESTFILES ) 843 if (NOT ${EXTENSION_NAME_CMAKE}_AUTO_TEST_LEVEL) 847 set(TESTLEVEL ${${EXTENSION_NAME_CMAKE}_AUTO_TEST_LEVEL}) 848 if (NOT ${TESTLEVEL} MATCHES "^[1-3]
") 850 message(WARNING "AUTO_TEST_LEVEL
set to 3 (${TESTLEVEL} is not
a valid level)
") 853 set(TESTLEVEL ${${EXTENSION_NAME_CMAKE}_AUTO_TEST_LEVEL}) 857 # Different the test level are done automatically: 858 # - level 1: load component extension, open & close test data 859 # - level 2: load component extension, open & close test data, save as 860 # - level 3: load component extension, open & close test data, save as and compare input with output 861 # disable some tests accordingly to options defined in camitk_extension macro arguments 862 if(${TESTLEVEL} STREQUAL "1
") 863 set(TEST_DESCRIPTION "Test loading the extension, opening and closing the component.
") 864 elseif(${TESTLEVEL} STREQUAL "2
") 865 set(TEST_DESCRIPTION "Test loading the extension, opening the component and saving it as
a file.
") 868 set(TEST_DESCRIPTION "Test loading the extension, opening, saving and closing the component and comparing saved with input component.
") 871 foreach(COMPONENT_TESTDATA_FILE ${TESTFILES}) 872 # Give the file name (full path) 873 get_directory_name(${COMPONENT_TESTDATA_FILE} DATA_FILE) 875 # Test procedure: Open an extension and a component- save it - Compare saved file to original file(level3) 876 if(${TESTLEVEL} EQUAL 3) 877 # Level 3 = level 2 + test the output -> test level 2 + add the PASS_FILE_OUTPUT options to the test 878 camitk_add_test(EXECUTABLE_ARGS "-i ${CAMITK_BUILD_TESTDATA_DIR}/${DATA_FILE} -c ${EXTENSION_PLUGIN_FILE} -l 2
" 879 PASS_FILE_OUTPUT ${CAMITK_BUILD_TESTDATA_DIR}/${DATA_FILE} 880 TEST_SUFFIX "-level3-
" 881 PROJECT_NAME ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} 885 if(${TESTLEVEL} EQUAL 2) 886 camitk_add_test(EXECUTABLE_ARGS "-i ${CAMITK_BUILD_TESTDATA_DIR}/${DATA_FILE} -c ${EXTENSION_PLUGIN_FILE} -l 2
" 887 TEST_SUFFIX "-level2-
" 888 PROJECT_NAME ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} 892 if(${TESTLEVEL} EQUAL 1) 893 camitk_add_test(EXECUTABLE_ARGS "-i ${CAMITK_BUILD_TESTDATA_DIR}/${DATA_FILE} -c ${EXTENSION_PLUGIN_FILE} -l 1
" 894 TEST_SUFFIX "-level1-
" 895 PROJECT_NAME ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} 899 camitk_parse_test_add(NAME ${CAMITK_TEST_NAME} LEVEL ${TESTLEVEL} DESCRIPTION ${TEST_DESCRIPTION}) 902 ######################################################################### 904 # CTEST - ACTION TESTS DESCRIPTION # 906 ######################################################################### 907 # We do not apply automatic tests on actions like (close, save, save as) as they 908 # may not act directly on components 909 elseif( ${EXTENSION_NAME_CMAKE}_ACTION_EXTENSION AND NOT (${${TYPE_EXTENSION_CMAKE}_OUTPUT_NAME} MATCHES "application
")) 910 camitk_init_test( camitk-testactions ) 912 camitk_parse_test_add_separator(EXTENSION_TYPE ${TYPE_EXTENSION} EXTENSION_NAME ${EXTENSION_NAME}) 914 # get the names of actions .dlls in lib directory 915 get_subdirectoryfiles( ${CAMITK_BUILD_PRIVATE_LIB_DIR}/actions/ ACTIONSDLLS ) 917 # Retrieve the files in testdata directory - a test will be applied for each of these files 918 # or use only the given files 919 if (${EXTENSION_NAME_CMAKE}_TEST_FILES) 920 # add testdata dir to filename 922 foreach(ACTION_TESTDATA_FILE ${${EXTENSION_NAME_CMAKE}_TEST_FILES}) 923 list(APPEND TESTFILES ${CAMITK_BUILD_TESTDATA_DIR}/${ACTION_TESTDATA_FILE}) 926 get_subdirectoryfiles(${CAMITK_BUILD_TESTDATA_DIR} TESTFILES) 929 foreach( ACTION_TESTDATA_FILE ${TESTFILES}) 930 # Test procedure: Open a file - load an action extension - Apply an action on the component wrapping the file 931 camitk_add_test(EXECUTABLE_ARGS "-i ${ACTION_TESTDATA_FILE} -
a ${EXTENSION_PLUGIN_FILE}
" 932 TEST_SUFFIX "-level1-
" 933 PROJECT_NAME ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME} 935 camitk_parse_test_add(NAME ${CAMITK_TEST_NAME} LEVEL 1 DESCRIPTION "Open
a file, load the action and apply it on the component.
") 938 endif() # NOT PACKAGING_NSIS AND BUILD_TESTING AND ${EXTENSION_NAME_CMAKE}_ENABLE_AUTO_TEST) 940 ######################################################################### 942 # CTEST - Integration test # 944 ######################################################################### 946 if (NOT PACKAGING_NSIS AND BUILD_TESTING AND ${EXTENSION_NAME_CMAKE}_ENABLE_INTEGRATION_TEST) 947 # add a specific test to run the action, save the output and compare it to expected 948 camitk_add_integration_test() 951 endif() # endif(${TYPE_EXTENSION_CMAKE}_${EXTENSION_NAME_CMAKE}) 956 # TODO write a viewer_extension macro in CamiTK A pseudo-namespace used to group CMake macros and functions.
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
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
cmake modules macros camitk test endif() add_custom_target(camitk-ce-iwyu COMMAND $
Definition: CamiTKIncludeWhatYouUse.h:37
camitk_extension()
Macro camitk_extension simplifies writing a camitk extension (component, action)
Definition: CamiTKExtension.h:90
gather_headers_and_sources()
macro gather_headers_and_sources find all headers, sources, including the qt ui, moc and resources an...
Definition: GatherHeadersAndSources.h:15
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