[llvm-commits] [llvm] r123232 - /llvm/trunk/cmake/modules/LLVMProcessSources.cmake

Oscar Fuentes ofv at wanadoo.es
Tue Jan 11 04:31:35 PST 2011


Author: ofv
Date: Tue Jan 11 06:31:34 2011
New Revision: 123232

URL: http://llvm.org/viewvc/llvm-project?rev=123232&view=rev
Log:
Made llvm_replace_compiler_option more robust. Use it on
llvm_process_sources.

Modified:
    llvm/trunk/cmake/modules/LLVMProcessSources.cmake

Modified: llvm/trunk/cmake/modules/LLVMProcessSources.cmake
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/cmake/modules/LLVMProcessSources.cmake?rev=123232&r1=123231&r2=123232&view=diff
==============================================================================
--- llvm/trunk/cmake/modules/LLVMProcessSources.cmake (original)
+++ llvm/trunk/cmake/modules/LLVMProcessSources.cmake Tue Jan 11 06:31:34 2011
@@ -1,15 +1,22 @@
 include(AddFileDependencies)
 
-macro(llvm_replace_compiler_option var old new)
+function(llvm_replace_compiler_option var old new)
   # Replaces a compiler option or switch `old' in `var' by `new'.
   # If `old' is not in `var', appends `new' to `var'.
   # Example: llvm_replace_compiler_option(CMAKE_CXX_FLAGS_RELEASE "-O3" "-O2")
+  # If the option already is on the variable, don't add it:
+  if( "${${var}}" MATCHES "(^| )${new}($| )" )
+    set(n "")
+  else()
+    set(n "${new}")
+  endif()
   if( "${${var}}" MATCHES "(^| )${old}($| )" )
-    string( REGEX REPLACE "(^| )${old}($| )" " ${new}  " ${var} "${${var}}" )
+    string( REGEX REPLACE "(^| )${old}($| )" " ${n} " ${var} "${${var}}" )
   else()
-    set( ${var} "${${var}} ${new}" )
+    set( ${var} "${${var}} ${n}" )
   endif()
-endmacro(llvm_replace_compiler_option)
+  set( ${var} "${${var}}" PARENT_SCOPE )
+endfunction(llvm_replace_compiler_option)
 
 macro(add_td_sources srcs)
   file(GLOB tds *.td)
@@ -52,15 +59,15 @@
     if( CMAKE_COMPILER_IS_GNUCXX )
       add_definitions( -fno-exceptions )
     elseif( MSVC )
-      string( REGEX REPLACE "[ ^]/EHsc ?" " /EHs-c- " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" )
+      llvm_replace_compiler_option(CMAKE_CXX_FLAGS "/EHsc" "/EHs-c-")
       add_definitions( /D_HAS_EXCEPTIONS=0 )
     endif()
   endif()
   if( NOT LLVM_REQUIRES_RTTI )
     if( CMAKE_COMPILER_IS_GNUCXX )
-      add_definitions( -fno-rtti )
+      llvm_replace_compiler_option(CMAKE_CXX_FLAGS "-frtti" "-fno-rtti")
     elseif( MSVC )
-      string( REGEX REPLACE "[ ^]/GR ?" " /GR- " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" )
+      llvm_replace_compiler_option(CMAKE_CXX_FLAGS "/GR" "/GR-")
     endif()
   endif()
 





More information about the llvm-commits mailing list