diff --git a/cmake/Config.cmake b/cmake/Config.cmake index 04217c6d..9b6c1c3f 100644 --- a/cmake/Config.cmake +++ b/cmake/Config.cmake @@ -37,7 +37,15 @@ else() endif() # detect the compiler and its version -if(CMAKE_COMPILER_IS_GNUCXX) +# 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(COMPILER_CLANG 1) + execute_process(COMMAND "${CMAKE_CXX_COMPILER}" "--version" OUTPUT_VARIABLE CLANG_VERSION_OUTPUT) + string(REGEX REPLACE ".*clang version ([0-9]+\\.[0-9]+).*" "\\1" CLANG_VERSION "${CLANG_VERSION_OUTPUT}") +elseif(CMAKE_COMPILER_IS_GNUCXX) set(COMPILER_GCC 1) execute_process(COMMAND "${CMAKE_CXX_COMPILER}" "-dumpversion" OUTPUT_VARIABLE GCC_VERSION_OUTPUT) string(REGEX REPLACE "([0-9]+\\.[0-9]+).*" "\\1" GCC_VERSION "${GCC_VERSION_OUTPUT}") diff --git a/cmake/Macros.cmake b/cmake/Macros.cmake index 65c6c4a5..c13ad549 100644 --- a/cmake/Macros.cmake +++ b/cmake/Macros.cmake @@ -126,19 +126,17 @@ macro(sfml_add_library target) set_target_properties(${target} PROPERTIES SOVERSION ${VERSION_MAJOR}) set_target_properties(${target} PROPERTIES VERSION ${VERSION_MAJOR}.${VERSION_MINOR}) - # for gcc 4.x on Windows, apply the STATIC_STD_LIBS option if it is enabled + # for gcc >= 4.0 on Windows, apply the STATIC_STD_LIBS option if it is enabled if(WINDOWS AND COMPILER_GCC AND STATIC_STD_LIBS) - if(${GCC_VERSION} MATCHES "4\\..*") + if(NOT GCC_VERSION VERSION_LESS "4") set_target_properties(${target} PROPERTIES LINK_FLAGS "-static-libgcc -static-libstdc++") endif() endif() - # on Unix systems with gcc 4.x, we must hide public symbols by default + # If using gcc >= 4.0 or clang >= 3.0 on a non-Windows platform, we must hide public symbols by default # (exported ones are explicitely marked) - if((LINUX OR MACOSX) AND COMPILER_GCC) - if(${GCC_VERSION} MATCHES "4\\..*") - set_target_properties(${target} PROPERTIES COMPILE_FLAGS -fvisibility=hidden) - endif() + if(NOT WINDOWS AND ((COMPILER_GCC AND NOT GCC_VERSION VERSION_LESS "4") OR (COMPILER_CLANG AND NOT CLANG_VERSION VERSION_LESS "3"))) + set_target_properties(${target} PROPERTIES COMPILE_FLAGS -fvisibility=hidden) endif() # link the target to its SFML dependencies @@ -205,9 +203,9 @@ macro(sfml_add_example target) # set the debug suffix set_target_properties(${target} PROPERTIES DEBUG_POSTFIX -d) - # for gcc 4.x on Windows, apply the STATIC_STD_LIBS option if it is enabled + # for gcc >= 4.0 on Windows, apply the STATIC_STD_LIBS option if it is enabled if(WINDOWS AND COMPILER_GCC AND STATIC_STD_LIBS) - if(${GCC_VERSION} MATCHES "4\\..*") + if(NOT GCC_VERSION VERSION_LESS "4") set_target_properties(${target} PROPERTIES LINK_FLAGS "-static-libgcc -static-libstdc++") endif() endif()