2

This is my first time trying to do this, so this might be a bit of a newbie question. I'm running ubuntu/linux, and I have a C++ library called wmrde that I'm trying to make "installable" using CMake. So I have a CMakeLists.txt file set up so that if you run the cmake command from the command line, followed by "make install" it installs all of the library files to /usr/local/lib/wmrde/, installs the header files to /usr/local/include/wmrde/, and installs a wmrdeConfig.cmake file in /usr/local/lib/cmake/wmrde/. That much is all working correctly.

Now I have a separate project and want to be able to link against this wmrde library. So I put FIND_PACKAGE(wmrde) in the CMakeLists.txt file for this other project. But when I try to build it, I get an error:

Could not find a package configuration file provided by "wmrde" with any of the following names:

wmrdeConfig.cmake
wmrde-config.cmake

I checked, and the files /usr/local/lib/cmake/wmrde/wmrdeConfig.cmake and /usr/local/lib/cmake/wmrde/wmrdeConfigVersion.cmake both exist, so I'm not sure why this FIND_PACKAGE statement can't find it.

So my question is, am I missing a step in the installation? I'd prefer it if I could find a solution that only involves modifying this wmrde library, since I'll be sharing this library and want other people to be able to easily include it in their own projects.

This is the entirety of the CMakeLists.txt file for my library-- it's pretty simple:

# Setup
cmake_minimum_required(VERSION 2.8.11)
project(wmrde)
set(WMRDE_VERSION 1.0.0)

INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
set(CMAKE_CXX_STANDARD 11)
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib/wmrde")

# Building the library
add_library(wmrde SHARED
  wmrde.cpp
)

# Installation stuff
FILE(GLOB headerFiles "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
INSTALL(FILES ${headerFiles} DESTINATION "${CMAKE_INSTALL_PREFIX}/include/wmrde")

INSTALL(TARGETS wmrde LIBRARY DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/wmrde")

SET(INSTALL_CMAKE_DIR "${CMAKE_INSTALL_PREFIX}/lib/cmake/wmrde")

CONFIGURE_FILE("wmrdeConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/wmrdeConfig.cmake")
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/wmrdeConfig.cmake DESTINATION ${INSTALL_CMAKE_DIR})

CONFIGURE_FILE(wmrdeConfigVersion.cmake.in "${PROJECT_BINARY_DIR}/wmrdeConfigVersion.cmake")
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/wmrdeConfigVersion.cmake DESTINATION ${INSTALL_CMAKE_DIR})
Eric Foote
  • 76
  • 5
  • Does this answer your question? [CMake find\_package not finding Find.cmake](https://stackoverflow.com/questions/33251390/cmake-find-package-not-finding-findpackage-cmake) – Kevin Feb 19 '20 at 17:01
  • Not quite-- I think it'd work if I was the only one using it, but I'll eventually be delivering this library to a client, and I'm trying to follow the rule from the find_package documentation: "Package maintainers providing CMake package configuration files are encouraged to name and install them such that the procedure outlined below will find them without requiring use of additional options." – Eric Foote Feb 20 '20 at 14:43
  • In the `find_package()` documentation, did you read through the [search procedure](https://cmake.org/cmake/help/latest/command/find_package.html#search-procedure) for *how* this command searches your system for the `wmrdeConfig.cmake` file? See the ordered search steps 1 through 9; it would appear that none of these cases allowed CMake to find the package on your machine, which is why you need to manually specify the path somehow. For what it's worth, it seems CMake looks for the .config file in `wmrde/cmake`, not `cmake/wmrde`. – Kevin Feb 20 '20 at 15:56

0 Answers0