Don't add SFML:: namespace to external targets

The SFML target export set includes a number of external targets
which are not owned by the project itself. This includes targets
like Freetype and OpenGL. By specifying a namespace for the export
set, a SFML:: namespace was prepended to all targets. This is not
a problem when using shared libraries but when building and using
static libraries caused a problem where CMake was attempting and
failing to find targets with names like SFML::Freetype or
SFML::OpenGL which did not exist.

Luckily CMake allows you put namespaces in the EXPORT_NAME target
property so now we can just add the SFML:: namespace in the macro
which creates SFML targets and remove the `NAMESPACE SFML::` line
which was adding namespaces to all targets.
This commit is contained in:
Chris Thrasher 2022-01-27 13:22:59 -07:00 committed by Lukas Dürrenberger
parent 7c80f302e4
commit 8f1955af17

View File

@ -81,7 +81,7 @@ macro(sfml_add_library module)
set_target_properties(${target} PROPERTIES DEFINE_SYMBOL ${NAME_UPPER}_EXPORTS) set_target_properties(${target} PROPERTIES DEFINE_SYMBOL ${NAME_UPPER}_EXPORTS)
# define the export name of the module # define the export name of the module
set_target_properties(${target} PROPERTIES EXPORT_NAME ${module}) set_target_properties(${target} PROPERTIES EXPORT_NAME SFML::${module})
# adjust the output file prefix/suffix to match our conventions # adjust the output file prefix/suffix to match our conventions
if(BUILD_SHARED_LIBS AND NOT THIS_STATIC) if(BUILD_SHARED_LIBS AND NOT THIS_STATIC)
@ -452,7 +452,6 @@ function(sfml_export_targets)
install(EXPORT SFMLConfigExport install(EXPORT SFMLConfigExport
FILE ${targets_config_filename} FILE ${targets_config_filename}
NAMESPACE SFML::
DESTINATION ${config_package_location}) DESTINATION ${config_package_location})
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/SFMLConfig.cmake" install(FILES "${CMAKE_CURRENT_BINARY_DIR}/SFMLConfig.cmake"