Suggest fix when incorrect library type is found by find_package

This is what it currently looks like when find_package(SFML) fails
due to locating the incorrect library type:

    CMake Error at <path>/<to>/lib/cmake/SFML/SFMLConfig.cmake:182 (message):
      Requested SFML configuration (Shared) was not found
    Call Stack (most recent call first):
      CMakeLists.txt:7 (find_package)

    CMake Error at CMakeLists.txt:7 (find_package):
      Found package configuration file:

        <path>/<to>/lib/cmake/SFML/SFMLConfig.cmake

      but it set SFML_FOUND to FALSE so package "SFML" is considered to be NOT
      FOUND.

After this change the "Requested SFML configuration" line is followed by either

    Set SFML_STATIC_LIBRARIES to ON for static libraries

or

    Set SFML_STATIC_LIBRARIES to OFF for shared libraries

depending on the value of SFML_STATIC_LIBRARIES. This should help clear up a
common source of confusion when users build SFML from source. The library
follows CMake convention of building static libraries by default but our
config module assumes shared libraries by default so those who build SFML
from source are prone to run into this error.
This commit is contained in:
Chris Thrasher 2024-12-29 20:36:50 -06:00 committed by Lukas Dürrenberger
parent b56604c940
commit dfc9b83fe4

View File

@ -169,6 +169,11 @@ foreach(component ${FIND_SFML_COMPONENTS_SORTED})
endif()
else()
set(FIND_SFML_ERROR "Requested SFML configuration (${config_name}) was not found")
if(config_name STREQUAL "Shared")
string(APPEND FIND_SFML_ERROR "\nSet SFML_STATIC_LIBRARIES to ON for static libraries")
elseif(config_name STREQUAL "Static")
string(APPEND FIND_SFML_ERROR "\nSet SFML_STATIC_LIBRARIES to OFF for shared libraries")
endif()
set(SFML_${UPPER_COMPONENT}_FOUND OFF)
set(SFML_FOUND OFF)
endif()