Browse Source

Split the deprecated available check from setting macro values.

Stephen Kelly 14 years ago
parent
commit
9554e1013e

+ 18 - 4
Modules/GenerateExportHeader.cmake

@@ -140,6 +140,20 @@ macro(_test_compiler_hidden_visibility)
   endif()
   endif()
 endmacro()
 endmacro()
 
 
+macro(_test_compiler_has_deprecated)
+  if (WIN32)
+    if (NOT ${CMAKE_CXX_COMPILER_ID} MATCHES Borland)
+      set(COMPILER_HAS_DEPRECATED TRUE)
+    endif()
+  else()
+    # TODO: Test properly for this
+    if(COMPILER_HAS_HIDDEN_VISIBILITY AND USE_COMPILER_HIDDEN_VISIBILITY)
+      set(COMPILER_HAS_DEPRECATED TRUE)
+    endif()
+  endif()
+  set(COMPILER_HAS_DEPRECATED "${COMPILER_HAS_DEPRECATED}" CACHE INTERNAL "Compiler support for a deprecated attribute")
+endmacro()
+
 set(myDir ${CMAKE_CURRENT_LIST_DIR})
 set(myDir ${CMAKE_CURRENT_LIST_DIR})
 
 
 macro(_DO_SET_MACRO_VALUES TARGET_LIBRARY)
 macro(_DO_SET_MACRO_VALUES TARGET_LIBRARY)
@@ -149,13 +163,11 @@ macro(_DO_SET_MACRO_VALUES TARGET_LIBRARY)
   set(DEFINE_NO_EXPORT)
   set(DEFINE_NO_EXPORT)
 
 
   if(WIN32)
   if(WIN32)
-    message("Compiler is ${CMAKE_CXX_COMPILER_ID}")
-    if (NOT ${CMAKE_CXX_COMPILER_ID} MATCHES Borland)
-      message("Deprecation macro enabled.")
+    if (COMPILER_HAS_DEPRECATED)
       set(DEFINE_DEPRECATED "__declspec(deprecated)")
       set(DEFINE_DEPRECATED "__declspec(deprecated)")
     endif()
     endif()
   else()
   else()
-    if(COMPILER_HAS_HIDDEN_VISIBILITY AND USE_COMPILER_HIDDEN_VISIBILITY)
+    if(COMPILER_HAS_DEPRECATED)
       set(DEFINE_DEPRECATED "__attribute__ ((__deprecated__))")
       set(DEFINE_DEPRECATED "__attribute__ ((__deprecated__))")
     endif()
     endif()
   endif()
   endif()
@@ -244,6 +256,7 @@ function(GENERATE_EXPORT_HEADER TARGET_LIBRARY)
     return()
     return()
   endif()
   endif()
   _test_compiler_hidden_visibility()
   _test_compiler_hidden_visibility()
+  _test_compiler_has_deprecated()
   _do_set_macro_values(${TARGET_LIBRARY})
   _do_set_macro_values(${TARGET_LIBRARY})
   _do_generate_export_header(${TARGET_LIBRARY} ${ARGN})
   _do_generate_export_header(${TARGET_LIBRARY} ${ARGN})
 endfunction()
 endfunction()
@@ -251,6 +264,7 @@ endfunction()
 function(add_compiler_export_flags)
 function(add_compiler_export_flags)
 
 
   _test_compiler_hidden_visibility()
   _test_compiler_hidden_visibility()
+  _test_compiler_has_deprecated()
 
 
   if(NOT (USE_COMPILER_HIDDEN_VISIBILITY AND COMPILER_HAS_HIDDEN_VISIBILITY))
   if(NOT (USE_COMPILER_HIDDEN_VISIBILITY AND COMPILER_HAS_HIDDEN_VISIBILITY))
     message(WARNING "Compiler doesn't have hidden visibility")
     message(WARNING "Compiler doesn't have hidden visibility")

+ 1 - 1
Tests/Module/GenerateExportHeader/lib_shared_and_statictest/CMakeLists.txt

@@ -17,7 +17,7 @@ endmacro()
 
 
 static_variant_build_pass("return libshared_and_static_exported();" "Failed to build static variant")
 static_variant_build_pass("return libshared_and_static_exported();" "Failed to build static variant")
 shared_variant_build_pass("return libshared_and_static_exported();" "Failed to build shared variant")
 shared_variant_build_pass("return libshared_and_static_exported();" "Failed to build shared variant")
-if (NOT ${CMAKE_CXX_COMPILER_ID} MATCHES Borland)
+if (COMPILER_HAS_DEPRECATED)
   shared_variant_build_fail("return libshared_and_static_deprecated();" "Built shared deprecated variant")
   shared_variant_build_fail("return libshared_and_static_deprecated();" "Built shared deprecated variant")
   static_variant_build_fail("return libshared_and_static_deprecated();" "Built static deprecated variant")
   static_variant_build_fail("return libshared_and_static_deprecated();" "Built static deprecated variant")
 else()
 else()

+ 1 - 1
Tests/Module/GenerateExportHeader/libsharedtest/CMakeLists.txt

@@ -9,7 +9,7 @@ endmacro()
 
 
 shared_build_pass("Libshared l; return l.libshared_exported();" "Failed to build exported")
 shared_build_pass("Libshared l; return l.libshared_exported();" "Failed to build exported")
 
 
-if (NOT ${CMAKE_CXX_COMPILER_ID} MATCHES Borland)
+if (COMPILER_HAS_DEPRECATED)
   shared_build_fail("Libshared l; return l.libshared_deprecated();" "Built use of deprecated class method. This should not be possible.")
   shared_build_fail("Libshared l; return l.libshared_deprecated();" "Built use of deprecated class method. This should not be possible.")
 else()
 else()
   shared_build_pass("Libshared l; return l.libshared_deprecated();" "Built use of deprecated class method. This should not be possible.")
   shared_build_pass("Libshared l; return l.libshared_deprecated();" "Built use of deprecated class method. This should not be possible.")

+ 1 - 1
Tests/Module/GenerateExportHeader/libstatictest/CMakeLists.txt

@@ -9,7 +9,7 @@ endmacro()
 
 
 static_build_pass("Libstatic l; return l.libstatic_exported();" "Failed to build exported.")
 static_build_pass("Libstatic l; return l.libstatic_exported();" "Failed to build exported.")
 
 
-if (NOT ${CMAKE_CXX_COMPILER_ID} MATCHES Borland)
+if (COMPILER_HAS_DEPRECATED)
   static_build_fail("Libstatic l; return l.libstatic_deprecated();" "Built use of deprecated class method. This should not be possible.")
   static_build_fail("Libstatic l; return l.libstatic_deprecated();" "Built use of deprecated class method. This should not be possible.")
   static_build_fail("libstatic_deprecated();" "Built use of deprecated function. This should not be possible.")
   static_build_fail("libstatic_deprecated();" "Built use of deprecated function. This should not be possible.")
 else()
 else()