mrAndersen
mrAndersen

Reputation: 85

Building SDL2_image alongside SDL2 (and similar cases)

I have the following conditions:

  1. I am using SDL2 (sources) as dependency directly from github mirror by using git submodules
  2. Also i am using SDL2_image (sources) as similar dependency
  3. My cmake project includes both deps with add_subdirectory

Problem here is that SDL2_image is trying to find SDL2 with find_package, but as i mentioned i am building SDL2 alongside with my project, so find_package fails to find it in the system. After that i am setting SDL2_DIR pointing to the correct directory, but SDL2Config.cmake inside one of the most popular unofficial repos are just including invalid file and thus breaks all project.

Question is. How i can nicely solve this issue? I have all my deps built from sources alongside the project and it works nice. Of course i can build SDL2_image and include binaries separately, but this is not a nice solution in my opinion.

Upvotes: 3

Views: 393

Answers (1)

Botje
Botje

Reputation: 31020

Create a FindSDL2.cmake with the following:

add_library(SDL2::SDL2 ALIAS SDL2)

Make sure find_package sees this file first by adding the path to it to CMAKE_MODULE_PATH or CMAKE_PREFIX_PATH.

Upvotes: 1

Related Questions