Computer Assited Medical Intervention Tool Kit  version 3.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Functions
CMake macros

The CMake macros defined for the CamiTK SDK. More...

+ Collaboration diagram for CMake macros:

Functions

 camitk_add_subdirectory ()
 camitk_add_subdirectory is a utility macro that add a source subdirectory only if: More...
 
 camitk_add_test ()
 camitk_add_test is a macro to add a new test to the CTest infrastructure It encapsulates CMake add_test and adds useful way of testing programs. More...
 
 camitk_application ()
 macro camitk_application simplify writing a CMakeLists.txt for CamiTK application extension More...
 
 camitk_cep_packaging ()
 CamiTK cep packaging allows you to build a package from a CEP If README and COPYRIGHT files exists at top source dir, then they will be included in the source package. More...
 
 camitk_extension ()
 Macro camitk_extension simplifies writing a camitk extension (component, action) More...
 
 camitk_extension_project ()
 macro add_cep creates an optional (disabled by default) CEP (CamiTK Extension Project) subdirectory the build. More...
 
 camitk_init_test ()
 camitk_init_test is a macro to initialize a group of test (for the same command) It is used to initialize a series of tests for a given target. More...
 
 camitk_library ()
 macro camitk_library simplifies the declaration of a library inside CamiTK and is to be used for all inner project libraries More...
 
 camitk_sub_project_add ()
 macro camitk_sub_project_add adds a subproject definition from targets and its dependencies (if any) to the variable Typically recursively call this function accross all targets to generate Project.xml file. More...
 
 camitk_sub_project_init ()
 MACRO camitk_sub_project_init initializes the xml_subprojects variable to gather CamiTK subprojects. More...
 
 camitk_sub_project_validate ()
 macro camitk_sub_project_validate validates the xml_subprojects variable by ending its xml tag i.e. More...
 
 export_headers ()
 export_headers is a macro that install header files at build and install time More...
 
 gather_headers_and_sources ()
 macro gather_headers_and_sources find all headers, sources, including the qt ui, moc and resources and create two variables from it: ${Name}_HEADERS ${Name}_SOURCES, and define all needed commands for qt if BaseDirectory is specified, the glob recurse starts in directory DIR More...
 
 get_directory_name ()
 macro get_directory_name set the variable VariableName to the name of the last directory of FullPathDirectory set the variable VariableName_CMAKE to be the same but in uppercase More...
 
 get_subdirectories ()
 macro get_subdirectories get the names of all the subdirectories that contains a CMakeLists.txt More...
 
 get_subdirectoryfiles ()
 macro get_subdirectoryfiles get the names of all the files (and not directories) contained in a defined directory More...
 
 parse_arguments ()
 macro parse_arguments is a fork from CMakeMacroParseArguments see http://www.cmake.org/Wiki/CMakeMacroParseArguments for more information More...
 

Detailed Description

The CMake macros defined for the CamiTK SDK.

Function Documentation

camitk_add_subdirectory ( )

camitk_add_subdirectory is a utility macro that add a source subdirectory only if:

  1. it exists
  2. it contains a CMakeLists This can avoid CMake warning (see cmake –help-policy CMP0014), but do the opposite: it prints out an information message when it succeed including the directory.

Usage:

Parameters
subdir(required) the name of the source subdirectory to include
camitk_add_test ( )

camitk_add_test is a macro to add a new test to the CTest infrastructure It encapsulates CMake add_test and adds useful way of testing programs.

It cannot operate on its on, you need to call camitk_init_test first (and only once) before calling camitk_add_test

Details on the runned test can be found in ${CMAKE_BINARY_DIR}/Testing/Temporary/target# where target is the executable name (see camitk_init_test() macro), and # is the test order number.

Usage:

camitk_add_test(EXECUTABLE_ARGS "arg1 arg2 arg3"
PASS_FILE pristineOutput
)
Parameters
EXECUTABLE_ARGS(optional) The executable arguments (all in double quotes), typically each test will have different arguments. Can be empty
PASS_FILE(optional) If specified the test to perform is to compare the output of the command to this file. It the output is the same, then the test is passed, otherwise it is failed.
PASS_REGULAR_EXPRESSION(optional) This is equivalent to "PASS_REGULAR_EXPRESSION regexp" property for the test, see http://www.cmake.org/Wiki/CTest:FAQ#My_test_does_not_return_non-zero_on_failure._What_can_I_do.3F
FAIL_REGULAR_EXPRESSIONThis is equivalent to "FAIL_REGULAR_EXPRESSION regexp" property for the test, see http://www.cmake.org/Wiki/CTest:FAQ#My_test_does_not_return_non-zero_on_failure._What_can_I_do.3F

