From eee71285b6fdd3e6956f7dd0c83d9701aeabcf84 Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Tue, 3 Mar 2015 13:17:27 +0100 Subject: [PATCH] Keep cmake defines GLIB_VERSION_... in sync with autotools. This patch adds autotools related cmake macros autoinit() and autodefine(). Bug: https://bugs.freedesktop.org/show_bug.cgi?id=89284 --- cmake/CMakeLists.txt | 8 +++++- cmake/config.h.cmake | 4 +++ cmake/modules/MacrosAutotools.cmake | 51 +++++++++++++++++++++++++++++-------- 3 files changed, 51 insertions(+), 12 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index adc6d4b..6922129 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -15,7 +15,8 @@ endif(COMMAND cmake_policy) # detect version include(MacrosAutotools) -autoversion(../configure.ac dbus) +autoinit(../configure.ac) +autoversion(dbus) # used by file version info set (DBUS_PATCH_VERSION "0") @@ -183,6 +184,11 @@ if (UNIX AND NOT DBUS_DISABLE_ASSERT) add_definitions(-DDBUS_BUILT_R_DYNAMIC) endif (UNIX AND NOT DBUS_DISABLE_ASSERT) +if(DBUS_WITH_GLIB) + autodefine(GLIB_VERSION_MIN_REQUIRED) + autodefine(GLIB_VERSION_MAX_ALLOWED) +endif() + SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG") ######################################################################### diff --git a/cmake/config.h.cmake b/cmake/config.h.cmake index cd4720c..88c2caa 100644 --- a/cmake/config.h.cmake +++ b/cmake/config.h.cmake @@ -96,6 +96,10 @@ #cmakedefine DBUS_VA_COPY_AS_ARRAY @DBUS_VA_COPY_AS_ARRAY@ +#cmakedefine DBUS_WITH_GLIB 1 +#cmakedefine GLIB_VERSION_MIN_REQUIRED @GLIB_VERSION_MIN_REQUIRED@ +#cmakedefine GLIB_VERSION_MAX_ALLOWED @GLIB_VERSION_MAX_ALLOWED@ + // headers /* Define to 1 if you have dirent.h */ #cmakedefine HAVE_DIRENT_H 1 diff --git a/cmake/modules/MacrosAutotools.cmake b/cmake/modules/MacrosAutotools.cmake index 2b1c59d..a218db9 100644 --- a/cmake/modules/MacrosAutotools.cmake +++ b/cmake/modules/MacrosAutotools.cmake @@ -1,6 +1,21 @@ # +# cmake package for autotools support +# # @Author Ralf Habacker # + +# +# load autotools configure file into an internal list named _configure_ac +# +macro(autoinit config) + set(_configure_ac_name ${config}) + file(READ ${config} _configure_ac_raw) + # Convert file contents into a CMake list (where each element in the list + # is one line of the file) + STRING(REGEX REPLACE ";" "\\\\;" _configure_ac "${_configure_ac_raw}") + STRING(REGEX REPLACE "\n" ";" _configure_ac "${_configure_ac}") +endmacro() + # extracts version information from autoconf config file # and set related cmake variables # @@ -14,17 +29,16 @@ # ${prefix}_LIBRARY_REVISION # ${prefix}_LIBRARY_CURRENT # -macro(autoversion config prefix) - file (READ ${config} _configure_ac) - string(TOUPPER ${prefix} prefix_upper) - string (REGEX REPLACE ".*${prefix}_major_version], .([0-9]+).*" "\\1" ${prefix_upper}_MAJOR_VERSION ${_configure_ac}) - string (REGEX REPLACE ".*${prefix}_minor_version], .([0-9]+).*" "\\1" ${prefix_upper}_MINOR_VERSION ${_configure_ac}) - string (REGEX REPLACE ".*${prefix}_micro_version], .([0-9]+).*" "\\1" ${prefix_upper}_MICRO_VERSION ${_configure_ac}) - set (${prefix_upper}_VERSION ${${prefix_upper}_MAJOR_VERSION}.${${prefix_upper}_MINOR_VERSION}.${${prefix_upper}_MICRO_VERSION}) - set (${prefix_upper}_VERSION_STRING "${${prefix_upper}_VERSION}") - string (REGEX REPLACE ".*LT_AGE=([0-9]+).*" "\\1" ${prefix_upper}_LIBRARY_AGE ${_configure_ac}) - string (REGEX REPLACE ".*LT_CURRENT=([0-9]+).*" "\\1" ${prefix_upper}_LIBRARY_CURRENT ${_configure_ac}) - string (REGEX REPLACE ".*LT_REVISION=([0-9]+).*" "\\1" ${prefix_upper}_LIBRARY_REVISION ${_configure_ac}) +macro(autoversion prefix) + string(TOUPPER ${prefix} prefix_upper) + string (REGEX REPLACE ".*${prefix}_major_version], .([0-9]+).*" "\\1" ${prefix_upper}_MAJOR_VERSION ${_configure_ac_raw}) + string (REGEX REPLACE ".*${prefix}_minor_version], .([0-9]+).*" "\\1" ${prefix_upper}_MINOR_VERSION ${_configure_ac_raw}) + string (REGEX REPLACE ".*${prefix}_micro_version], .([0-9]+).*" "\\1" ${prefix_upper}_MICRO_VERSION ${_configure_ac_raw}) + set (${prefix_upper}_VERSION ${${prefix_upper}_MAJOR_VERSION}.${${prefix_upper}_MINOR_VERSION}.${${prefix_upper}_MICRO_VERSION}) + set (${prefix_upper}_VERSION_STRING "${${prefix_upper}_VERSION}") + string (REGEX REPLACE ".*LT_AGE=([0-9]+).*" "\\1" ${prefix_upper}_LIBRARY_AGE ${_configure_ac_raw}) + string (REGEX REPLACE ".*LT_CURRENT=([0-9]+).*" "\\1" ${prefix_upper}_LIBRARY_CURRENT ${_configure_ac_raw}) + string (REGEX REPLACE ".*LT_REVISION=([0-9]+).*" "\\1" ${prefix_upper}_LIBRARY_REVISION ${_configure_ac_raw}) endmacro() # @@ -88,6 +102,21 @@ macro(autopackage name version url support_url) endmacro(autopackage) # +# define a cmake variable from autotools AC_DEFINE statement +# +macro(autodefine name) + foreach(line ${_configure_ac}) + if(line MATCHES ".*AC_DEFINE(.*${name}.*).*") + string (REGEX REPLACE ".*AC_DEFINE(.*).*" "\\1" value ${line}) + string (REGEX REPLACE ".*,(.*),.*" "\\1" value2 ${value}) + string (REPLACE "[" "" value3 ${value2}) + string (REPLACE "]" "" value4 ${value3}) + set(${name} ${value4}) + endif() + endforeach() +endmacro() + +# # parses config.h template and create cmake equivalent # not implemented yet # -- 1.8.4.5