From dfc9b83fe45b6cb8e55ab39e94816b7ed4bee479 Mon Sep 17 00:00:00 2001 From: Chris Thrasher Date: Sun, 29 Dec 2024 20:36:50 -0600 Subject: [PATCH] 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 //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: //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. --- cmake/SFMLConfig.cmake.in | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cmake/SFMLConfig.cmake.in b/cmake/SFMLConfig.cmake.in index 855f8a273..5d5b2f4db 100644 --- a/cmake/SFMLConfig.cmake.in +++ b/cmake/SFMLConfig.cmake.in @@ -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()