If no argument are given, it does the equivalent as add_test(name target)

Note
You can only choose one between nothing, PASS_FILE, PASS_REGULAR_EXPRESSION and FAIL_REGULAR_EXPRESSION

Example invocation:

add_executable(myprogram)
...
# Start the test series for myprogram
camitk_init_test(myprogram)
camitk_add_test(EXECUTABLE_ARGS "-a inputfile.xml -c" PASS_FILE pristineOuputToCompareTo.xml) # will be called myprogram1
...
camitk_add_test(...) # myprogram2
See Also
camitk_init_test
camitk_application ( )

macro camitk_application simplify writing a CMakeLists.txt for CamiTK application extension

The name of the application is automatically the name of the directory from where this macro is called prefixed with "camitk-"

On Unix additional system resources can also be automatically installed or configured: man pages, desktop file and XPM icons.

To write a simple man page, please refer to SDK application examples. If you need to generate a simple manpage or analyze the command line arguments, the CamiTK team recommands to use Code Synthesis CLI configuration (see http://codesynthesis.com/projects/cli)

usage:

[DISABLED]
[NEEDS_QT_MODULES]
[NEEDS_ITK]
[NEEDS_PYTHON]
[NEEDS_CEP_LIBRARIES CEPLib1 CEPLib12 ...]
[NEEDS_COMPONENT_EXTENSION component1 component2 ...]
[NEEDS_ACTION_EXTENSION ation1 action2 ...]
[DEFINES flag1 flag2 ...]
[CXX_FLAGS flag1 flag2 ...]
[ADDITIONAL_SOURCES source.cxx source.cpp ...]
[INCLUDE_DIRECTORIES dir1 dir2 ...]
[EXTERNAL_LIBRARIES lib1 lib2 ...]
)
Parameters
DISABLEDmeans this is a default application is NOT to be compiled automatically
NEEDS_QT_MODULESadd this if your library depends on Qt modules, such as QtCore, QtGui, QtMultimedia, QtNetwork, QtOpenGL, QtScript, QtScriptTools, QtSql, QtSvg, QtWebkit, QtXml, QtXmlPatterns, QtDeclarative
NEEDS_ITKmeans this application requires ITK to be compiled / run.
NEEDS_CEP_LIBRARIESlist of needed camitk CEP libraries
NEEDS_COMPONENT_EXTENSIONlist of needed component extensions
NEEDS_ACTION_EXTENSIONlist of needed component extensions
DEFINESlist of define flags to add at compilation time
CXX_FLAGS= list of compiler flags to add (such as warning levels (-Wall ...)).
ADDITIONAL_SOURCESlist of additional sources (that cannot be automatically found by gather_headers_and_sources macro)
CEP_NAMEspecify the CEP_NAME, which is used to categorized the application for packaging purpose No CEP_NAME provided will result in default categorization (generic application).
DESCRIPTIONSimple description of the application. Used for packaging presentation for instance.
INCLUDE_DIRECTORIESadditional include directories
EXTERNAL_LIBRARIESexternal libraries to add to the link command
camitk_cep_packaging ( )

CamiTK cep packaging allows you to build a package from a CEP If README and COPYRIGHT files exists at top source dir, then they will be included in the source package.

Usage:

camitk_cep_packaging(DESCRIPTION "CEP package description"
[NAME packageName]
[VENDOR vendorName]
[CONTACT contactName]
)
Parameters
NAME(optional) Specify the package name (default is project name)
VENDOR(optional) Specify the vendor name (default is TIMC-IMAG)
CONTACT(optional) Specify the contact name (default is link to CamiTK website)
APPLICATIONS(optional) If you want to package some applications

When configuring CMake, do not forget to set the CMAKE_INSTALL_PREFIX correctly (e.g., /usr on Linux) It will always use the CamiTK install directory as install prefix (install where the core is already)

