user10397729
user10397729

Reputation: 23

CMake find_package() doesn't respect CMAKE_MODULE_PATH

I'm having trouble with detection of a package (glfw) in CMake. I cannot install the library in a standard location due to no root privileges, so I installed it in .local instead:

$ ls ~/.local/lib/cmake/glfw3/glfw3Config.cmake
/home/emil/.local/lib/cmake/glfw3/glfw3Config.cmake

My CMakeLists.txt consists of

cmake_minimum_required(VERSION 3.10.0)
project(test VERSION 1.0 LANGUAGES C CXX)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "$ENV{HOME}/.local")
message("CMAKE_MODULE_PATH: ${CMAKE_MODULE_PATH}")
find_package(glfw3 3.2 REQUIRED)

Which I execute with the flag below to ensure search directory output:

$ cmake -DCMAKE_FIND_DEBUG_MODE=ON ..

This outputs:

CMAKE_MODULE_PATH: /home/emil/.local
Checking prefix [/]
Checking file [/glfw3Config.cmake]
Checking file [/glfw3-config.cmake]
Checking prefix [/usr/]
Checking file [/usr/glfw3Config.cmake]
Checking file [/usr/glfw3-config.cmake]
Checking prefix [/opt/thinlinc/]
Checking file [/opt/thinlinc/glfw3Config.cmake]
Checking file [/opt/thinlinc/glfw3-config.cmake]
Checking prefix [/usr/local/]
Checking file [/usr/local/glfw3Config.cmake]
Checking file [/usr/local/glfw3-config.cmake]
Checking prefix [/usr/bin/X11/]
Checking file [/usr/bin/X11/glfw3Config.cmake]
Checking file [/usr/bin/X11/glfw3-config.cmake]
Checking file [/usr/bin/X11/cmake/glfw3Config.cmake]
Checking file [/usr/bin/X11/cmake/glfw3-config.cmake]
Checking prefix [/snap/]
Checking file [/snap/glfw3Config.cmake]
Checking file [/snap/glfw3-config.cmake]
Checking prefix [/opt/puppetlabs/]
Checking file [/opt/puppetlabs/glfw3Config.cmake]
Checking file [/opt/puppetlabs/glfw3-config.cmake]
Checking prefix [/home/emil/]
Checking file [/home/emil/glfw3Config.cmake]
Checking file [/home/emil/glfw3-config.cmake]
Checking prefix [/usr/X11R6/]
Checking prefix [/usr/pkg/]
Checking prefix [/opt/]
Checking file [/opt/glfw3Config.cmake]
Checking file [/opt/glfw3-config.cmake]
CMake Error at CMakeLists.txt:13 (find_package):
  By not providing "Findglfw3.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "glfw3", but
  CMake did not find one.

So it seems like CMake searches in a lot of places, including my home directory, but not in ~/.local. I'm actually not sure why. I think CMAKE_MODULE_PATH is supposed to add search directories. On my other machine it looks there and finds it when running the same script. The erroneous machine runs Ubuntu MATE 18.04 and the working one Ubuntu 18.04.

CMake version is as below.

$ cmake --version
cmake version 3.10.2

I understand that I could just move the files to my home directory, but I don't want to do that.

Upvotes: 2

Views: 668

Answers (1)

Tsyvarev
Tsyvarev

Reputation: 66118

Variable CMAKE_MODULE_PATH helps only in locating FindXXX.cmake scripts.

For locate XXXConfig.cmake script set CMAKE_PREFIX_PATH variable. (Or some other variable used by find_package in search algorithm).

Upvotes: 4

Related Questions