CMake for cisst Developers
Note
This page is for cisst library developers. For users building against cisst, see Compiling cisst and SAW with CMake.
For the cisst libraries developers, we have a few important macros that should be used to maintain the consistency of the CMake configuration:
cisst_set_package_settings: this macro allows to save some specific settings associated to a given cisst library. For example, in thecisstCommonCMakeLists.txt configuration file,cisst_set_package_settings (cisstCommon LibXml2 INCLUDE_DIRECTORIES LIBXML2_INCLUDE_DIR)indicates that any library compiled againstcisstCommonwill need to use some extra include directories (keywordINCLUDE_DIRECTORIES) becausecisstCommonhas been compiled with LibXml2 support. The extra include directories are defined by the CMake variableLIBXML2_INCLUDE_DIRdefined byFindLibXml2.cmake. The following settings can be saved:INCLUDE_DIRECTORIES: will be used with CMakeinclude_directoriesin the cisst use file (include (${CISST_USE_FILE})LIBRARIES: will be used bycisst_target_link_librariesLINK_DIRECTORIES: will be used with CMakelink_directoriesin the cisst use file (include (${CISST_USE_FILE})PACKAGES,PACKAGE_COMPONENTSandCMAKE_FILES: will be used by CMakefind_packageandincludein the cisst use file (include (${CISST_USE_FILE})
cisst_unset_all_package_settings: this macro is used to remove all settings. For examplecisst_unset_all_package_settings (cisstCommon LibXml2)tells thatcisstCommondoesn’t use LibXml2 anymore. For all external dependencies, the CMake configuration should have anif else endifto make sure settings are removed when an external dependency is either not found or turned off by the user.cisst_add_library: this macro is used to add a new library. For example, the `cisstVectorQt CMakeLists.txt CMake configuration file] contains:cisst_add_library ( LIBRARY cisstVectorQt LIBRARY_DIR cisstVector DEPENDENCIES cisstCommon cisstVector SOURCE_FILES vctPlot2DOpenGLQtWidget.cpp HEADER_FILES vctPlot2DOpenGLQtWidget.h vctExportQt.h ADDITIONAL_SOURCE_FILES ${QT_WRAPPED_CPP})
In this example the following keywords are used:
LIBRARY: name of the library to be generatedLIBRARY_DIR: relative path to include files from the cisst source directory, i.e.cisst/DEPENDENCIES: list of cisst libraries required for this librarySOURCE_FILES: list of source files found in the current source directory, i.e. directory containing this CMakeLists.txt fileHEADER_FILES: list of header files found in theLIBRARY_DIR. In this example, header files are found incisst/cisstVectorADDITIONAL_SOURCE_FILES(andADDITIONAL_HEADER_FILES): extra source (header) files not found in the default directories. These can be generated files, private header files, …