How to select an instance of SDL2 if multiple versions are installed?

Hello all,

I have the following problem:
On some systems (for example Debian) older versions of SDL2 are pre-installed. Now I’d like to compile an application against a self-built newer version of SDL2 using CMake. Is there a way to do that without using some FindSDL2.cmake?

Best wishes,
Andreas

Assuming you’re using find_package. You have several ways to go about it:

  • You can pass SDL2_DIR, either as an environment variable or through the command-line (-DSDL2_DIR='/path/to/SDL2/config'), this path should point to the directory containing the SDL2Config.cmake file, not the file itself.
  • You can set CMAKE_PREFIX_PATH, either as an environment variable or through the command-line (-DCMAKE_PREFIX_PATH='/path/to/SDL2'), this path should point to the install prefix of SDL2, which contains the include and lib directories.

There are other ways to go about it detailed in the documentation linked above, just keep in mind the order CMake uses to search paths and how they may affect other people trying to compile on different systems.

Thank you very much! That solved the problem!

1 Like