【问题标题】:CMake - finding external librariesCMake - 查找外部库
【发布时间】:2013-11-26 20:12:43
【问题描述】:

我有一个具有以下结构的项目:

projectName-master/
                   data/
                   source/
                   thirdparty/ (here is placed FindSFML.cmake file)
                   .gitignore 
                   CMakeLists.txt
                   README.md
                   SOURCES.md
                   TODO.md

我使用 CMake 2.8.11.1 (cmake-gui) 生成 Visual Studio sln 文件。路径是这样设置的:

  • 源代码在哪里:E:/projectName-master
  • 在哪里构建二进制文件:E:/projectName-master/source(1.我可以选择其他目录还是应该设置为包含源文件的目录:h,cpp等?)

接下来我选择:Configure -> “Specify the generator for this project = Visual Studio 11, Use default native compilers” -> Finish

然后我得到一个信息:配置过程出错,项目文件可能无效

CMake Gui 包含以下信息:

名称: CMAKE_INSTALL_PREFIX C:/Program Files(x86)/projectName 名称: SFML_INCLUDE_DIR SFML_INCLUDE_DIR-NOTFOUND

CMake Error at thirdparty/FindSFML.cmake:165 (message):
  Could NOT find SFML (missing: SFML_SYSTEM_LIBRARY SFML_WINDOW_LIBRARY
  SFML_AUDIO_LIBRARY SFML_NETWORK_LIBRARY SFML_GRAPHICS_LIBRARY)
Call Stack (most recent call first):
  CMakeLists.txt:63 (find_package)

我下载了 SFML 并设置了 SFML_INCLUDE_DIR(在 CMake Gui 中):C:/OpenGL/SFML-2.1/include/SFML 但我仍然收到该错误。 2.如何解决? lib 文件和 dll 的呢?

编辑1: 我从official site下载了SFML

从项目中查找SFML.cmake 不包含任何SFML_ROOT 条目,但SFML_INCLUDE_DIR 看起来像这样:

# find the SFML include directory
find_path(SFML_INCLUDE_DIR SFML/Config.hpp
      PATH_SUFFIXES include
      PATHS
      ${SFMLDIR}
      $ENV{SFMLDIR}
      ~/Library/Frameworks
      /Library/Frameworks
      /usr/local/
      /usr/
      /sw          # Fink
      /opt/local/  # DarwinPorts
      /opt/csw/    # Blastwave
      /opt/)

那么如何设置 SFML_ROOT 呢?我需要在该文件中添加一些条目(记录)吗?它会是什么样子?

Edit2:新 FindSFML.cmake 的一部分,带有 SFML (C:/OpenGL/SFML-2.1/) 的路径

find_path(SFML_INCLUDE_DIR SFML/Config.hpp
      PATH_SUFFIXES include
      PATHS
      ${SFML_ROOT}
      $ENV{SFML_ROOT}
      C:/OpenGL/SFML-2.1/
      ~/Library/Frameworks
      /Library/Frameworks
      /usr/local/
      /usr/
      /sw          # Fink
      /opt/local/  # DarwinPorts
      /opt/csw/    # Blastwave
      /opt/)

【问题讨论】:

    标签: c++ cmake


    【解决方案1】:

    首先,SFML 不是 CMake 标准模块,所以最好提供源链接。我希望你的意思是this product。看看FindSFML 文件:

    # If SFML is not installed in a standard path, you can use the SFML_ROOT CMake (or environment) variable
    # to tell CMake where SFML is.
    

    所以您可能只需要设置SFML_ROOT 变量,而不是SFML_INCLUDE_DIR

    lib 文件和 dll 呢?

    我认为这可能会有所帮助:

    # By default, the dynamic libraries of SFML will be found. To find the static ones instead,
    # you must set the SFML_STATIC_LIBRARIES variable to TRUE before calling find_package(SFML ...).
    

    我可以选择其他目录还是应该设置为包含源文件的目录:h,cpp等。

    强烈推荐use a separate directory

    【讨论】:

    • 我在项目位置添加了一个新的 FindSFML.cmake,其中包含 SFML 的路径 - Edit2。你是这个意思吗?
    • 但是我必须如何以及在哪里定义 SFML_ROOT ?我使用 CMake-Gui。
    • @Irbis 只需点击Add Entry 按钮。将Type 设置为PATH,将Name 设置为SFML_ROOT,将Value 设置为目录路径
    猜你喜欢
    • 2017-11-25
    • 1970-01-01
    • 1970-01-01
    • 2013-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-14
    • 2021-09-17
    相关资源
    最近更新 更多