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()
This commit is contained in:
friendlyanon 2022-03-28 01:37:01 +02:00 committed by Lukas Dürrenberger
parent 8f6903d008
commit 9b3735c05f

View File

@ -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()