mirror of
https://gitlab.freedesktop.org/dbus/dbus.git
synced 2026-05-05 16:58:00 +02:00
Let cmake retrieve version and variable information from meson build system
Signed-off-by: Ralf Habacker <ralf.habacker@freenet.de>
This commit is contained in:
parent
dbb4e0ea90
commit
e665f96c76
5 changed files with 83 additions and 206 deletions
|
|
@ -3,40 +3,33 @@ cmake_minimum_required(VERSION 3.9)
|
|||
# we do not need to have WIN32 defined
|
||||
set(CMAKE_LEGACY_CYGWIN_WIN32 0)
|
||||
|
||||
project(dbus)
|
||||
|
||||
# where to look first for cmake modules, before ${CMAKE_ROOT}/Modules/ is checked
|
||||
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
|
||||
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/modules")
|
||||
|
||||
option(DBUS_BUILD_TESTS "enable unit test code" ON)
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
|
||||
|
||||
# detect version
|
||||
include(MacrosAutotools)
|
||||
autoinit(configure.ac)
|
||||
autoversion(dbus)
|
||||
include(MacrosMeson)
|
||||
meson_init(meson.build)
|
||||
meson_version(dbus)
|
||||
set(DBUS_PATCH_VERSION 0)
|
||||
set(VERSION "${DBUS_VERSION}")
|
||||
|
||||
if(WIN32)
|
||||
set(LANGUAGES C CXX)
|
||||
else()
|
||||
set(LANGUAGES C)
|
||||
endif()
|
||||
project(dbus
|
||||
VERSION ${DBUS_VERSION}
|
||||
LANGUAGES C CXX
|
||||
)
|
||||
|
||||
option(DBUS_BUILD_TESTS "enable unit test code" ON)
|
||||
|
||||
# replacement for AC_C_BIGENDIAN
|
||||
include (TestBigEndian)
|
||||
test_big_endian(WORDS_BIGENDIAN)
|
||||
|
||||
if(EXISTS ${PROJECT_SOURCE_DIR}/config.h.in)
|
||||
autoheaderchecks(${PROJECT_SOURCE_DIR}/config.h.in ${PROJECT_SOURCE_DIR}/cmake/ConfigureChecks.cmake ${PROJECT_SOURCE_DIR}/cmake/config.h.cmake)
|
||||
else()
|
||||
message(STATUS "Generate config.h.in with autogen.sh to enable cmake header difference check.")
|
||||
endif()
|
||||
|
||||
# used by file version info
|
||||
set(DBUS_PATCH_VERSION "0")
|
||||
|
||||
# set PACKAGE_... variables
|
||||
autopackage(
|
||||
dbus
|
||||
${DBUS_VERSION_STRING}
|
||||
"http://dbus.freedesktop.org"
|
||||
"https://gitlab.freedesktop.org/dbus/dbus/issues"
|
||||
)
|
||||
|
||||
include(Macros)
|
||||
string(TIMESTAMP DBUS_BUILD_TIMESTAMP "%Y%m%d%H%M" UTC)
|
||||
set(BUILD_FILEVERSION ${DBUS_MAJOR_VERSION},${DBUS_MINOR_VERSION},${DBUS_MICRO_VERSION},${DBUS_PATCH_VERSION})
|
||||
|
|
@ -111,6 +104,7 @@ set(BUILD_SHARED_LIBS ON)
|
|||
set(INSTALL_TARGETS_DEFAULT_ARGS EXPORT DBus1Targets RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
|
||||
if(CYGWIN)
|
||||
# TODO cygwin is not using WIN32 api
|
||||
set(WIN32)
|
||||
endif()
|
||||
|
||||
|
|
@ -381,8 +375,9 @@ if(UNIX AND NOT DBUS_DISABLE_ASSERT)
|
|||
endif()
|
||||
|
||||
if(DBUS_WITH_GLIB)
|
||||
autodefine(GLIB_VERSION_MIN_REQUIRED)
|
||||
autodefine(GLIB_VERSION_MAX_ALLOWED)
|
||||
# keep in sync with meson.build
|
||||
set(GLIB_VERSION_MIN_REQUIRED GLIB_VERSION_2_38)
|
||||
set(GLIB_VERSION_MAX_ALLOWED "G_ENCODE_VERSION(2,44)")
|
||||
endif()
|
||||
|
||||
string(APPEND CMAKE_C_FLAGS_DEBUG " -D_DEBUG")
|
||||
|
|
@ -674,10 +669,10 @@ set(DBUS_INTERNAL_LIBRARIES dbus-internal)
|
|||
set(DBUS_INTERNAL_ADD_LIBRARY_OPTIONS STATIC)
|
||||
set(DBUS_INTERNAL_CLIENT_DEFINITIONS "-DDBUS_COMPILATION")
|
||||
|
||||
configure_file(cmake/config.h.cmake ${PROJECT_BINARY_DIR}/config.h )
|
||||
configure_file(cmake/config.h.cmake ${PROJECT_BINARY_DIR}/config.h)
|
||||
|
||||
if(WIN32)
|
||||
configure_file(cmake/dbus-env.bat.cmake ${PROJECT_BINARY_DIR}/bin/dbus-env.bat )
|
||||
configure_file(cmake/dbus-env.bat.cmake ${PROJECT_BINARY_DIR}/bin/dbus-env.bat)
|
||||
install(FILES ${PROJECT_BINARY_DIR}/bin/dbus-env.bat DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
endif()
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
#ifndef _DBUS_CONFIG_H
|
||||
#define _DBUS_CONFIG_H
|
||||
|
||||
#cmakedefine VERSION "@VERSION@"
|
||||
|
||||
/* On Windows, we expect to be using msvcrt.dll-compatible printf
|
||||
* (%I64u instead of %llu) unless otherwise specified. This must be
|
||||
* done near the beginning of config.h, before we have included any
|
||||
|
|
@ -11,14 +13,6 @@
|
|||
# define __USE_MINGW_ANSI_STDIO 0
|
||||
#endif
|
||||
|
||||
@AUTOPACKAGE_CONFIG_H_TEMPLATE@
|
||||
|
||||
/*
|
||||
* Variables defined by AC_DEFINE in ../configure.ac
|
||||
* should be placed in this file
|
||||
*/
|
||||
|
||||
/* AC_C_BIGENDIAN */
|
||||
#cmakedefine WORDS_BIGENDIAN
|
||||
|
||||
/* Opt-in to modern APIs and thread-safety for Solaris. In the Autotools
|
||||
|
|
|
|||
|
|
@ -1,168 +0,0 @@
|
|||
#
|
||||
# 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
|
||||
#
|
||||
# returns
|
||||
# ${prefix}_VERSION
|
||||
# ${prefix}_VERSION_STRING
|
||||
# ${prefix}_MAJOR_VERSION
|
||||
# ${prefix}_MINOR_VERSION
|
||||
# ${prefix}_MICRO_VERSION
|
||||
# ${prefix}_LIBRARY_AGE
|
||||
# ${prefix}_LIBRARY_REVISION
|
||||
# ${prefix}_LIBRARY_CURRENT
|
||||
#
|
||||
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()
|
||||
|
||||
#
|
||||
# Defines package related variables (PACKAGE_..., PACKAGE and VERSION)
|
||||
# as done by autotools.
|
||||
#
|
||||
# Additional it defines a cmake variable named PACKAGE_CONFIG_H_TEMPLATE
|
||||
# which could be placed in config.h templates to have those variables
|
||||
# defined at code level like shown below:
|
||||
#
|
||||
# config.h.template
|
||||
# ...
|
||||
# @AUTOPACKAGE_CONFIG_H_TEMPLATE@
|
||||
# ...
|
||||
#
|
||||
macro(autopackage name version url support_url)
|
||||
# Define to the full name of this package.
|
||||
set(PACKAGE_NAME ${name})
|
||||
|
||||
# Define to the version of this package.
|
||||
set(PACKAGE_VERSION ${version})
|
||||
|
||||
# Define to the home page for this package.
|
||||
set(PACKAGE_URL ${url})
|
||||
|
||||
# Define to the address where bug reports for this package should be sent.
|
||||
set(PACKAGE_BUGREPORT ${support_url})
|
||||
|
||||
# Define to the full name and version of this package.
|
||||
set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
|
||||
|
||||
# Define to the one symbol short name of this package.
|
||||
set(PACKAGE_TARNAME ${PACKAGE_NAME})
|
||||
|
||||
set(PACKAGE ${name})
|
||||
set(VERSION ${DBUS_VERSION_STRING})
|
||||
|
||||
string(CONFIGURE "/* generated by cmake macro autopackage */\n
|
||||
/* Define to the address where bug reports for this package should be sent. */
|
||||
#define PACKAGE_BUGREPORT \"@PACKAGE_BUGREPORT@\"
|
||||
|
||||
/* Define to the full name of this package. */
|
||||
#define PACKAGE_NAME \"@PACKAGE_NAME@\"
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#define PACKAGE_STRING \"@PACKAGE_STRING@\"
|
||||
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#define PACKAGE_TARNAME \"@PACKAGE_TARNAME@\"
|
||||
|
||||
/* Define to the home page for this package. */
|
||||
#define PACKAGE_URL \"@PACKAGE_URL@\"
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#define PACKAGE_VERSION \"@PACKAGE_VERSION@\"
|
||||
|
||||
/* defined by autotools package */
|
||||
#define PACKAGE \"@PACKAGE@\"
|
||||
#define VERSION \"@VERSION@\"
|
||||
" AUTOPACKAGE_CONFIG_H_TEMPLATE)
|
||||
endmacro()
|
||||
|
||||
#
|
||||
# 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()
|
||||
|
||||
macro(autoheaderchecks config_h_in configure_checks_file config_h_cmake)
|
||||
file(READ ${configure_checks_file} configure_checks_file_raw)
|
||||
file(READ ${config_h_in} _config_h_in_raw)
|
||||
file(READ ${config_h_cmake} _config_h_cmake_raw)
|
||||
string(REGEX REPLACE ";" "\\\\;" _config_h_in "${_config_h_in_raw}")
|
||||
string(REGEX REPLACE "\n" ";" _config_h_in "${_config_h_in}")
|
||||
foreach(line ${_config_h_in})
|
||||
#message(STATUS ${line})
|
||||
if(line MATCHES ".*HAVE_.*_H.*")
|
||||
string(REGEX REPLACE ".*HAVE_(.*)_H.*" "\\1" key ${line})
|
||||
set(full_key "HAVE_${key}_H")
|
||||
if(key MATCHES ".*_.*")
|
||||
string(REGEX MATCH "^[A-Z0-9]+" dir ${key})
|
||||
string(REGEX MATCH "[A-Z0-9]+$" file ${key})
|
||||
string(TOLOWER ${dir} dirname)
|
||||
string(TOLOWER ${file} filename)
|
||||
set(check "check_include_file(${dirname}/${filename}.h ${full_key})")
|
||||
set(config_define "#cmakedefine ${full_key}")
|
||||
else()
|
||||
set(file ${key})
|
||||
string(TOLOWER ${file} filename)
|
||||
set(check "check_include_file(${filename}.h ${full_key})")
|
||||
set(config_define "#cmakedefine ${full_key}")
|
||||
endif()
|
||||
if(NOT configure_checks_file_raw MATCHES ".*${full_key}.*")
|
||||
message("${check}")
|
||||
endif()
|
||||
if(NOT _config_h_cmake_raw MATCHES "${full_key}")
|
||||
message("${config_define}")
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
endmacro()
|
||||
|
||||
#
|
||||
# parses config.h template and create cmake equivalent
|
||||
# not implemented yet
|
||||
#
|
||||
macro(autoconfig template output)
|
||||
file(READ ${template} contents)
|
||||
# Convert file contents into a CMake list (where each element in the list
|
||||
# is one line of the file)
|
||||
string(REGEX REPLACE ";" "\\\\;" contents "${contents}")
|
||||
string(REGEX REPLACE "\n" ";" contents "${contents}")
|
||||
foreach(line contents)
|
||||
message(STATUS ${line})
|
||||
# find #undef lines
|
||||
# append to config.h #define <variable-name> <variable-content>
|
||||
endforeach()
|
||||
endmacro()
|
||||
52
cmake/modules/MacrosMeson.cmake
Normal file
52
cmake/modules/MacrosMeson.cmake
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
#
|
||||
# cmake package for meson support
|
||||
#
|
||||
# SPDX-FileCopyrightText: © 2023 Ralf Habacker
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
#
|
||||
# load meson build file into an internal list named _meson_build
|
||||
#
|
||||
macro(meson_init config)
|
||||
set(_meson_build_name ${config})
|
||||
file(READ ${config} _meson_build_raw)
|
||||
# Convert file contents into a CMake list (where each element in the list
|
||||
# is one line of the file)
|
||||
string(REGEX REPLACE ";" "\\\\;" _meson_build "${_meson_build_raw}")
|
||||
string(REGEX REPLACE "\n" ";" _meson_build "${_meson_build}")
|
||||
endmacro()
|
||||
|
||||
# extracts version information from autoconf config file
|
||||
# and set related cmake variables
|
||||
#
|
||||
# returns
|
||||
# ${prefix}_VERSION
|
||||
# ${prefix}_VERSION_STRING
|
||||
# ${prefix}_MAJOR_VERSION
|
||||
# ${prefix}_MINOR_VERSION
|
||||
# ${prefix}_MICRO_VERSION
|
||||
# ${prefix}_LIBRARY_AGE
|
||||
# ${prefix}_LIBRARY_REVISION
|
||||
# ${prefix}_LIBRARY_CURRENT
|
||||
#
|
||||
macro(meson_version prefix)
|
||||
set(WS "[ \t\r\n]")
|
||||
string(TOUPPER ${prefix} prefix_upper)
|
||||
string(REGEX REPLACE ".*${WS}version:${WS}*'([0-9.]+)'.*" "\\1" ${prefix_upper}_VERSION ${_meson_build_raw})
|
||||
string(REPLACE "." ";" VERSION_LIST ${${prefix_upper}_VERSION})
|
||||
list(GET VERSION_LIST 0 ${prefix_upper}_MAJOR_VERSION)
|
||||
list(GET VERSION_LIST 1 ${prefix_upper}_MINOR_VERSION)
|
||||
list(GET VERSION_LIST 2 ${prefix_upper}_MICRO_VERSION)
|
||||
set(${prefix_upper}_VERSION_STRING "${${prefix_upper}_VERSION}")
|
||||
string(REGEX REPLACE ".*${WS}lt_age${WS}*=${WS}*([0-9]+).*" "\\1" ${prefix_upper}_LIBRARY_AGE ${_meson_build_raw})
|
||||
string(REGEX REPLACE ".*${WS}lt_current${WS}*=*${WS}*([0-9]+).*" "\\1" ${prefix_upper}_LIBRARY_CURRENT ${_meson_build_raw})
|
||||
string(REGEX REPLACE ".*${WS}lt_revision${WS}*=${WS}*([0-9]+).*" "\\1" ${prefix_upper}_LIBRARY_REVISION ${_meson_build_raw})
|
||||
message(STATUS "fetched variable from meson.build - ${prefix_upper}_VERSION = ${${prefix_upper}_VERSION} ")
|
||||
message(STATUS "fetched variable from meson.build - ${prefix_upper}_VERSION_STRING = ${${prefix_upper}_VERSION_STRING} ")
|
||||
message(STATUS "fetched variable from meson.build - ${prefix_upper}_MAJOR_VERSION = ${${prefix_upper}_MAJOR_VERSION} ")
|
||||
message(STATUS "fetched variable from meson.build - ${prefix_upper}_MINOR_VERSION = ${${prefix_upper}_MINOR_VERSION} ")
|
||||
message(STATUS "fetched variable from meson.build - ${prefix_upper}_MICRO_VERSION = ${${prefix_upper}_MICRO_VERSION} ")
|
||||
message(STATUS "fetched variable from meson.build - ${prefix_upper}_LIBRARY_AGE = ${${prefix_upper}_LIBRARY_AGE} ")
|
||||
message(STATUS "fetched variable from meson.build - ${prefix_upper}_LIBRARY_REVISION = ${${prefix_upper}_LIBRARY_REVISION}")
|
||||
message(STATUS "fetched variable from meson.build - ${prefix_upper}_LIBRARY_CURRENT = ${${prefix_upper}_LIBRARY_CURRENT} ")
|
||||
endmacro()
|
||||
|
|
@ -61,6 +61,9 @@ config.set_quoted('DBUS_DAEMON_NAME', 'dbus-daemon')
|
|||
###############################################################################
|
||||
# libtool versioning - this applies to libdbus
|
||||
# http://sources.redhat.com/autobook/autobook/autobook_91.html#SEC91
|
||||
#
|
||||
# These variables are parsed automatically by cmake/modules/MacrosMeson.cmake,
|
||||
# be careful if changing the formatting
|
||||
|
||||
## increment if the interface has additions, changes, removals.
|
||||
lt_current = 40
|
||||
|
|
@ -804,6 +807,7 @@ config.set('DBUS_DISABLE_CHECKS', not checks ? 1 : false)
|
|||
config.set('G_DISABLE_CHECKS', not checks ? 1 : false)
|
||||
config.set('HAVE_GIO_UNIX', have_gio_unix ? 1 : false)
|
||||
# Ignore post-2.38 deprecations, prevent use of post-2.44 APIs.
|
||||
# keep in sync with CMakeLists.txt
|
||||
config.set('GLIB_VERSION_MIN_REQUIRED', 'GLIB_VERSION_2_38')
|
||||
config.set('GLIB_VERSION_MAX_ALLOWED', 'G_ENCODE_VERSION(2,44)')
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue