1

I'm creating a library (called fmi2) which I intend to install on my local machine (via a package manager) and then link to with a bunch of other libraries.

I'll be providing a Findfmi2.cmake file so that I can call find_package(fmi2) from my other libraries, but where should this file be conventionally installed?

Here are some choices I've considered and their problems:

  • /usr/share/cmake-3.8/Modules/Findfmi2.cmake
    • Advantage: find_package(fmi2) will just work
    • Disadvantage: Only works for one version of cmake
  • /usr/share/cmake/Modules/Findfmi2.cmake
    • Advantage: Should work for any version of cmake
    • Disadvantage: This is not a default folder. We would need to add set(CMAKE_MODULES_PATH /usr/share/cmake/Modules) and this kills any portability.
  • ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Findfmi2.cmake
    • Advantage: Portable, just need to add set(CMAKE_MODULES_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
    • Disadvantage: Not system-wide. Need to manually add this file to each library that uses it. This duplicates files in my framework.
Stewart
  • 4,356
  • 2
  • 27
  • 59
  • 1
    I had a [similar question](https://stackoverflow.com/questions/44920389/installing-a-cmake-library-also-ship-find-modules-for-the-dependencies) some time ago and would be very interested to hear an answer to your question! – oLen Aug 08 '17 at 10:59

1 Answers1

1

You are authoring content in CMake. You don't need a FindModule. That is designed to find external non-CMake outputs.

This Stackoverflow post from ruslo should help you understand the difference between find_package() module mode and config mode. It also answers your question about paths for FindModules, i.e. they are copied into your CMake project, not discovered system-wide, unless they are part of the official FindModules bundled with CMake in the "Modules" directory.

Modern CMake documentation now finally contains good examples to create a config mode package: cmake-packages

If you want explicit full examples, though using slightly older syntax for the config.cmake files, ruslo has more on Github.

utopia
  • 1,477
  • 8
  • 7