From 076456aa91874fce82cd95f7a8ca59ed81eaca76 Mon Sep 17 00:00:00 2001 From: LaurentGom Date: Mon, 4 Oct 2010 21:16:12 +0000 Subject: [PATCH] Added a FindSFML.cmake file for CMake git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1571 4e206d99-4929-0410-ac5d-dfc041789085 --- CMakeLists.txt | 2 + cmake/Modules/FindSFML.cmake | 72 ++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 cmake/Modules/FindSFML.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c3570cc7..6fa4800e7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,6 +57,8 @@ install(DIRECTORY include DESTINATION . COMPONENT devel PATTERN ".svn" EXCLUDE) +install(FILES cmake/Modules/FindSFML.cmake + DESTINATION ${INSTALL_MISC_DIR}/cmake/Modules) install(FILES license.txt DESTINATION ${INSTALL_MISC_DIR}) if(WINDOWS) install(FILES extlibs/bin/libsndfile-1.dll DESTINATION bin) diff --git a/cmake/Modules/FindSFML.cmake b/cmake/Modules/FindSFML.cmake new file mode 100644 index 000000000..e54b95ade --- /dev/null +++ b/cmake/Modules/FindSFML.cmake @@ -0,0 +1,72 @@ +# Locate the SFML library +# +# This module defines +# SFML_FOUND, if false, do not try to link to SFML +# SFML_XXX_LIBRARY library corresponding to the XXX component +# SFML_LIBRARIES, list containing all the libraries corresponding to the requested components +# SFML_INCLUDE_DIR, where to find SFML/Config.hpp +# +# To select a particular debug/release/static/dynamic variant of the SFML libraries, +# you must set these variables before calling find_package(SFML ...): +# - SFML_DEBUG_LIBRARIES: 1 for debug, 0 for release +# - SFML_STATIC_LIBRARIES: 1 for static, 0 for dynamic +# If not specified, both are set to 0 (release dynamic) + +# deduce the SFML libraries prefix from the major version number +set(FIND_SFML_LIB_PREFIX "sfml-") +if(${SFML_FIND_VERSION_MAJOR} GREATER 1) + set(FIND_SFML_LIB_PREFIX "sfml${SFML_FIND_VERSION_MAJOR}-") +endif() + +# deduce the libraries suffix from the options +set(FIND_SFML_LIB_SUFFIX "") +if(SFML_STATIC_LIBRARIES) + set(FIND_SFML_LIB_SUFFIX "${FIND_SFML_LIB_SUFFIX}-s") +endif() +if(SFML_DEBUG_LIBRARIES) + set(FIND_SFML_LIB_SUFFIX "${FIND_SFML_LIB_SUFFIX}-d") +endif() + +# find the SFML include directory +find_path(SFML_INCLUDE_DIR SFML/Config.hpp + PATH_SUFFIXES include + PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local/ + /usr/ + /sw # Fink + /opt/local/ # DarwinPorts + /opt/csw/ # Blastwave + /opt/ + ${SFMLDIR}) + +# find the requested components +foreach(FIND_SFML_COMPONENT ${SFML_FIND_COMPONENTS}) + string(TOLOWER ${FIND_SFML_COMPONENT} FIND_SFML_COMPONENT_LOWER) + string(TOUPPER ${FIND_SFML_COMPONENT} FIND_SFML_COMPONENT_UPPER) + set(FIND_SFML_COMPONENT_VAR SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY) + set(FIND_SFML_COMPONENT_NAME ${FIND_SFML_LIB_PREFIX}${FIND_SFML_COMPONENT_LOWER}${FIND_SFML_LIB_SUFFIX}) + + find_library(${FIND_SFML_COMPONENT_VAR} + NAMES ${FIND_SFML_COMPONENT_NAME} + PATH_SUFFIXES lib64 lib + PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr + /sw + /opt/local + /opt/csw + /opt + ${SFMLDIR}) + + set(SFML_LIBRARIES_NAMES ${SFML_LIBRARIES_NAMES} ${FIND_SFML_COMPONENT_VAR}) + 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})