浏览代码

Replace string(REGEX REPLACE) with string(REPLACE) where possible

The simple replacement is much faster.
Rolf Eike Beer 11 年之前
父节点
当前提交
5bd48ac534

+ 3 - 3
Modules/BundleUtilities.cmake

@@ -235,8 +235,8 @@ function(get_bundle_main_executable bundle result_var)
     #
     set(eol_char "E")
     file(READ "${bundle}/Contents/Info.plist" info_plist)
-    string(REGEX REPLACE ";" "\\\\;" info_plist "${info_plist}")
-    string(REGEX REPLACE "\n" "${eol_char};" info_plist "${info_plist}")
+    string(REPLACE ";" "\\;" info_plist "${info_plist}")
+    string(REPLACE "\n" "${eol_char};" info_plist "${info_plist}")
 
     # Scan the lines for "<key>CFBundleExecutable</key>" - the line after that
     # is the name of the main executable.
@@ -394,7 +394,7 @@ function(get_item_key item key_var)
   if(WIN32)
     string(TOLOWER "${item_name}" item_name)
   endif()
-  string(REGEX REPLACE "\\." "_" ${key_var} "${item_name}")
+  string(REPLACE "." "_" ${key_var} "${item_name}")
   set(${key_var} ${${key_var}} PARENT_SCOPE)
 endfunction()
 

+ 1 - 1
Modules/CMakeDetermineCompilerId.cmake

@@ -27,7 +27,7 @@ function(CMAKE_DETERMINE_COMPILER_ID lang flagvar src)
   else()
     set(CMAKE_${lang}_COMPILER_ID_FLAGS $ENV{${flagvar}})
   endif()
-  string(REGEX REPLACE " " ";" CMAKE_${lang}_COMPILER_ID_FLAGS_LIST "${CMAKE_${lang}_COMPILER_ID_FLAGS}")
+  string(REPLACE " " ";" CMAKE_${lang}_COMPILER_ID_FLAGS_LIST "${CMAKE_${lang}_COMPILER_ID_FLAGS}")
 
   # Compute the directory in which to run the test.
   set(CMAKE_${lang}_COMPILER_ID_DIR ${CMAKE_PLATFORM_INFO_DIR}/CompilerId${lang})

+ 2 - 2
Modules/CMakeDetermineSystem.cmake

@@ -72,8 +72,8 @@ if(CMAKE_HOST_UNIX)
     endif()
     set(CMAKE_UNAME ${CMAKE_UNAME} CACHE INTERNAL "uname command")
     # processor may have double quote in the name, and that needs to be removed
-    string(REGEX REPLACE "\"" "" CMAKE_HOST_SYSTEM_PROCESSOR "${CMAKE_HOST_SYSTEM_PROCESSOR}")
-    string(REGEX REPLACE "/" "_" CMAKE_HOST_SYSTEM_PROCESSOR "${CMAKE_HOST_SYSTEM_PROCESSOR}")
+    string(REPLACE "\"" "" CMAKE_HOST_SYSTEM_PROCESSOR "${CMAKE_HOST_SYSTEM_PROCESSOR}")
+    string(REPLACE "/" "_" CMAKE_HOST_SYSTEM_PROCESSOR "${CMAKE_HOST_SYSTEM_PROCESSOR}")
   endif()
 else()
   if(CMAKE_HOST_WIN32)

+ 1 - 1
Modules/CPackDeb.cmake

@@ -259,7 +259,7 @@ if(CPACK_DEBIAN_PACKAGE_SHLIBDEPS)
       OUTPUT_VARIABLE CPACK_DEB_INSTALL_FILES)
 
     # Convert to CMake list
-    string(REGEX REPLACE "\n" ";" CPACK_DEB_INSTALL_FILES ${CPACK_DEB_INSTALL_FILES})
+    string(REPLACE "\n" ";" CPACK_DEB_INSTALL_FILES ${CPACK_DEB_INSTALL_FILES})
 
     # Only dynamically linked ELF files are included
     # Extract only file name infront of ":"

+ 1 - 1
Modules/CPackRPM.cmake

