Here is the code:
I have found and implemented a solution that can extract data from a header file
with the "help" from evaluation of regular expressions.
file(STRINGS "${CPPCHECK_SOURCE_DIR}/lib/library_version.h"
CPPCHECK_BUILD_SPECIFICATION REGEX "^[ \t]*#define[
\t]+CPPCHECK_LIBRARY_VERSION_[A-Z]+[ \t]+[0-9]+.*$")
if(CPPCHECK_BUILD_SPECIFICATION)
message(STATUS "${CPPCHECK_BUILD_SPECIFICATION}")
foreach(item IN ITEMS MAJOR MINOR PATCH)
string(REGEX REPLACE ".*#define[ \t]+CPPCHECK_LIBRARY_VERSION_${item}[
\t]+([0-9]+).*"
"\\1" XYZ ${CPPCHECK_BUILD_SPECIFICATION})
set("CPPCHECK_BUILD_VERSION_${item}" ${XYZ} CACHE STRING "Version number
for the build of the Cppcheck software")
endforeach()
else()
message(FATAL_ERROR "Data were not found for the required build
specification.")
endif()
How do you think about any optimisation opportunities like it is mentioned in
the feature request "Directly reading data from a file into variables"?
http://public.kitware.com/Bug/view.php?id=11714
Regards,
Markus
_______________________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
Please keep messages on-topic and check the CMake FAQ at:
http://www.cmake.org/Wiki/CMake_FAQ
Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake