SFML / SFML-Game-Development-Book

Full and up-to-date source code of the chapters of the "SFML Game Development" book

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CMake script and SFML_ROOT

cschreib opened this issue · comments

The CMake script provides the SFML_ROOT variable to provide the location of SFML when installed outside of the system's default locations. However, find_path() is implemented to look in system default location first, and looks in the custom paths provided in PATHS only if no match is found in the system default. This means that if the system contains a version of SFML but the user has a (supposedly newer) version manually installed somewhere else that they want to use instead, the (older) system version will always be picked first.

To fix this, I would suggest specifying SFML_ROOT in HINTS instead of PATHS. Indeed, contrary to PATHS, HINTS are looked up before the system locations.

# find the SFML include directory
find_path(SFML_INCLUDE_DIR SFML/Config.hpp
          PATH_SUFFIXES include
          HINTS ${SFML_ROOT} $ENV{SFML_ROOT}
          PATHS ${FIND_SFML_PATHS})

The same should then be done for the find_library() calls, and SFML_ROOT should be removed from FIND_SFML_PATHS.

Did you check under which repository you've opened your ticket? 😉

The CMake system has been changed from SFML 2.5 and we're now using CMake config files and thus SFML_ROOT isn't relevant anymore.

I actually did. This repository (and the CMake find script) are the first results that come out from a Google search of "findsfml". I didn't know that SFML recently migrated from the Find script to the Config script, so I assumed this repository was the only official source of the Find script. It did strike me as weird, but nonetheless plausible!

I must say I am not used to the Config script aspects of CMake yet, and since the Find script just works I'm not sure I want to dig into that just yet. I expect a significant number of people are in the same situation.