To generate deb package add this to the cmake configuration line: -DCPACK_BINARY_DEB:BOOL=TRUE To generate rpm package add this to the cmake configuration line: -DCPACK_BINARY_RPM:BOOL=TRUE

camitk_extension ( )

Macro camitk_extension simplifies writing a camitk extension (component, action)

The name of the extension is automatically the name of the directory from where this macro is called, unless it is overriden by the TARGET_NAME parameter.

usage:

extension( <type>
[DISABLED]
[NEEDS_QT_MODULES]
[NEEDS_ITK]
[NEEDS_LIBXML2]
[NEEDS_OPENCV]
[NEEDS_IGSTK]
[NEEDS_XSD]
[NEEDS_GDCM]
[NEEDS_ACTION_EXTENSION action1 action2 ...]
[NEEDS_COMPONENT_EXTENSION component1 component2 ...]
[NEEDS_CEP_LIBRARIES CEPLib1 CEPLib2 ...]
[INCLUDE_DIRECTORIES dir1 dir2 ...]
[DEFINES flag1 flag2 ...]
[CXX_FLAGS flag1 flag2 ...]
[EXTERNAL_SOURCES file1 file2 ...]
[EXTERNAL_LIBRARIES lib1 lib2 ...]
[HEADERS_TO_INSTALL header1.h header2.h ...]
[INSTALL_ALL_HEADERS]
[TARGET_NAME non-default-targetname]
)
Parameters
<type>= REQUIRED. The selected type of extension you wish to build.
DISABLED= means this is a not a default extension, it will not be compiled automatically
NEEDS_QT_MODULES= add this if your library depends on Qt modules, such as QtCore, QtGui, QtMultimedia, QtNetwork, QtOpenGL, QtScript, QtScriptTools, QtSql, QtSvg, QtWebkit, QtXml, QtXmlPatterns, QtDeclarative
NEEDS_ITK= add this if your component needs itk. Do not forget to add the needed list of itk libraries in the LIBRARIES parameter
NEEDS_LIBXML2= add this if your component needs libxml2
NEEDS_XSD= add this if your action needs Codesynthesis xsd cxx (xml schema compiler)
NEEDS_OPENCV= add this if your component needs OpenCV
NEEDS_IGSTK= add this if your component needs IgsTK
NEEDS_XERCESC= add this if your action / component needs XercesC library
NEEDS_CEP_LIBRARIES= list of needed CEP libraries (not external dependencies)
NEEDS_COMPONENT_EXTENSION= list of needed component extensions
NEEDS_ACTION_EXTENSION= list of needed component extensions
INCLUDE_DIRECTORIES= additional include directories
DEFINES= list of define flags to add at compilation time.
CXX_FLAGS= list of compiler flags to add (such as warning levels (-Wall ...)).
EXTERNAL_SOURCES= list of extra source/headers files (external to the current directory) that needed to be added to the SOURCES variable. Note: EXTERNAL_SOURCES are not installed
EXTERNAL_LIBRARIES= external libraries to add to the link command
HEADERS_TO_INSTALL= list of headers to install, if present this will automatically create an "install-COMPONENT_NAMEcomponent" target, that can be used anywhere else to manage dependencies to this component. The headers are installed ${CAMITK_BUILD_INCLUDE_DIR}/COMPONENT_NAME when the target "install-COMPONENT_NAMEcomponent" is called.
INSTALL_ALL_HEADERS= install all of the headers (this is the lazy solution, please consider making a list and using HEADERS_TO_INSTALL parameter instead!
TARGET_NAME= specify a target name different than the default (default is the action/component directory name) this can be very useful for example when you have action/component directory in your CEP that has the same name as one in the camitk opensource.
CEP_NAME= specify the CEP_NAME, which is used to categorized the extension for packaging purpose No CEP_NAME provided will result in default categorization (generic extension).
DESCRIPTION= Simple description of the extension. Used for packaging presentation for instance.
NEEDS_GDCM= Add this, if your extension requires GDCM 2.x library
camitk_extension_project ( )

macro add_cep creates an optional (disabled by default) CEP (CamiTK Extension Project) subdirectory the build.

Usage:

[ENABLED]
[NAME cepName]
[DESCRIPTION longDescription]
[DEFAULT_APPLICATION exeName]
[NEEDS_CEP cep1 cep2...]
[LICENSE licenseName]
)
Parameters
CONTACTMandatory, this is the person(s) to contact to get more information about the CEP
ENABLEDIf used, this CEP is forced by default (otherwise the user as to tick the option in CMake GUI or defined a -DCEP_<cepName>:BOOL=TRUE on the command line
NAMEBy default the name of a CEP is given automatically by the name of the top level source directory If you specify a name here, the directory name will be ignored
DESCRIPTIONA (not so) small description of this CEP (objective, content, implementation information)
DEFAULT_APPLICATIONThe default application to run (for MSVC launchers), default is camitk-imp
NEEDS_CEP(TODO) Dependencies to other CEP
LICENSEThe name of the license for this CEP, default is LGPL-v3
camitk_init_test ( )

camitk_init_test is a macro to initialize a group of test (for the same command) It is used to initialize a series of tests for a given target.

Usually this is placed in the same CMakeLists.txt as the add_executable() cmake instruction or camitk_application() macro

It does few useful things:

  • check if the application is properly defined
  • initialize test id (then automatically incremented in camitk_test_declare
  • initialize test output directory

Usage:

camitk_init_test(applicationname)
Parameters
applicationname(required) The name of the test application (in camitk context, name of the project

Example invocation:

...
# Start the test series for myprogram
camitk_init_test(myprogram)
camitk_add_test(...) # will be called myprogram_1
...
camitk_add_test(...) # myprogram_2
See Also
camitk_add_test
camitk_library ( )

macro camitk_library simplifies the declaration of a library inside CamiTK and is to be used for all inner project libraries

The name of the CEP library is deduced from the name of the directory, unless LIBNAME is provided

If the library is compiled as shared, it adds the needed library properties If it needs relocation flag fPIC (on some plateforms), this macro should determine if this is the case and specify this flag

usage:

SHARED|STATIC
[LIBNAME libname]
[PUBLIC]
SOURCES source1.cpp source1.h...
[NEEDS_CEP_LIBRARIES lib1 lib2...]
[NEEDS_LIBXML2]
[NEEDS_XERCESC]
[NEEDS_XSD]
[NEEDS_QT_MODULES]
[DEFINES flag1 flag2 ...]
[EXTERNAL_LIBRARIES lib1 lib2... ]
[INCLUDE_DIRECTORIES dir1 dir2...]
[LINK_DIRECTORIES dir1 dir2...]
[HEADERS_TO_INSTALL]
[CEP_NAME]
)
Parameters
SHAREDoptional, if the library should be compiled as shared
SOURCESall sources to be included in the library
INCLUDE_DIRECTORIESall needed include directories (${CMAKE_CURRENT_SOURCE_DIR} and ${CMAKE_CURRENT_BINARY_DIR} are automatically added)
EXTERNAL_LIBRARIESall the libraries to be used during the link (shared or static)
NEEDS_CEP_LIBRARIESall the libraries to be used during the link (shared or static)
NEEDS_LIBXML2add this if the CEP library needs libxml2
NEEDS_XERCESCadd this if your action / component needs XercesC library
NEEDS_XSDadd this if your action needs Codesynthesis xsd cxx (xml schema compiler)
NEEDS_QT_MODULESadd this if your library depends on Qt modules, such as QtCore, QtGui, QtMultimedia, QtNetwork, QtOpenGL, QtScript, QtScriptTools, QtSql, QtSvg, QtWebkit, QtXml, QtXmlPatterns, QtDeclarative
LIBNAMEforce the CEP library name to be different from the directory it is in
LINK_DIRECTORIESadditional directories to use in link_directories(...)
DEFINESlist of define flags to add at compilation time
PUBLICThe library is a public library that has to be loaded directly by the operating system. It is generally only needed for SDK library. A public library should not be installed in the lib/${CAMITK_SHORT_VERSION_STRING} but directly in lib/ (on Unix/MacOS) or bin/ (on windows)
HEADERS_TO_INSTALLlist of headers to install, if present this will automatically create an "install-COMPONENT_NAMEcomponent" target, that can be used anywhere else to manage dependencies to this component. The headers are installed ${CAMITK_BUILD_INCLUDE_DIR}/COMPONENT_NAME when the target "install-COMPONENT_NAMEcomponent" is called.
CEP_NAMEspecify the CEP_NAME, which is used to categorized the extension for packaging purpose No CEP_NAME provided will result in default categorization (generic extension).
DESCRIPTIONSimple description of the extension. Used for packaging presentation for instance.

References camitk_sub_project_add(), CEP_LIBRARY, COMPONENT, DESCRIPTION, elseif(), endif(), export_headers(), file(), get_directory_name(), GROUP, if(), include(), macro(), message(), parse_arguments(), set(), string(), and variable().

camitk_sub_project_add ( )

macro camitk_sub_project_add adds a subproject definition from targets and its dependencies (if any) to the variable Typically recursively call this function accross all targets to generate Project.xml file.

Usage:

[DEPENDENCIES dep1 dep2 dep3]
)
Parameters
TARGET_TYPEname the library / exe program targeted for CMake compilation
DEPENDENCIES(optional) the library dependencies to build the target

Referenced by camitk_library().

camitk_sub_project_init ( )

MACRO camitk_sub_project_init initializes the xml_subprojects variable to gather CamiTK subprojects.

usage:

camitk_sub_project_validate ( )

macro camitk_sub_project_validate validates the xml_subprojects variable by ending its xml tag i.e.

By adding the closing </Project> xml node, this will close the xml data Then create the '${CMAKE_BINARY_DIR}/Project.xml file Use this file to send to the DashBoard to get the CEP and its subprojects definition

Usage:

Parameters
CEP_SET(optional) should be added only if this is a CEP set validation
export_headers ( )

export_headers is a macro that install header files at build and install time

Duplicate headers installation:

  • one is used at compiled time and puts everything in ${CMAKE_BINARY_DIR}/include/${CAMITK_SHORT_VERSION_STRING}/${GroupName}/${ComponentName}/${SubdirName}
  • the other one is used at installation time and puts everything in ${CMAKE_INSTALL_PREFIX}/include/${CAMITK_SHORT_VERSION_STRING}/${GroupName}/${ComponentName}/${SubdirName}

Usage:

export_headers(HeaderFile1.h HeaderFile2.h ...
COMPONENT ComponentName
[GROUP GroupName]
[SUBDIRECTORY SubdirName]
)
Parameters
HeaderFileX.h(required) A list of header files to install
COMPONENTname of the component to use. This is also the include subdirectory name used for copying the file
GROUP(optional) the name of the group this install should be using group will be prepend to the component name.
SUBDIRECTORY(optional) subdirectory to use in ${CAMITK_INCLUDE_DIR}/include/${ComponentName}

Example invocation:

#--------------
# installation
#--------------
export_headers(${MYPROJECT_HEADERS}
COMPONENT ${MYPROJECT_NAME}
)

Referenced by camitk_library().

gather_headers_and_sources ( )

macro gather_headers_and_sources find all headers, sources, including the qt ui, moc and resources and create two variables from it: ${Name}_HEADERS ${Name}_SOURCES, and define all needed commands for qt if BaseDirectory is specified, the glob recurse starts in directory DIR

Usage:

gather_headers_and_sources(Name [BaseDirectory])
Parameters
Name(required) the prefix of the resulting variables ${Name}_HEADERS ${Name}_SOURCES
BaseDirectory(optional) do not start gathering from current subdirectory but from the given directory
get_directory_name ( )

macro get_directory_name set the variable VariableName to the name of the last directory of FullPathDirectory set the variable VariableName_CMAKE to be the same but in uppercase

Usage:

directory_name(FullPathDirectory VariableName)
Parameters
FullPathDirectory(required) the full path directory (input)
VariableName(required) the resulting variable name containing the base name all in uppercase

Referenced by camitk_library().

get_subdirectories ( )

macro get_subdirectories get the names of all the subdirectories that contains a CMakeLists.txt

Usage:

Parameters
Name(required) the name of the resulting variable containing all the subdirectories names
get_subdirectoryfiles ( )

macro get_subdirectoryfiles get the names of all the files (and not directories) contained in a defined directory

Usage:

get_subdirectoryfiles(Path Filenames)

Path (required) input directory path Name (required) the name of the resulting variable containing all the file names of the given directory

parse_arguments ( )

macro parse_arguments is a fork from CMakeMacroParseArguments see http://www.cmake.org/Wiki/CMakeMacroParseArguments for more information

Usage:

parse_arguments(PREFIX POSSIBLE_ARGUMENTS POSSIBLE_OPTIONS)