CMake - finding external libraries

2019-06-04 22:36发布

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

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

  • where is the source code: E:/projectName-master
  • where to build the binaries: E:/projectName-master/source (1.Can I choose other directory or it should be set to the directory which contains source files: h, cpp etc. ?)

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 contains following informations:

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)

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: I downloaded SFML from the official site

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/)

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

Edit2: 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/)

标签: c++ cmake
1条回答
戒情不戒烟
2楼-- · 2019-06-04 23:29

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.

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

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 ...).

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

It is highly recommended to use a separate directory.

查看更多
登录 后发表回答