Exporting packages with a custom Find module

Hello,

I’m currently in the process of creating a CMake export package for a library we develop. This library has a public dependency on several other libraries, one of which doesn’t have package config files or a find module. In order to find this target (lets call it libA for now) we have a custom find module. From what I’ve gathered so far, the way you handle dependencies in the package is to call find_dependency(package_name). This obviously won’t work for libA as there isn’t a built in way to find it. I’m just wondering what options I have, I’m thinking I could either:

  1. Copy the contents of our custom find module into the config files, so we can create the targets.
  2. Install the custom find module along with the library, so find_dependency will create the targets.

I’m wondering if there is a better/standard way to solve this issue?

1 Like

I would do something like this:

set(_mypackage_module_path_save "${CMAKE_MODULE_PATH}")
list(CMAKE_MODULE_PATH INSERT 0 "${CMAKE_CURRENT_LIST_DIR}/find_modules")

# Find modules

set(CMAKE_MODULE_PATH "${_mypackage_module_path_save}")
unset(_mypackage_module_path_save)
2 Likes

Thank for your response! Can I just confirm this would be installing the libA finder with my library, i.e. the directory for my lib would be something like:

lib/cmake/MyLib
├── MyLibConfig.cmake
├── MyLibTargets.cmake
├── MyLibConfig-version.cmake
├── find_modules
│   ├── FindLiba.cmake

and then within the config file I put the above code

set(_mypackage_module_path_save "${CMAKE_MODULE_PATH}")
list(CMAKE_MODULE_PATH INSERT 0 "${CMAKE_CURRENT_LIST_DIR}/find_modules")

find_dependency(libA) # uses my installed finder to create liba::liba targets used by this library

set(CMAKE_MODULE_PATH "${_mypackage_module_path_save}")
unset(_mypackage_module_path_save)

Yep, that looks like a suitable pattern to me.

1 Like