Writing your own find-modules
On a rare occasion, the library that you really want to use in your project doesn't provide a config-file or a PkgConfig file, and there's no find-module readily available in CMake already. You can then write a custom find-module for that library and ship it with your project. This situation is not ideal, but in the interest of taking care of the users of your project, it has to be done.
Since we have already become familiar with libpqxx
in the previous section, let's write a nice find-module for it. We start by writing in a new FindPQXX.cmake
file, which we'll store in the cmake/module
directory of our project source tree. We need to make sure that the find-module gets discovered by the CMake when find_package()
is called, so we'll add this path to the CMAKE_MODULE_PATH
variable in our CMakeLists.txt
with list(APPEND)
. The whole list file should look like this:
chapter07/04-find-package-custom/CMakeLists.txt
cmake_minimum_required...