From 9b3735c05fa2aabd1e2bf90a0b7e91233f2b2dc5 Mon Sep 17 00:00:00 2001 From: friendlyanon Date: Mon, 28 Mar 2022 01:37:01 +0200 Subject: [PATCH] Honor `OPTIONAL_COMPONENTS` when finding SFML The "main" component is not available everywhere, but passing it to the find_package(SFML) call via the OPTIONAL_COMPONENTS still fails the call on platforms like Linux. This commit enables SFML to be used the same in a cross-platform fashion without forcing consumers to put custom logic around importing SFML. Example that works with this commit, but break before: find_package(SFML REQUIRED graphics OPTIONAL_COMPONENTS main) target_link_libraries(dummy PRIVATE SFML::graphics) if(SFML_MAIN_FOUND) target_link_libraries(dummy PRIVATE SFML::main) endif() --- cmake/SFMLConfig.cmake.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/SFMLConfig.cmake.in b/cmake/SFMLConfig.cmake.in index cb4fdc82c..741161cc2 100644 --- a/cmake/SFMLConfig.cmake.in +++ b/cmake/SFMLConfig.cmake.in @@ -130,11 +130,11 @@ if (EXISTS "${targets_config_file}") foreach (component ${SFML_FIND_COMPONENTS}) string(TOUPPER "${component}" UPPER_COMPONENT) + set(SFML_${UPPER_COMPONENT}_FOUND FALSE) if (TARGET SFML::${component}) set(SFML_${UPPER_COMPONENT}_FOUND TRUE) - else() + elseif(SFML_FIND_REQUIRED_${component}) set(FIND_SFML_ERROR "Found SFML but requested component '${component}' is missing in the config defined in ${SFML_DIR}.") - set(SFML_${UPPER_COMPONENT}_FOUND FALSE) set(SFML_FOUND FALSE) endif() endforeach()