简体   繁体   English

与 SDL2 一起构建 SDL2_image(和类似情况)

[英]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我通过使用 git 子模块直接从 github 镜像使用 SDL2(源)作为依赖项
  2. Also i am using SDL2_image (sources) as similar dependency我也使用 SDL2_image (sources) 作为类似的依赖
  3. My cmake project includes both deps with add_subdirectory我的 cmake 项目包括两个带有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.这里的问题是 SDL2_image 正在尝试使用find_package查找 SDL2,但正如我所提到的,我正在与我的项目一起构建 SDL2,因此find_package无法在系统中找到它。 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.之后,我将 SDL2_DIR 设置为指向正确的目录,但是在最流行的非官方存储库之一中的SDL2Config.cmake仅包含无效文件,因此会破坏所有项目。

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.当然,我可以单独构建 SDL2_image 并包含二进制文件,但我认为这不是一个好的解决方案。

Create a FindSDL2.cmake with the following:使用以下内容创建FindSDL2.cmake

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 .通过将路径添加到CMAKE_MODULE_PATHCMAKE_PREFIX_PATH来确保find_package看到这个文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM