1

I am developing two CMake projects: libABC and libXYZ. libXYZ requires libABC, and so I would like install FindABC.cmake in an appropriate location on Mac and Linux machines.

libABC and its related files are installed under /usr/local by default, and I think FindABC.cmake also should be installed under the same directory. I tried installing it in the following six different locations.

/usr/local/lib/cmake/ABC/FindABC.cmake
/usr/local/share/cmake/ABC/FindABC.cmake
/usr/local/lib/ABC/FindABC.cmake
/usr/local/share/ABC/FindABC.cmake
/usr/local/lib/ABC/cmake/FindABC.cmake
/usr/local/share/ABC/cmake/FindABC.cmake

However CMakeList.txt of libXYZ cannot find it with the following error.

CMake Error at CMakeLists.txt:51 (find_package):
  By not providing "FindABC.cmake" in CMAKE_MODULE_PATH this project
  has asked CMake to find a package configuration file provided by
  "ABC", but CMake did not find one.

My cmake command was installed under /opt/local by using MacPorts on OS X. So I think it searches not /usr/local but only /opt/local.

I know that defining CMAKE_MODULE_PATH when executing cmake command solve this issue (e.g., cmake -DCMAKE_MODULE_PATH=/usr/local/lib/cmake/ABC), but I do not want to ask all users to do it every time.

My questions are

Q1. Where should I install FindABC.cmake during the libABC installation process?

Q2. How do I properly find FindABC.cmake in CMakeLists.txt of libXYZ without hard-coding CMAKE_MODULE_PATH in it?

Akira Okumura
  • 1,816
  • 2
  • 20
  • 41
  • `FindXXX.cmake` files are provided either by CMake itself or by project, *which uses `find_package(XXX)` call*. If your ABC project want to be searched, it should install ABCConfig.cmake file instead. See description of [cmake-packaging](https://cmake.org/cmake/help/git-master/manual/cmake-packages.7.html) about creation such `*Config.cmake` files. – Tsyvarev Sep 30 '15 at 23:59
  • @ruso: The answer does not help here as it does not describe where to install module (findxxx.cmake) files. – usr1234567 Oct 04 '15 at 20:02
  • Possible duplicate of [How to install your custom CMake-Find module](http://stackoverflow.com/questions/10765885/how-to-install-your-custom-cmake-find-module) – usr1234567 Oct 05 '15 at 07:17
  • @ruslo: Yeah, the CMake guys which that every projects ships a config file. But in reality, there are many third party FindXXX.cmake modules. – usr1234567 Oct 05 '15 at 14:50
  • Thank you all. I added `install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/MyProjectConfig.cmake" DESTINATION lib/cmake/MyProject COMPONENT devel)` in my `CMakeLists.txt` – Akira Okumura Oct 05 '15 at 22:10

0 Answers0