CMake-查找外部库 [英] CMake - finding external libraries

查看:106
本文介绍了CMake-查找外部库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个结构如下的项目:

I have a project with the following structure:

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文件。路径是这样设置的:

I use CMake 2.8.11.1 (cmake-gui) to generate visual studio sln file. Paths are set this way:


  • 源代码在哪里:E:/ projectName-master

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

下一步,我选择:配置->指定该项目的生成器= Visual Studio 11,使用默认的本机编译器->完成

Next I choose: Configure -> "Specify the generator for this project = Visual Studio 11, Use default native compilers" -> Finish

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

Then I get an info: Error in configuration process, project files may be invalid

CMake Gui包含以下信息:

CMake Gui contains following informations:

名称: CMAKE_INSTALL_PREFIX C:/程序文件(x86)/项目名称
名称: SFML_INCLUDE_DIR SFML_INCLUDE_DIR-NOTFOUND

Name: CMAKE_INSTALL_PREFIX Value C:/Program Files(x86)/projectName Name: SFML_INCLUDE_DIR Value 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呢?

I downloaded SFML and set SFML_INCLUDE_DIR (in CMake Gui): C:/OpenGL/SFML-2.1/include/SFML but I still get that error. 2. How to fix that ? What about lib files and dll's ?

Edit1:
我从官方站点

该项目中的FindSFML.cmake不包含任何SFML_ROOT条目,但SFML_INCLUDE_DIR看起来像这样:

FindSFML.cmake from the project doesn't contain any SFML_ROOT entry, but SFML_INCLUDE_DIR looks like this:

# 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呢?我需要向该文件添加一些条目(记录)吗?会是什么样子?

So how to set SFML_ROOT ? Do I need to add some entries (records) to that file ? How it will look like ?

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

A part of the new FindSFML.cmake with a path to 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/)


推荐答案

首先, SFML 是不是CMake标准模块,因此最好提供到源的链接。希望您的意思是此产品。看看 FindSFML 文件:

First of all, SFML is not CMake standard module, so it would be nice to provide link to sources. I hope you mean this product. Take a look at the FindSFML file:

# 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

So you probably simply need to set SFML_ROOT variable, but not SFML_INCLUDE_DIR.


lib文件和dll呢?

What about lib files and dll's?

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

I think this may be helpful:

# 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等。

Can I choose other directory or it should be set to the directory which contains source files: h, cpp etc.

强烈建议使用单独的目录

这篇关于CMake-查找外部库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