CMake:How To Find Installed Software: Difference between revisions

From KitwarePublic
Jump to navigationJump to search
No edit summary
(Replace content with link to new CMake community wiki)
 
(13 intermediate revisions by 6 users not shown)
Line 1: Line 1:
If your software uses external libraries (i.e. libraries not coming with your software), you don't know in advance where its headers and libraries will be located on the system where your software will be compiled.
{{CMake/Template/Moved}}
Depending on the location appropriate include directories and library search paths will have to be added to the compile commands.


CMake helps you with this by providing so-called modules. Let's say you want to use the PNG-Library.  
This page has moved [https://gitlab.kitware.com/cmake/community/wikis/doc/tutorials/How-To-Find-Installed-Software here].
<pre>
FIND_PACKAGE(PNG)
 
IF(PNG_FOUND)
  INCLUDE_DIRECTORIES(${PNG_INCLUDE_DIR})
 
  ADD_EXECUTABLE(imageviewer main.c image.c)
  TARGET_LINK_LIBRARIES(imageviewer ${PNG_LIBRARY})
 
ENDIF(PNG_FOUND)
</pre>
 
Every module is provided in the form Find<name>.cmake, they are located in the CMake module directory, on UNIX usualy <tt>/usr/local/share/CMake/Modules/ </tt> It is then used in the CMakeLists.txt with the FIND_PACKAGE(<name>) command. For details see the regular CMake documentation.
Every module will define the following variables:
* <name>_FOUND
* <name>_INCLUDE_DIR or <name>_INCLUDES
* <name>_LIBRARY or <name>_LIBRARIES

Latest revision as of 15:40, 30 April 2018


The CMake community Wiki has moved to the Kitware GitLab Instance.

This page has moved here.