Add libraries to CMake projects
Add your own libraries
Use the qt_add_library command to create a library and link against it in the CMakeLists.txt file, as instructed in Structuring projects.
Specify whether the library is statically or dynamically linked. For a statically linked internal library, add the CMake: target_link_libraries command to the CMakeLists.txt project file to specify dependencies.
Add external libraries
Through external libraries, Qt Creator can support code completion and syntax highlighting as if the code were a part of the current project or the Qt library.
Qt Creator detects the external libraries using the CMake: find_package command command. Some libraries come with the CMake installation. You can find those in the Modules
directory of your CMake installation. For more information, see CMake: cmake-packages(7).
Use local CMake Find packages
For CMake projects that have external dependencies, use Find<package>.cmake modules that expose imported targets. You can use the pre-defined sample_find_module
code snippet to add sample commands to a .cmake
file. You can then change the commands as necessary.
Place Find modules in the ${CMAKE_CURRENT_SOURCE_DIR}/cmake
directory, and append the directory name to the CMAKE_MODULE_PATH list variable. For example:
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
See also How To: Build with CMake, CMake, Completion, and Snippets.