浏览代码

Add FAIL_REGEX to CHECK_(C|CXX)_SOURCE_COMPILES

This teaches the CHECK_C_SOURCE_COMPILES and CHECK_CXX_SOURCE_COMPILES
macros to recognize a FAIL_REGEX option.  If they see the regular
expression in the output of the test compilation, the check fails.
Brad King 16 年之前
父节点
当前提交
ca76645ab7
共有 2 个文件被更改,包括 41 次插入2 次删除
  1. 20 1
      Modules/CheckCSourceCompiles.cmake
  2. 21 1
      Modules/CheckCXXSourceCompiles.cmake

+ 20 - 1
Modules/CheckCSourceCompiles.cmake

@@ -1,7 +1,8 @@
 # - Check if the given C source code compiles.
-# CHECK_C_SOURCE_COMPILES(<code> <var>)
+# CHECK_C_SOURCE_COMPILES(<code> <var> [FAIL_REGEX <fail-regex>])
 #  <code>       - source code to try to compile
 #  <var>        - variable to store whether the source code compiled
+#  <fail-regex> - fail if test output matches this regex
 # The following variables may be set before calling this macro to
 # modify the way the check is run:
 #
@@ -12,6 +13,17 @@
 
 MACRO(CHECK_C_SOURCE_COMPILES SOURCE VAR)
   IF("${VAR}" MATCHES "^${VAR}$")
+    SET(_FAIL_REGEX)
+    SET(_key)
+    FOREACH(arg ${ARGN})
+      IF("${arg}" MATCHES "^(FAIL_REGEX)$")
+        SET(_key "${arg}")
+      ELSEIF(_key)
+        LIST(APPEND _${_key} "${arg}")
+      ELSE()
+        MESSAGE(FATAL_ERROR "Unknown argument:\n  ${arg}\n")
+      ENDIF()
+    ENDFOREACH()
     SET(MACRO_CHECK_FUNCTION_DEFINITIONS
       "-D${VAR} ${CMAKE_REQUIRED_FLAGS}")
     IF(CMAKE_REQUIRED_LIBRARIES)
@@ -38,6 +50,13 @@ MACRO(CHECK_C_SOURCE_COMPILES SOURCE VAR)
       "${CHECK_C_SOURCE_COMPILES_ADD_LIBRARIES}"
       "${CHECK_C_SOURCE_COMPILES_ADD_INCLUDES}"
       OUTPUT_VARIABLE OUTPUT)
+
+    FOREACH(_regex ${_FAIL_REGEX})
+      IF("${OUTPUT}" MATCHES "${_regex}")
+        SET(${VAR} 0)
+      ENDIF()
+    ENDFOREACH()
+
     IF(${VAR})
       SET(${VAR} 1 CACHE INTERNAL "Test ${VAR}")
       MESSAGE(STATUS "Performing Test ${VAR} - Success")

+ 21 - 1
Modules/CheckCXXSourceCompiles.cmake

@@ -1,7 +1,8 @@
 # - Check if the given C++ source code compiles.
-# CHECK_CXX_SOURCE_COMPILES(<code> <var>)
+# CHECK_CXX_SOURCE_COMPILES(<code> <var> [FAIL_REGEX <fail-regex>])
 #  <code>       - source code to try to compile
 #  <var>        - variable to store whether the source code compiled
+#  <fail-regex> - fail if test output matches this regex
 # The following variables may be set before calling this macro to
 # modify the way the check is run:
 #
@@ -12,6 +13,18 @@
 
 MACRO(CHECK_CXX_SOURCE_COMPILES SOURCE VAR)
   IF("${VAR}" MATCHES "^${VAR}$")
+    SET(_FAIL_REGEX)
+    SET(_key)
+    FOREACH(arg ${ARGN})
+      IF("${arg}" MATCHES "^(FAIL_REGEX)$")
+        SET(_key "${arg}")
+      ELSEIF(_key)
+        LIST(APPEND _${_key} "${arg}")
+      ELSE()
+        MESSAGE(FATAL_ERROR "Unknown argument:\n  ${arg}\n")
+      ENDIF()
+    ENDFOREACH()
+
     SET(MACRO_CHECK_FUNCTION_DEFINITIONS
       "-D${VAR} ${CMAKE_REQUIRED_FLAGS}")
     IF(CMAKE_REQUIRED_LIBRARIES)
@@ -38,6 +51,13 @@ MACRO(CHECK_CXX_SOURCE_COMPILES SOURCE VAR)
       "${CHECK_CXX_SOURCE_COMPILES_ADD_LIBRARIES}"
       "${CHECK_CXX_SOURCE_COMPILES_ADD_INCLUDES}"
       OUTPUT_VARIABLE OUTPUT)
+
+    FOREACH(_regex ${_FAIL_REGEX})
+      IF("${OUTPUT}" MATCHES "${_regex}")
+        SET(${VAR} 0)
+      ENDIF()
+    ENDFOREACH()
+
     IF(${VAR})
       SET(${VAR} 1 CACHE INTERNAL "Test ${VAR}")
       MESSAGE(STATUS "Performing Test ${VAR} - Success")