From 4be6783711b2ff510c3449c5de22d35663d8bfc1 Mon Sep 17 00:00:00 2001 From: Rolf Eike Beer Date: Sun, 19 Aug 2012 13:54:56 +0200 Subject: read less from version headers into variables Instead of reading the whole file using file(READ) and later matching on the whole file use file(STRINGS ... REGEX) to get only those lines we are interested in at all. This will make the list much smaller (good for debugging) and also the regular expressions will need to match on much smaller strings. Also unset the content variables once they are not used anymore. --- Modules/FindArmadillo.cmake | 3 ++- Modules/FindBoost.cmake | 3 ++- Modules/FindGTK2.cmake | 2 +- Modules/FindHSPELL.cmake | 3 ++- Modules/FindLibLZMA.cmake | 3 ++- Modules/FindOpenSceneGraph.cmake | 4 +++- Modules/FindQt3.cmake | 4 ++-- Modules/KDE3Macros.cmake | 35 +++++++++++++++++------------------ Modules/Qt4Macros.cmake | 8 ++++---- 9 files changed, 35 insertions(+), 30 deletions(-) diff --git a/Modules/FindArmadillo.cmake b/Modules/FindArmadillo.cmake index aad22d2..0bd3e6c 100644 --- a/Modules/FindArmadillo.cmake +++ b/Modules/FindArmadillo.cmake @@ -58,7 +58,7 @@ if(ARMADILLO_INCLUDE_DIR) if(EXISTS "${ARMADILLO_INCLUDE_DIR}/armadillo_bits/arma_version.hpp") # Read and parse armdillo version header file for version number - file(READ "${ARMADILLO_INCLUDE_DIR}/armadillo_bits/arma_version.hpp" _armadillo_HEADER_CONTENTS) + file(STRINGS "${ARMADILLO_INCLUDE_DIR}/armadillo_bits/arma_version.hpp" _armadillo_HEADER_CONTENTS REGEX "#define ARMA_VERSION_[A-Z]+ ") string(REGEX REPLACE ".*#define ARMA_VERSION_MAJOR ([0-9]+).*" "\\1" ARMADILLO_VERSION_MAJOR "${_armadillo_HEADER_CONTENTS}") string(REGEX REPLACE ".*#define ARMA_VERSION_MINOR ([0-9]+).*" "\\1" ARMADILLO_VERSION_MINOR "${_armadillo_HEADER_CONTENTS}") string(REGEX REPLACE ".*#define ARMA_VERSION_PATCH ([0-9]+).*" "\\1" ARMADILLO_VERSION_PATCH "${_armadillo_HEADER_CONTENTS}") @@ -66,6 +66,7 @@ if(ARMADILLO_INCLUDE_DIR) # WARNING: The number of spaces before the version name is not one. string(REGEX REPLACE ".*#define ARMA_VERSION_NAME\ +\"([0-9a-zA-Z\ _-]+)\".*" "\\1" ARMADILLO_VERSION_NAME "${_armadillo_HEADER_CONTENTS}") + unset(_armadillo_HEADER_CONTENTS) endif() set(ARMADILLO_VERSION_STRING "${ARMADILLO_VERSION_MAJOR}.${ARMADILLO_VERSION_MINOR}.${ARMADILLO_VERSION_PATCH}") diff --git a/Modules/FindBoost.cmake b/Modules/FindBoost.cmake index 607e249..17aba1b 100644 --- a/Modules/FindBoost.cmake +++ b/Modules/FindBoost.cmake @@ -729,7 +729,7 @@ set(Boost_ERROR_REASON) # set(BOOST_VERSION 0) set(BOOST_LIB_VERSION "") - file(READ "${Boost_INCLUDE_DIR}/boost/version.hpp" _boost_VERSION_HPP_CONTENTS) + file(STRINGS "${Boost_INCLUDE_DIR}/boost/version.hpp" _boost_VERSION_HPP_CONTENTS REGEX "#define BOOST_(LIB_)?VERSION ") if(Boost_DEBUG) message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " "location of version.hpp: ${Boost_INCLUDE_DIR}/boost/version.hpp") @@ -737,6 +737,7 @@ set(Boost_ERROR_REASON) string(REGEX REPLACE ".*#define BOOST_VERSION ([0-9]+).*" "\\1" Boost_VERSION "${_boost_VERSION_HPP_CONTENTS}") string(REGEX REPLACE ".*#define BOOST_LIB_VERSION \"([0-9_]+)\".*" "\\1" Boost_LIB_VERSION "${_boost_VERSION_HPP_CONTENTS}") + unset(_boost_VERSION_HPP_CONTENTS) set(Boost_LIB_VERSION ${Boost_LIB_VERSION} CACHE INTERNAL "The library version string for boost libraries") set(Boost_VERSION ${Boost_VERSION} CACHE INTERNAL "The version number for boost libraries") diff --git a/Modules/FindGTK2.cmake b/Modules/FindGTK2.cmake index d10b419..1e54cd7 100644 --- a/Modules/FindGTK2.cmake +++ b/Modules/FindGTK2.cmake @@ -114,7 +114,7 @@ # _gtkversion_hdr = Header file to parse #============================================================= function(_GTK2_GET_VERSION _OUT_major _OUT_minor _OUT_micro _gtkversion_hdr) - file(READ ${_gtkversion_hdr} _contents) + file(STRINGS ${_gtkversion_hdr} _contents REGEX "#define GTK_M[A-Z]+_VERSION[ \t]+") if(_contents) string(REGEX REPLACE ".*#define GTK_MAJOR_VERSION[ \t]+\\(([0-9]+)\\).*" "\\1" ${_OUT_major} "${_contents}") string(REGEX REPLACE ".*#define GTK_MINOR_VERSION[ \t]+\\(([0-9]+)\\).*" "\\1" ${_OUT_minor} "${_contents}") diff --git a/Modules/FindHSPELL.cmake b/Modules/FindHSPELL.cmake index 05b5505..71e55da 100644 --- a/Modules/FindHSPELL.cmake +++ b/Modules/FindHSPELL.cmake @@ -29,10 +29,11 @@ find_path(HSPELL_INCLUDE_DIR hspell.h) find_library(HSPELL_LIBRARIES NAMES hspell) if (HSPELL_INCLUDE_DIR) - file(READ "${HSPELL_INCLUDE_DIR}/hspell.h" HSPELL_H) + file(STRINGS "${HSPELL_INCLUDE_DIR}/hspell.h" HSPELL_H REGEX "#define HSPELL_VERSION_M(AJO|INO)R [0-9]+") string(REGEX REPLACE ".*#define HSPELL_VERSION_MAJOR ([0-9]+).*" "\\1" HSPELL_VERSION_MAJOR "${HSPELL_H}") string(REGEX REPLACE ".*#define HSPELL_VERSION_MINOR ([0-9]+).*" "\\1" HSPELL_VERSION_MINOR "${HSPELL_H}") set(HSPELL_VERSION_STRING "${HSPELL_VERSION_MAJOR}.${HSPELL_VERSION_MINOR}") + unset(HSPELL_H) endif() # handle the QUIETLY and REQUIRED arguments and set HSPELL_FOUND to TRUE if diff --git a/Modules/FindLibLZMA.cmake b/Modules/FindLibLZMA.cmake index 37cace8..f8ea18b 100644 --- a/Modules/FindLibLZMA.cmake +++ b/Modules/FindLibLZMA.cmake @@ -33,13 +33,14 @@ find_path(LIBLZMA_INCLUDE_DIR lzma.h ) find_library(LIBLZMA_LIBRARY lzma) if(LIBLZMA_INCLUDE_DIR AND EXISTS "${LIBLZMA_INCLUDE_DIR}/lzma/version.h") - file(READ "${LIBLZMA_INCLUDE_DIR}/lzma/version.h" LIBLZMA_HEADER_CONTENTS) + file(STRINGS "${LIBLZMA_INCLUDE_DIR}/lzma/version.h" LIBLZMA_HEADER_CONTENTS REGEX "#define LZMA_VERSION_[A-Z]+ [0-9]+") string(REGEX REPLACE ".*#define LZMA_VERSION_MAJOR ([0-9]+).*" "\\1" LIBLZMA_VERSION_MAJOR "${LIBLZMA_HEADER_CONTENTS}") string(REGEX REPLACE ".*#define LZMA_VERSION_MINOR ([0-9]+).*" "\\1" LIBLZMA_VERSION_MINOR "${LIBLZMA_HEADER_CONTENTS}") string(REGEX REPLACE ".*#define LZMA_VERSION_PATCH ([0-9]+).*" "\\1" LIBLZMA_VERSION_PATCH "${LIBLZMA_HEADER_CONTENTS}") set(LIBLZMA_VERSION_STRING "${LIBLZMA_VERSION_MAJOR}.${LIBLZMA_VERSION_MINOR}.${LIBLZMA_VERSION_PATCH}") + unset(LIBLZMA_HEADER_CONTENTS) endif() # We're using new code known now as XZ, even library still been called LZMA diff --git a/Modules/FindOpenSceneGraph.cmake b/Modules/FindOpenSceneGraph.cmake index 17ab057..95912fa 100644 --- a/Modules/FindOpenSceneGraph.cmake +++ b/Modules/FindOpenSceneGraph.cmake @@ -103,7 +103,8 @@ if(OSG_INCLUDE_DIR) endif() if(EXISTS "${_osg_Version_file}") - file(READ "${_osg_Version_file}" _osg_Version_contents) + file(STRINGS "${_osg_Version_file}" _osg_Version_contents + REGEX "#define (OSG_VERSION_[A-Z]+|OPENSCENEGRAPH_[A-Z]+_VERSION)[ \t]+[0-9]+") else() set(_osg_Version_contents "unknown") endif() @@ -130,6 +131,7 @@ if(OSG_INCLUDE_DIR) message(WARNING "[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] " "Failed to parse version number, please report this as a bug") endif() + unset(_osg_Version_contents) set(OPENSCENEGRAPH_VERSION "${_osg_VERSION_MAJOR}.${_osg_VERSION_MINOR}.${_osg_VERSION_PATCH}" CACHE INTERNAL "The version of OSG which was detected") diff --git a/Modules/FindQt3.cmake b/Modules/FindQt3.cmake index 15fbc0b..28af7ad 100644 --- a/Modules/FindQt3.cmake +++ b/Modules/FindQt3.cmake @@ -74,9 +74,9 @@ endif() if(QT_INCLUDE_DIR) #extract the version string from qglobal.h - file(READ ${QT_INCLUDE_DIR}/qglobal.h QGLOBAL_H) - string(REGEX MATCH "#define[\t ]+QT_VERSION_STR[\t ]+\"[0-9]+.[0-9]+.[0-9]+[a-z]*\"" QGLOBAL_H "${QGLOBAL_H}") + file(STRINGS ${QT_INCLUDE_DIR}/qglobal.h QGLOBAL_H REGEX "#define[\t ]+QT_VERSION_STR[\t ]+\"[0-9]+.[0-9]+.[0-9]+[a-z]*\"") string(REGEX REPLACE ".*\"([0-9]+.[0-9]+.[0-9]+[a-z]*)\".*" "\\1" qt_version_str "${QGLOBAL_H}") + unset(QGLOBAL_H) # Under windows the qt library (MSVC) has the format qt-mtXYZ where XYZ is the # version X.Y.Z, so we need to remove the dots from version diff --git a/Modules/KDE3Macros.cmake b/Modules/KDE3Macros.cmake index 6d6cdb0..07864f5 100644 --- a/Modules/KDE3Macros.cmake +++ b/Modules/KDE3Macros.cmake @@ -223,31 +223,30 @@ macro(KDE3_AUTOMOC) if (EXISTS ${_abs_FILE} AND NOT _skip) - file(READ ${_abs_FILE} _contents) + file(STRINGS ${_abs_FILE} _match REGEX "#include +[^ ]+\\.moc[\">]") get_filename_component(_abs_PATH ${_abs_FILE} PATH) - string(REGEX MATCHALL "#include +[^ ]+\\.moc[\">]" _match "${_contents}") - if(_match) - foreach (_current_MOC_INC ${_match}) - string(REGEX MATCH "[^ <\"]+\\.moc" _current_MOC "${_current_MOC_INC}") + foreach (_current_MOC_INC IN LISTS _match) + string(REGEX MATCH "[^ <\"]+\\.moc" _current_MOC "${_current_MOC_INC}") - get_filename_component(_basename ${_current_MOC} NAME_WE) -# set(_header ${CMAKE_CURRENT_SOURCE_DIR}/${_basename}.h) - set(_header ${_abs_PATH}/${_basename}.h) - set(_moc ${CMAKE_CURRENT_BINARY_DIR}/${_current_MOC}) + get_filename_component(_basename ${_current_MOC} NAME_WE) +# set(_header ${CMAKE_CURRENT_SOURCE_DIR}/${_basename}.h) + set(_header ${_abs_PATH}/${_basename}.h) + set(_moc ${CMAKE_CURRENT_BINARY_DIR}/${_current_MOC}) - add_custom_command(OUTPUT ${_moc} - COMMAND ${QT_MOC_EXECUTABLE} - ARGS ${_header} -o ${_moc} - DEPENDS ${_header} - ) + add_custom_command(OUTPUT ${_moc} + COMMAND ${QT_MOC_EXECUTABLE} + ARGS ${_header} -o ${_moc} + DEPENDS ${_header} + ) - ADD_FILE_DEPENDENCIES(${_abs_FILE} ${_moc}) - - endforeach () - endif() + ADD_FILE_DEPENDENCIES(${_abs_FILE} ${_moc}) + endforeach () + unset(_match) + unset(_header) + unset(_moc) endif () endforeach () endmacro() diff --git a/Modules/Qt4Macros.cmake b/Modules/Qt4Macros.cmake index 4324347..95a2176 100644 --- a/Modules/Qt4Macros.cmake +++ b/Modules/Qt4Macros.cmake @@ -187,15 +187,15 @@ macro (QT4_ADD_RESOURCES outfiles ) if(EXISTS "${infile}") # parse file for dependencies # all files are absolute paths or relative to the location of the qrc file - file(READ "${infile}" _RC_FILE_CONTENTS) - string(REGEX MATCHALL "]*>" "" _RC_FILE "${_RC_FILE}") + file(STRINGS "${infile}" _RC_FILES REGEX "]*>[^<]+") + foreach(_RC_FILE IN LISTS _RC_FILES) + string(REGEX REPLACE "^]*>([^<]*)" "\\1" _RC_FILE "${_RC_FILE}") if(NOT IS_ABSOLUTE "${_RC_FILE}") set(_RC_FILE "${rc_path}/${_RC_FILE}") endif() set(_RC_DEPENDS ${_RC_DEPENDS} "${_RC_FILE}") endforeach() + unset(_RC_FILES) # Since this cmake macro is doing the dependency scanning for these files, # let's make a configured file and add it as a dependency so cmake is run # again when dependencies need to be recomputed. -- cgit v0.12