Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: FindSFML.cmake use HINTS instead of/additional to PATHS  (Read 2862 times)

0 Members and 1 Guest are viewing this topic.

Robert42

  • Newbie
  • *
  • Posts: 31
    • View Profile
FindSFML.cmake use HINTS instead of/additional to PATHS
« on: November 22, 2015, 11:21:58 pm »
The current implementation of FindSFML.cmake is using the cmake command find_path together with the PATHS argument.
My Request is to use HITNS additional to PATHS

Story:
I am using sfml for two projects. one is using sfml version 2.1 from the ubuntu packages. I want to keep working with this version (in order not to force the whole team to install sfml manually)
For another project I started using sfgui, which has sfml 2.3 as prerequirement.

So I downloaded the compiled version of SFML. (I am using the precompiled version, as I am planning to also work on a computer on my university, where I don't have root privileges, so I don't want to need to install the dev versions of all dependencies)

Problem:
The current FindSFML.cmake script finds always the sfml version installed with the ubuntu packages, although I am using SFML_ROOT to override the path.

The Problem is, that the PATHS attribute will cause cmake to look first at the default locations (I think it is CMAKE_MODULE_PATH, but I am not 100% sure), bevore checking the paths of the PATHS attribute. I've modified the FindSFML.cmake script to use HINTS, they are checked before the CMAKE_MODULE PATH. SO instead of

# define the list of search paths for headers and libraries
set(FIND_SFML_PATHS
    ${SFML_ROOT}
    $ENV{SFML_ROOT}
    ~/Library/Frameworks
    /Library/Frameworks
    /usr/local
    /usr
    /sw
    /opt/local
    /opt/csw
    /opt)

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

I have now

# define the list of search paths for headers and libraries
set(FIND_SFML_PATHS
    ${SFML_ROOT}
    $ENV{SFML_ROOT}
    ~/Library/Frameworks
    /Library/Frameworks
    /usr/local
    /usr
    /sw
    /opt/local
    /opt/csw
    /opt)

 #################### ADDED
set(FIND_SFML_HINTS
    ${SFML_ROOT}
    $ENV{SFML_ROOT}
  )

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

What now?
This fix is working perfectly for me, so I wanted to share it with you :)
I you thik that's usefull, use it as you whish

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11027
    • View Profile
    • development blog
    • Email
Re: FindSFML.cmake use HINTS instead of/additional to PATHS
« Reply #1 on: November 23, 2015, 01:57:43 am »
When do you define SFML_ROOT? Because given the order in FIND_SFML_PATHS it should first pick the libraries that are in SFML_ROOT.
It could be however that if you set SFML_ROOT after the FindSFML.cmake script ran, that it won't change the cached paths to your /usr/local or similar directory. So I think it's more a limitation of usage.

But I guess it's something to consider.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything