diff --git a/bindings/c/include/SFML/Config.h b/bindings/c/include/SFML/Config.h index db3aac78c..cfc31a9db 100644 --- a/bindings/c/include/SFML/Config.h +++ b/bindings/c/include/SFML/Config.h @@ -26,6 +26,13 @@ #define SFML_CONFIG_H +//////////////////////////////////////////////////////////// +// Define the CSFML version +//////////////////////////////////////////////////////////// +#define CSFML_VERSION_MAJOR 2 +#define CSFML_VERSION_MINOR 0 + + //////////////////////////////////////////////////////////// // Identify the operating system //////////////////////////////////////////////////////////// diff --git a/cmake/Modules/FindSFML.cmake b/cmake/Modules/FindSFML.cmake index c2d150ee5..4b1e6e60e 100644 --- a/cmake/Modules/FindSFML.cmake +++ b/cmake/Modules/FindSFML.cmake @@ -9,6 +9,9 @@ # # By default, the dynamic libraries of SFML will be found. To find the static ones instead, # you must set the SFML_STATIC_LIBRARIES variable to TRUE before calling find_package(SFML ...). +# +# If SFML is not installed in a standard path, you can use the SFMLDIR CMake variable +# to tell CMake where SFML is. # deduce the libraries suffix from the options set(FIND_SFML_LIB_SUFFIX "") @@ -30,6 +33,32 @@ find_path(SFML_INCLUDE_DIR SFML/Config.hpp /opt/ ${SFMLDIR}) +# check the version number +set(SFML_VERSION_OK TRUE) +if(SFML_FIND_VERSION AND SFML_INCLUDE_DIR) + # extract the major and minor version numbers from SFML/Config.hpp + FILE(READ "${SFML_INCLUDE_DIR}/SFML/Config.hpp" SFML_CONFIG_HPP_CONTENTS) + STRING(REGEX REPLACE ".*#define SFML_VERSION_MAJOR ([0-9]+).*" "\\1" SFML_VERSION_MAJOR "${SFML_CONFIG_HPP_CONTENTS}") + STRING(REGEX REPLACE ".*#define SFML_VERSION_MINOR ([0-9]+).*" "\\1" SFML_VERSION_MINOR "${SFML_CONFIG_HPP_CONTENTS}") + math(EXPR SFML_REQUESTED_VERSION "${SFML_FIND_VERSION_MAJOR} * 10 + ${SFML_FIND_VERSION_MINOR}") + + # if we could extract them, compare with the requested version number + if (SFML_VERSION_MAJOR) + # transform version numbers to an integer + math(EXPR SFML_VERSION "${SFML_VERSION_MAJOR} * 10 + ${SFML_VERSION_MINOR}") + + # compare them + if(SFML_VERSION LESS SFML_REQUESTED_VERSION) + set(SFML_VERSION_OK FALSE) + endif() + else() + # SFML version is < 2.0 + if (SFML_REQUESTED_VERSION GREATER 19) + set(SFML_VERSION_OK FALSE) + endif() + endif() +endif() + # find the requested components set(FIND_SFML_LIB_PATHS ~/Library/Frameworks /Library/Frameworks @@ -62,7 +91,12 @@ foreach(FIND_SFML_COMPONENT ${SFML_FIND_COMPONENTS}) set(SFML_LIBRARIES ${SFML_LIBRARIES} ${${FIND_SFML_COMPONENT_VAR}}) endforeach() -# handle the QUIETLY and REQUIRED arguments and set SFML_FOUND to TRUE if all listed variables are TRUE -INCLUDE(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(SFML DEFAULT_MSG SFML_INCLUDE_DIR ${SFML_LIBRARIES_NAMES}) -MARK_AS_ADVANCED(SFML_INCLUDE_DIR ${SFML_LIBRARIES_NAMES}) +if(SFML_FIND_REQUIRED AND NOT SFML_VERSION_OK) + message(SEND_ERROR "Bad SFML version (requested: ${SFML_FIND_VERSION}, found: ${SFML_VERSION_MAJOR}.${SFML_VERSION_MINOR})") + set(SFML_FOUND FALSE) +else() + # handle the QUIETLY and REQUIRED arguments and set SFML_FOUND to TRUE if all listed variables are TRUE + INCLUDE(FindPackageHandleStandardArgs) + FIND_PACKAGE_HANDLE_STANDARD_ARGS(SFML DEFAULT_MSG SFML_INCLUDE_DIR ${SFML_LIBRARIES_NAMES}) + MARK_AS_ADVANCED(SFML_INCLUDE_DIR ${SFML_LIBRARIES_NAMES}) +endif() diff --git a/include/SFML/Config.hpp b/include/SFML/Config.hpp index 3d2ed3d18..5b628a776 100644 --- a/include/SFML/Config.hpp +++ b/include/SFML/Config.hpp @@ -26,6 +26,13 @@ #define SFML_CONFIG_HPP +//////////////////////////////////////////////////////////// +// Define the SFML version +//////////////////////////////////////////////////////////// +#define SFML_VERSION_MAJOR 2 +#define SFML_VERSION_MINOR 0 + + //////////////////////////////////////////////////////////// // Identify the operating system ////////////////////////////////////////////////////////////