@@ -384,7 +384,7 @@ if(CPACK_RPM_PACKAGE_DEBUG)
                     OUTPUT_VARIABLE _TMP_LSB_RELEASE_OUTPUT
                     ERROR_QUIET
                     OUTPUT_STRIP_TRAILING_WHITESPACE)
-    string(REGEX REPLACE "\n" ", "
+    string(REPLACE "\n" ", "
            LSB_RELEASE_OUTPUT
            ${_TMP_LSB_RELEASE_OUTPUT})
   else ()

+ 1 - 2
Modules/FindCUDA/make2cmake.cmake

@@ -41,8 +41,7 @@ if (${depend_text} MATCHES ".+")
 
   # message("FOUND DEPENDS")
 
-  # Remember, four backslashes is escaped to one backslash in the string.
-  string(REGEX REPLACE "\\\\ " " " depend_text ${depend_text})
+  string(REPLACE "\\ " " " depend_text ${depend_text})
 
   # This works for the nvcc -M generated dependency files.
   string(REGEX REPLACE "^.* : " "" depend_text ${depend_text})

+ 2 - 3
Modules/FindCUDA/parse_cubin.cmake

@@ -39,9 +39,8 @@ file(READ ${input_file} file_text)
 
 if (${file_text} MATCHES ".+")
 
-  # Remember, four backslashes is escaped to one backslash in the string.
-  string(REGEX REPLACE ";" "\\\\;" file_text ${file_text})
-  string(REGEX REPLACE "\ncode" ";code" file_text ${file_text})
+  string(REPLACE ";" "\\;" file_text ${file_text})
+  string(REPLACE "\ncode" ";code" file_text ${file_text})
 
   list(LENGTH file_text len)
 

+ 2 - 2
Modules/FindGDAL.cmake

@@ -90,9 +90,9 @@ if(UNIX)
         exec_program(${GDAL_CONFIG} ARGS --libs OUTPUT_VARIABLE GDAL_CONFIG_LIBS)
         if(GDAL_CONFIG_LIBS)
             string(REGEX MATCHALL "-l[^ ]+" _gdal_dashl ${GDAL_CONFIG_LIBS})
-            string(REGEX REPLACE "-l" "" _gdal_lib "${_gdal_dashl}")
+            string(REPLACE "-l" "" _gdal_lib "${_gdal_dashl}")
             string(REGEX MATCHALL "-L[^ ]+" _gdal_dashL ${GDAL_CONFIG_LIBS})
-            string(REGEX REPLACE "-L" "" _gdal_libpath "${_gdal_dashL}")
+            string(REPLACE "-L" "" _gdal_libpath "${_gdal_dashL}")
         endif()
     endif()
 endif()

+ 2 - 2
Modules/FindHDF5.cmake

@@ -162,7 +162,7 @@ macro( _HDF5_parse_compile_line
     )
     foreach( IPATH ${include_path_flags} )
         string( REGEX REPLACE "^-I" "" IPATH ${IPATH} )
-        string( REGEX REPLACE "//" "/" IPATH ${IPATH} )
+        string( REPLACE "//" "/" IPATH ${IPATH} )
         list( APPEND ${include_paths} ${IPATH} )
     endforeach()
 
@@ -179,7 +179,7 @@ macro( _HDF5_parse_compile_line
 
     foreach( LPATH ${library_path_flags} )
         string( REGEX REPLACE "^-L" "" LPATH ${LPATH} )
-        string( REGEX REPLACE "//" "/" LPATH ${LPATH} )
+        string( REPLACE "//" "/" LPATH ${LPATH} )
         list( APPEND ${library_paths} ${LPATH} )
     endforeach()
 

+ 1 - 1
Modules/FindKDE3.cmake

@@ -192,7 +192,7 @@ if(KDECONFIG_EXECUTABLE)
    if ("${kde_version}" MATCHES "KDE: 3\\.")
       execute_process(COMMAND ${KDECONFIG_EXECUTABLE} --prefix
                         OUTPUT_VARIABLE kdedir )
-      string(REGEX REPLACE "\n" "" KDE3PREFIX "${kdedir}")
+      string(REPLACE "\n" "" KDE3PREFIX "${kdedir}")
 
     endif ()
 endif()

+ 2 - 2
Modules/FindMPI.cmake

@@ -330,7 +330,7 @@ function (interrogate_mpi_compiler lang try_libs)
         string(REGEX MATCHALL "(^| )-I([^\" ]+|\"[^\"]+\")" MPI_ALL_INCLUDE_PATHS "${MPI_COMPILE_CMDLINE}")
         foreach(IPATH ${MPI_ALL_INCLUDE_PATHS})
           string(REGEX REPLACE "^ ?-I" "" IPATH ${IPATH})
-          string(REGEX REPLACE "//" "/" IPATH ${IPATH})
+          string(REPLACE "//" "/" IPATH ${IPATH})
           list(APPEND MPI_INCLUDE_PATH_WORK ${IPATH})
         endforeach()
 
@@ -354,7 +354,7 @@ function (interrogate_mpi_compiler lang try_libs)
         set(MPI_LINK_PATH)
         foreach(LPATH ${MPI_ALL_LINK_PATHS})
           string(REGEX REPLACE "^(| |-Wl,)-L" "" LPATH ${LPATH})
-          string(REGEX REPLACE "//" "/" LPATH ${LPATH})
+          string(REPLACE "//" "/" LPATH ${LPATH})
           list(APPEND MPI_LINK_PATH ${LPATH})
         endforeach()
 

+ 1 - 1
Modules/FindPackageMessage.cmake

@@ -42,7 +42,7 @@
 function(FIND_PACKAGE_MESSAGE pkg msg details)
   # Avoid printing a message repeatedly for the same find result.
   if(NOT ${pkg}_FIND_QUIETLY)
-    string(REGEX REPLACE "[\n]" "" details "${details}")
+    string(REPLACE "\n" "" details "${details}")
     set(DETAILS_VAR FIND_PACKAGE_MESSAGE_DETAILS_${pkg})
     if(NOT "${details}" STREQUAL "${${DETAILS_VAR}}")
       # The message has not yet been printed.

+ 1 - 1
Modules/FortranCInterface.cmake

@@ -328,7 +328,7 @@ function(FortranCInterface_VERIFY)
   # Error if compilers are incompatible.
   if(NOT FortranCInterface_VERIFIED_${lang} AND NOT quiet)
     file(READ "${FortranCInterface_BINARY_DIR}/Verify${lang}/output.txt" _output)
-    string(REGEX REPLACE "\n" "\n  " _output "${_output}")
+    string(REPLACE "\n" "\n  " _output "${_output}")
     message(FATAL_ERROR
       "The Fortran compiler:\n  ${CMAKE_Fortran_COMPILER}\n"
       "and the ${lang} compiler:\n  ${CMAKE_${lang}_COMPILER}\n"

+ 4 - 4
Modules/GetPrerequisites.cmake

@@ -509,10 +509,10 @@ function(gp_resolved_file_type original_file file exepath dirs type_var)
 
     if(WIN32)
       string(TOLOWER "$ENV{SystemRoot}" sysroot)
-      string(REGEX REPLACE "\\\\" "/" sysroot "${sysroot}")
+      file(TO_CMAKE_PATH "${sysroot}" sysroot)
 
       string(TOLOWER "$ENV{windir}" windir)
-      string(REGEX REPLACE "\\\\" "/" windir "${windir}")
+      file(TO_CMAKE_PATH "${windir}" windir)
 
       if(lower MATCHES "^(${sysroot}/sys(tem|wow)|${windir}/sys(tem|wow)|(.*/)*msvc[^/]+dll)")
         set(is_system 1)
@@ -772,8 +772,8 @@ function(get_prerequisites target prerequisites_var exclude_system recurse exepa
 
   # Convert to a list of lines:
   #
-  string(REGEX REPLACE ";" "\\\\;" candidates "${gp_cmd_ov}")
-  string(REGEX REPLACE "\n" "${eol_char};" candidates "${candidates}")
+  string(REPLACE ";" "\\;" candidates "${gp_cmd_ov}")
+  string(REPLACE "\n" "${eol_char};" candidates "${candidates}")
 
   # check for install id and remove it from list, since otool -L can include a
   # reference to itself

+ 1 - 1
Modules/Platform/OpenBSD.cmake

@@ -10,7 +10,7 @@ if(NOT CMAKE_PLATFORM_RUNTIME_PATH)
                   ERROR_QUIET)
   string(REGEX REPLACE ".*search\\ directories:\\ ([^\n]*).*" "\\1"
          LDCONFIG_HINTS "${LDCONFIG_HINTS}")
-  string(REGEX REPLACE ":" ";"
+  string(REPLACE ":" ";"
          CMAKE_PLATFORM_RUNTIME_PATH
          "${LDCONFIG_HINTS}")
 endif()

+ 2 - 2
Tests/CMakeTests/CheckCMakeTest.cmake

@@ -9,8 +9,8 @@ function(check_cmake_test_single prefix test testfile)
     ERROR_VARIABLE stderr
     RESULT_VARIABLE result
     )
-  string(REGEX REPLACE "\n" "\n out> " out " out> ${stdout}")
-  string(REGEX REPLACE "\n" "\n err> " err " err> ${stderr}")
+  string(REPLACE "\n" "\n out> " out " out> ${stdout}")
+  string(REPLACE "\n" "\n err> " err " err> ${stderr}")
   if(NOT "${result}" STREQUAL "${${test}-RESULT}")
     message(FATAL_ERROR
       "Test ${test} result is [${result}], not [${${test}-RESULT}].\n"

+ 2 - 2
Tests/CTestUpdateCommon.cmake

@@ -9,7 +9,7 @@ function(run_child)
     ERROR_STRIP_TRAILING_WHITESPACE
     )
   if(FAILED)
-    string(REGEX REPLACE "\n" "\n  " OUTPUT "${OUTPUT}")
+    string(REPLACE "\n" "\n  " OUTPUT "${OUTPUT}")
     message(FATAL_ERROR "Child failed (${FAILED}), output is\n  ${OUTPUT}\n"
       "Command = [${ARGN}]\n")
   endif()
@@ -108,7 +108,7 @@ function(check_updates build)
       ${TOP}/${build}/Testing/Temporary/LastUpdate*.log)
     if(UPDATE_LOG_FILE)
       file(READ ${UPDATE_LOG_FILE} UPDATE_LOG LIMIT ${max_update_xml_size})
-      string(REGEX REPLACE "\n" "\n  " UPDATE_LOG "${UPDATE_LOG}")
+      string(REPLACE "\n" "\n  " UPDATE_LOG "${UPDATE_LOG}")
       set(MSG "${MSG}Update log:\n  ${UPDATE_LOG}")
     else()
       set(MSG "${MSG}No update log found!")

+ 2 - 2
Tests/CustomCommand/CMakeLists.txt

@@ -367,8 +367,8 @@ endif()
 
 foreach(arg ${CHECK_ARGS} "")
   set(ARG "${arg}")
-  string(REGEX REPLACE "\\\\" "\\\\\\\\" ARG "${ARG}")
-  string(REGEX REPLACE "\"" "\\\\\"" ARG "${ARG}")
+  string(REPLACE "\\" "\\\\" ARG "${ARG}")
+  string(REPLACE "\"" "\\\"" ARG "${ARG}")
   set(EXPECTED_ARGUMENTS
     "${EXPECTED_ARGUMENTS}  \"${ARG}\",
 ")

+ 1 - 1
cmake_uninstall.cmake.in

@@ -3,7 +3,7 @@ if(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
 endif()
 
 file(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files)
-string(REGEX REPLACE "\n" ";" files "${files}")
+string(REPLACE "\n" ";" files "${files}")
 foreach(file ${files})
   message(STATUS "Uninstalling \"$ENV{DESTDIR}${file}\"")
   if(EXISTS "$ENV{DESTDIR}${file}")