SFML/cmake/Config.cmake

79 lines
3.2 KiB
CMake
Raw Normal View History

# detect the OS
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
set(SFML_OS_WINDOWS 1)
# detect the architecture (note: this test won't work for cross-compilation)
include(CheckTypeSize)
check_type_size(void* SIZEOF_VOID_PTR)
2012-03-31 02:53:16 +08:00
if("${SIZEOF_VOID_PTR}" STREQUAL "4")
set(ARCH_32BITS 1)
2012-03-31 02:53:16 +08:00
elseif("${SIZEOF_VOID_PTR}" STREQUAL "8")
set(ARCH_64BITS 1)
else()
message(FATAL_ERROR "Unsupported architecture")
return()
endif()
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set(SFML_OS_LINUX 1)
2011-09-14 23:58:51 +08:00
elseif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
set(SFML_OS_FREEBSD 1)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(SFML_OS_MACOSX 1)
2011-09-14 23:58:51 +08:00
# detect OS X version. (use '/usr/bin/sw_vers -productVersion' to extract V from '10.V.x'.)
EXEC_PROGRAM(/usr/bin/sw_vers ARGS -productVersion OUTPUT_VARIABLE MACOSX_VERSION_RAW)
STRING(REGEX REPLACE "10\\.([0-9]).*" "\\1" MACOSX_VERSION "${MACOSX_VERSION_RAW}")
if(${MACOSX_VERSION} LESS 7)
message(FATAL_ERROR "Unsupported version of OS X : ${MACOSX_VERSION_RAW}")
2011-09-14 23:58:51 +08:00
return()
endif()
else()
message(FATAL_ERROR "Unsupported operating system")
return()
endif()
# detect the compiler and its version
2011-12-29 05:20:15 +08:00
# Note: on some platforms (OS X), CMAKE_COMPILER_IS_GNUCXX is true
# even when CLANG is used, therefore the Clang test is done first
if(CMAKE_CXX_COMPILER MATCHES ".*clang[+][+]" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
# CMAKE_CXX_COMPILER_ID is an internal CMake variable subject to change,
# but there is no other way to detect CLang at the moment
set(SFML_COMPILER_CLANG 1)
2011-12-29 05:20:15 +08:00
execute_process(COMMAND "${CMAKE_CXX_COMPILER}" "--version" OUTPUT_VARIABLE CLANG_VERSION_OUTPUT)
string(REGEX REPLACE ".*clang version ([0-9]+\\.[0-9]+).*" "\\1" SFML_CLANG_VERSION "${CLANG_VERSION_OUTPUT}")
2011-12-29 05:20:15 +08:00
elseif(CMAKE_COMPILER_IS_GNUCXX)
set(SFML_COMPILER_GCC 1)
execute_process(COMMAND "${CMAKE_CXX_COMPILER}" "-dumpversion" OUTPUT_VARIABLE GCC_VERSION_OUTPUT)
string(REGEX REPLACE "([0-9]+\\.[0-9]+).*" "\\1" SFML_GCC_VERSION "${GCC_VERSION_OUTPUT}")
execute_process(COMMAND "${CMAKE_CXX_COMPILER}" "--version" OUTPUT_VARIABLE GCC_COMPILER_VERSION)
string(REGEX MATCHALL ".*(tdm[64]*-[1-9]).*" SFML_COMPILER_GCC_TDM "${GCC_COMPILER_VERSION}")
execute_process(COMMAND "${CMAKE_CXX_COMPILER}" "-dumpmachine" OUTPUT_VARIABLE GCC_MACHINE)
string(STRIP "${GCC_MACHINE}" GCC_MACHINE)
if(${GCC_MACHINE} MATCHES ".*w64.*")
set(SFML_COMPILER_GCC_W64 1)
endif()
elseif(MSVC)
set(SFML_COMPILER_MSVC 1)
if(MSVC_VERSION EQUAL 1400)
set(SFML_MSVC_VERSION 8)
elseif(MSVC_VERSION EQUAL 1500)
set(SFML_MSVC_VERSION 9)
elseif(MSVC_VERSION EQUAL 1600)
set(SFML_MSVC_VERSION 10)
elseif(MSVC_VERSION EQUAL 1700)
set(SFML_MSVC_VERSION 11)
elseif(MSVC_VERSION EQUAL 1800)
set(SFML_MSVC_VERSION 12)
endif()
else()
message(FATAL_ERROR "Unsupported compiler")
return()
endif()
# define the install directory for miscellaneous files
if(SFML_OS_WINDOWS)
set(INSTALL_MISC_DIR .)
elseif(SFML_OS_LINUX OR SFML_OS_FREEBSD OR SFML_OS_MACOSX)
set(INSTALL_MISC_DIR share/SFML)
endif()