2

I have installed a library (SDL) with the following command:

cmake --build . --target install

I read in the documentation that installed packages are going to be registered in the CMAKE_SYSTEM_PREFIX_PATH.

But when I print out the variable it is empty.

Currently I am using Windows, and I read online that I should register the installation path in the registry, but it did not help at all.

How can I find, for example, SDL with find_package()?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ryper
  • 338
  • 3
  • 15
  • ***Currently I am using windows*** Sometimes this means you have to tell it where to look. I use batch files and environment variables that feed CMake variables to force it to pick the version that I want. Although this is partly due to me using more than 1 version of Visual Studio combined with building for 32 and 64 bit. – drescherjm Jun 04 '18 at 19:36
  • Check out CMAKE_PREFIX_PATH, e.g., https://stackoverflow.com/a/41909627/2799037 – usr1234567 Jun 04 '18 at 21:47
  • I checked out that, but it is not working as I want to. I added `SDL2 2.0.8 : T:\installed\2.0.8\CMake` TO the package registry but when I want to include the SDL2 package, it says that there is no FINDSDL2.cmake, altough in this tutorial https://github.com/Wigner-GPU-Lab/Teaching/tree/master/CMake/Lesson3_Dependecies the writer did not have a find script neither. – Ryper Jun 05 '18 at 10:13
  • I just had this exact same problem when installing and trying to use Google Benchmark on Windows - to work around it I used CMAKE_PREFIX_PATH, so the command I used was `cmake -DCMAKE_PREFIX_PATH="C:\Program Files" -G "Visual Studio 15 2017 Win64" ..` I thought it should work without but apparently not. I'm going to keep digging as CMake did install Benchmark to the right location, so it must be the default somewhere! :P – Tom Mar 01 '19 at 21:41

2 Answers2

0

Try this:

Using the get_cmake_property function the following loop will print out all CMake variables defined and their values:

get_cmake_property(_variableNames VARIABLES)
list (SORT _variableNames)
foreach (_variableName ${_variableNames})
    message(STATUS "${_variableName}=${${_variableName}}")
endforeach()

To print environment variables use CMake's command mode:

execute_process(COMMAND "${CMAKE_COMMAND}" "-E" "environment")

It prints:

-- CMAKE_SYSTEM_PREFIX_PATH=/usr/local;/usr;/;/usr;/usr/local;/usr/X11R6;/usr/pkg;/opt

(Credits to Sakra)

You can search your source tree for a file named FindSDL*.cmake then try to find this file in your CMAKE_SYSTEM_PREFIX_PATH directories.

If CMAKE_SYSTEM_PREFIX_PATH is still empty, try to locate FindSDL*.cmake in your entire computer to check whether files are being installed somewhere cmake knows or try to append this path to your CMAKE_SYSTEM_PREFIX_PATH.

You can also check this link: Using SDL2 with CMake

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
j4x
  • 3,595
  • 3
  • 33
  • 64
0

I believe the reason this wasn't working for you is because your find_package command came before your project command in your CMakeLists.txt file. If you ensure project is the first command (after cmake_minimum_required(VERSION <NUM>) then all of the CMAKE_SYSTEM_*** variables will be initialized correctly :)

I actually stumbled across this post after having the exact same problem (see my comment on the initial question). I tried the advice posted by j4x using the foreach VARIABLES command to print all the variables and serendipitously pasted it after my project command. I noticed CMAKE_SYSTEM_PREFIX_PATH was a sensible value - I then moved the code above the project command and noticed far fewer variables were printed :P CMAKE_SYSTEM_PREFIX_PATH was no where to be seen...

I hope this works for you too!

Tom
  • 1,956
  • 2
  • 18
  • 23