|
|
(43 intermediate revisions by 10 users not shown) |
Line 1: |
Line 1: |
| This article mostly discusses creating new Find*.cmake files for libraries that don't have one yet. But in case you already have one, let's see how it works. In CMakeLists.txt, write
| | {{CMake/Template/Moved}} |
|
| |
|
| <pre>
| | This page has moved [https://gitlab.kitware.com/cmake/community/wikis/doc/tutorials/How-To-Find-Libraries here]. |
| find_package(LibXML++ REQUIRED)
| |
| include_directories(${LibXML++_INCLUDE_DIRS})
| |
| set(LIBS ${LIBS} ${LibXML++_LIBRARIES})
| |
| </pre>
| |
| | |
| Then, after detecting all the libraries, for your target:
| |
| | |
| <pre>
| |
| target_link_libraries(exampleProgram ${LIBS})
| |
| </pre>
| |
| | |
| For this to work, you'll need a file called FindLibXML++.cmake in your CMake module path. Since CMake (currently) doesn't ship one, you'll have to ship it within your project. Create a folder named cmake/Modules/ under your project root, and in the root CMakeLists.txt, include the following code:
| |
| | |
| <pre>
| |
| set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
| |
| </pre>
| |
| | |
| As you may have guessed, you need to put the CMake modules that you use, and that CMake has to find automatically, inside that folder.
| |
| | |
| That's it, usually. Some libraries might require something else, so be sure to look inside that FindSomething.cmake file to see the documentation for that specific library.
| |
Latest revision as of 15:40, 30 April 2018