简体   繁体   English

无法编译获取两个依赖项且其中一个依赖于另一个的 CMake 项目,为什么?

[英]Unable to compile a CMake project which fetches two dependencies and one of them depends on the other, why?

I have the following problem.我有以下问题。 I am trying to compile a project which depends on two libraries: SFML and Thor , and the latter depends on the former.我正在尝试编译一个依赖于两个库的项目: SFMLThor ,后者依赖于前者。

In my main CMakeLists.txt I fetch these dependencies with:在我的主要CMakeLists.txt中,我通过以下方式获取这些依赖项:

...
add_subdirectory(SFML)
add_subdirectory(Thor)
...

The CMakeLists of SFML fetching is the following: SFML抓取的CMakeLists如下:

# Finding the package
find_package( SFML 2.5.1 COMPONENTS system window graphics )

# Fetching the package if not found
if( NOT SFML_FOUND )

    # Fetching the package
    include( FetchContent )

    FetchContent_Declare(
      SFML
      GIT_REPOSITORY "https://github.com/SFML/SFML"
      GIT_TAG 2.5.1
    )

    # No need to build audio and network modules
    set( SFML_BUILD_AUDIO FALSE )
    set( SFML_BUILD_NETWORK FALSE )

    # Make it available
    message( STATUS "Fetching SFML..." )
    FetchContent_MakeAvailable( SFML )
endif()

While the one of Thor fetching is this other one: Thor获取的是另一个:

# Fetching the package
include( FetchContent )

FetchContent_Declare(
  Thor
  GIT_REPOSITORY "https://github.com/Bromeon/Thor"
  GIT_TAG master # 2.0
)

# Make it available
message( STATUS "Fetching Thor..." )
FetchContent_MakeAvailable( Thor )

The problem is that when compiling I got the following error:问题是编译时出现以下错误:

CMake Error at build/_deps/thor-src/CMakeLists.txt:114 (find_package):
  By not providing "FindSFML.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "SFML", but
  CMake did not find one.

  Could not find a package configuration file provided by "SFML" (requested
  version 2.5) with any of the following names:

    SFMLConfig.cmake
    sfml-config.cmake

  Add the installation prefix of "SFML" to CMAKE_PREFIX_PATH or set
  "SFML_DIR" to a directory containing one of the above files.  If "SFML"
  provides a separate development package or SDK, be sure it has been
  installed.

Do you have any idea of what is going on?你知道发生了什么事吗? Thanks.谢谢。

To answer your question very briefly, take a look at the documentation of find_package :要非常简要地回答您的问题,请查看find_package的文档:

If the package configuration file cannot be found CMake will 
generate an error describing the problem unless the QUIET 
argument is specified. If REQUIRED is specified and the 
package is not found a fatal error is generated and the configure 
step stops executing. If <PackageName>_DIR has been set to a directory not 
containing a configuration file CMake will ignore it and search from scratch.

From this we can deduce that all you need to do is update the find_package call as so:由此我们可以推断出您需要做的就是更新find_package调用:

find_package( SFML 2.5.1 QUIET COMPONENTS system window graphics )

Hope it helps!希望能帮助到你!

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

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