new FindClang.cmake webgl
authorkoda
Tue, 18 Jun 2013 10:03:11 +0200
branchwebgl
changeset 9246 75f430ebeb74
parent 9244 bb95e351270c
child 9248 3e8558dc285a
new FindClang.cmake
CMakeLists.txt
cmake_modules/FindClang.cmake
--- a/CMakeLists.txt	Tue Jun 18 09:48:10 2013 +0200
+++ b/CMakeLists.txt	Tue Jun 18 10:03:11 2013 +0200
@@ -54,7 +54,6 @@
 set(HEDGEWARS_PROTO_VER 46)
 set(HEDGEWARS_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
 include(${CMAKE_MODULE_PATH}/revinfo.cmake)
-set(required_clang_version 3.0)
 
 message(STATUS "Building ${HEDGEWARS_VERSION}-r${HEDGEWARS_REVISION} (${HEDGEWARS_HASH})")
 
@@ -135,12 +134,13 @@
 #build engine without freepascal
 if(${NOPASCAL})
     find_package(Clang)
-    # Check LLVM/Clang version
-    if(CLANG_VERSION VERSION_LESS required_clang_version)
-        message(FATAL_ERROR "LLVM/Clang compiler required version is ${required_clang_version} but version ${CLANG_VERSION} was found!")
-    else()
-        message(STATUS "Found CLANG: ${CLANG_EXECUTABLE} (version ${CLANG_VERSION})")
+
+    if(CLANG_VERSION VERSION_LESS "3.0")
+        message(FATAL_ERROR "LLVM/Clang compiler required version is 3.0 but version ${CLANG_VERSION} was found!")
     endif()
+
+    set(CMAKE_C_COMPILER ${CLANG_EXECUTABLE})
+    set(CMAKE_CXX_COMPILER ${CLANG_EXECUTABLE})
 endif(${NOPASCAL})
 
 
--- a/cmake_modules/FindClang.cmake	Tue Jun 18 09:48:10 2013 +0200
+++ b/cmake_modules/FindClang.cmake	Tue Jun 18 10:03:11 2013 +0200
@@ -1,21 +1,36 @@
-# Load LLVM/Clang
-if (CLANG)
-    set(CLANG_EXECUTABLE ${CLANG})
-else()
-    find_program(CLANG_EXECUTABLE
+# - Try to find the Clang/LLVM executable
+# Once done this will define
+#
+#  CLANG_FOUND       - system has Clang
+#  CLANG_VERSION     - Clang version
+#  CLANG_EXECUTABLE  - Clang executable
+#
+# Copyright (c) 2013, Vittorio Giovara <vittorio.giovara@gmail.com>
+#
+# Redistribution and use is allowed according to the terms of the BSD license.
+# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+
+find_program(CLANG_EXECUTABLE
         NAMES clang-mp-3.3 clang-mp-3.2 clang-mp-3.1 clang-mp-3.0 clang
         PATHS /opt/local/bin /usr/local/bin /usr/bin)
+
+if (CLANG_EXECUTABLE)
+    execute_process(COMMAND ${CLANG_EXECUTABLE} --version
+                    OUTPUT_VARIABLE CLANG_VERSION_OUTPUT
+                    ERROR_VARIABLE CLANG_VERSION_ERROR
+                    RESULT_VARIABLE CLANG_VERSION_RESULT
+                    OUTPUT_STRIP_TRAILING_WHITESPACE
+                    )
+
+    if(${CLANG_VERSION_RESULT} EQUAL 0)
+        string(REGEX MATCH "[0-9]+\\.[0-9]+" CLANG_VERSION "${CLANG_VERSION_OUTPUT}")
+        string(REGEX REPLACE "([0-9]+\\.[0-9]+)" "\\1" CLANG_VERSION "${CLANG_VERSION}")
+    else()
+        message(SEND_ERROR "Command \"${CLANG_EXECUTABLE} --version\" failed with output: ${CLANG_VERSION_ERROR}")
+    endif()
 endif()
 
-# Check LLVM/Clang version
-if (CLANG_EXECUTABLE)
-    exec_program(${CLANG_EXECUTABLE} ARGS "-v" OUTPUT_VARIABLE CLANG_VERSION_FULL)
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(Clang DEFAULT_MSG CLANG_EXECUTABLE CLANG_VERSION)
+mark_as_advanced(CLANG_VERSION)
 
-    string(REGEX MATCH "[0-9]+\\.[0-9]+" CLANG_VERSION_LONG "${CLANG_VERSION_FULL}")
-    string(REGEX REPLACE "([0-9]+\\.[0-9]+)" "\\1" CLANG_VERSION "${CLANG_VERSION_LONG}")
-else()
-    message(FATAL_ERROR "No LLVM/Clang compiler found (required for engine_c target)")
-endif()
-
-set(CMAKE_C_COMPILER ${CLANG_EXECUTABLE})
-set(CMAKE_CXX_COMPILER ${CLANG_EXECUTABLE})