Browse Source

Better compiler detection in CMake. Language detection for Clang

Christophe Riccio 12 years ago
parent
commit
da38a6e58c
3 changed files with 51 additions and 30 deletions
  1. 21 19
      CMakeLists.txt
  2. 24 11
      glm/core/setup.hpp
  3. 6 0
      readme.txt

+ 21 - 19
CMakeLists.txt

@@ -11,31 +11,33 @@ if(NOT GLM_TEST_ENABLE)
 	message(FATAL_ERROR "GLM is a header only library, no need to build it. Set the option GLM_TEST_ENABLE with ON to build and run the test bench")
 endif()
 
-option(GLM_TEST_ENABLE_CXX_11 "Enable C++ 11" OFF)
-if(GLM_TEST_ENABLE_CXX_11)
-	if(CMAKE_COMPILER_IS_GNUCXX)
-		add_definitions(-std=c++0x)
+if(("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") OR ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") OR (("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel") AND UNIX))
+	option(GLM_TEST_ENABLE_CXX_98 "Enable C++ 98" OFF)
+	option(GLM_TEST_ENABLE_CXX_0X "Enable C++ 0x" OFF)
+	option(GLM_TEST_ENABLE_CXX_11 "Enable C++ 11" OFF)
+	option(GLM_TEST_ENABLE_CXX_1Y "Enable C++ 1y" OFF)
+	option(GLM_TEST_ENABLE_CXX_PEDANTIC "Pedantic" ON)
+
+	if(GLM_TEST_ENABLE_CXX_PEDANTIC)
+		add_definitions(-pedantic)
 	endif()
-elseif(NOT GLM_TEST_ENABLE_CXX_11)
-	if(CMAKE_COMPILER_IS_GNUCXX)
+
+	if(GLM_TEST_ENABLE_CXX_1Y)
+		add_definitions(-std=c++1y)
+	elseif(GLM_TEST_ENABLE_CXX_11)
+		add_definitions(-std=c++11)
+	elseif(GLM_TEST_ENABLE_CXX_0X)
+		add_definitions(-std=c++0x)
+	elseif(GLM_TEST_ENABLE_CXX_98)
 		add_definitions(-std=c++98)
 	endif()
 endif()
 
-option(GLM_TEST_ENABLE_MS_EXTENSIONS "Enable MS extensions" OFF)
-if(GLM_TEST_ENABLE_MS_EXTENSIONS)
-	if(CMAKE_COMPILER_IS_GNUCXX)
-		#Doesn't seem to work...
-		#add_definitions(-fms-extensions)
-		#add_definitions(-D_MSC_EXTENSIONS)
-	endif()
-elseif(NOT GLM_TEST_ENABLE_MS_EXTENSIONS)
-	if(CMAKE_COMPILER_IS_GNUCXX)
-		add_definitions(-pedantic)
-	endif()
+if(("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") OR (("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel") AND WIN32))
+	option(GLM_TEST_ENABLE_MS_EXTENSIONS "Enable MS extensions" OFF)
 
-	if(MSVC)
-		add_definitions(/Za)	
+	if(NOT GLM_TEST_ENABLE_MS_EXTENSIONS)
+		add_definitions(/Za)
 	endif()
 endif()
 

+ 24 - 11
glm/core/setup.hpp

@@ -110,6 +110,17 @@
 
 #define GLM_COMPILER_UNKNOWN		0x00000000
 
+// Intel
+#define GLM_COMPILER_INTEL			0x00100000
+#define GLM_COMPILER_INTEL9			0x00100010
+#define GLM_COMPILER_INTEL10_0		0x00100020
+#define GLM_COMPILER_INTEL10_1		0x00100030
+#define GLM_COMPILER_INTEL11_0		0x00100040
+#define GLM_COMPILER_INTEL11_1		0x00100050
+#define GLM_COMPILER_INTEL12_0		0x00100060
+#define GLM_COMPILER_INTEL12_1		0x00100070
+#define GLM_COMPILER_INTEL13_0		0x00100080
+
 // Visual C++ defines
 #define GLM_COMPILER_VC				0x01000000
 #define GLM_COMPILER_VC2			0x01000010
@@ -187,17 +198,6 @@
 // LLVM GCC
 #define GLM_COMPILER_LLVM_GCC		0x40000000
 
-// Intel
-#define GLM_COMPILER_INTEL			0x80000000
-#define GLM_COMPILER_INTEL9			0x80000010
-#define GLM_COMPILER_INTEL10_0		0x80000020
-#define GLM_COMPILER_INTEL10_1		0x80000030
-#define GLM_COMPILER_INTEL11_0		0x80000040
-#define GLM_COMPILER_INTEL11_1		0x80000050
-#define GLM_COMPILER_INTEL12_0		0x80000060
-#define GLM_COMPILER_INTEL12_1		0x80000070
-#define GLM_COMPILER_INTEL13_0		0x80000080
-
 // Build model
 #define GLM_MODEL_32				0x00000010
 #define GLM_MODEL_64				0x00000020
@@ -431,6 +431,19 @@
 #else
 #	if(__cplusplus >= 201103L)
 #		define GLM_LANG GLM_LANG_CXX11
+#	elif((GLM_COMPILER & GLM_COMPILER_CLANG) == GLM_COMPILER_CLANG)
+#		if(GLM_PLATFORM == GLM_PLATFORM_APPLE)
+#			define GLM_DETAIL_MAJOR 1
+#		else
+#			define GLM_DETAIL_MAJOR 0
+#		endif
+#		if(__clang_major__ < (2 + GLM_DETAIL_MAJOR))
+#			define GLM_LANG GLM_LANG_CXX
+#		elif(__has_feature(cxx_auto_type))
+#			define GLM_LANG GLM_LANG_CXX0X
+#		else
+#			define GLM_LANG GLM_LANG_CXX98
+#		endif
 #	elif((GLM_COMPILER & GLM_COMPILER_GCC) == GLM_COMPILER_GCC)
 #		if defined(__GXX_EXPERIMENTAL_CXX0X__)
 #			define GLM_LANG GLM_LANG_CXX0X

+ 6 - 0
readme.txt

@@ -41,6 +41,12 @@ GLM 0.9.4.6: 2013-08-XX
 --------------------------------------------------------------------------------
 - Fixed detection to select the last known compiler if newer version #106
 - Fixed is_int and is_uint code duplication with GCC and C++11 #107 
+- Fixed test suite build while using Clang in C++11 mode
+- Added c++1y mode support in CMake test suite
+- Removed ms extension mode to CMake when no using Visual C++
+- Added pedantic mode to CMake test suite for Clang and GCC
+- Added use of GCC frontend on Unix for ICC and Visual C++ fronted on Windows 
+  for ICC
 
 ================================================================================
 GLM 0.9.4.5: 2013-08-12