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

The simple replacement is much faster.
This commit is contained in:
Rolf Eike Beer 2014-04-06 21:51:33 +02:00
parent 2622bc3f65
commit 5bd48ac534
19 changed files with 32 additions and 34 deletions

View File

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

View File

@ -27,7 +27,7 @@ function(CMAKE_DETERMINE_COMPILER_ID lang flagvar src)
else() else()
set(CMAKE_${lang}_COMPILER_ID_FLAGS $ENV{${flagvar}}) set(CMAKE_${lang}_COMPILER_ID_FLAGS $ENV{${flagvar}})
endif() 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. # Compute the directory in which to run the test.
set(CMAKE_${lang}_COMPILER_ID_DIR ${CMAKE_PLATFORM_INFO_DIR}/CompilerId${lang}) set(CMAKE_${lang}_COMPILER_ID_DIR ${CMAKE_PLATFORM_INFO_DIR}/CompilerId${lang})

View File

@ -72,8 +72,8 @@ if(CMAKE_HOST_UNIX)
endif() endif()
set(CMAKE_UNAME ${CMAKE_UNAME} CACHE INTERNAL "uname command") set(CMAKE_UNAME ${CMAKE_UNAME} CACHE INTERNAL "uname command")
# processor may have double quote in the name, and that needs to be removed # 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(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}")
endif() endif()
else() else()
if(CMAKE_HOST_WIN32) if(CMAKE_HOST_WIN32)

View File

@ -259,7 +259,7 @@ if(CPACK_DEBIAN_PACKAGE_SHLIBDEPS)
OUTPUT_VARIABLE CPACK_DEB_INSTALL_FILES) OUTPUT_VARIABLE CPACK_DEB_INSTALL_FILES)
# Convert to CMake list # 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 # Only dynamically linked ELF files are included
# Extract only file name infront of ":" # Extract only file name infront of ":"

View File

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

View File

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

View File

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

View File

@ -90,9 +90,9 @@ if(UNIX)
exec_program(${GDAL_CONFIG} ARGS --libs OUTPUT_VARIABLE GDAL_CONFIG_LIBS) exec_program(${GDAL_CONFIG} ARGS --libs OUTPUT_VARIABLE GDAL_CONFIG_LIBS)
if(GDAL_CONFIG_LIBS) if(GDAL_CONFIG_LIBS)
string(REGEX MATCHALL "-l[^ ]+" _gdal_dashl ${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 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() endif()
endif() endif()

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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