Skip to content

Commit 0447b7a

Browse files
committed
Avoid generated version headers
Use a fixed libwpe-version.h header which contains #defines for the version numbers only, which is the location where the canonical version is read by the build systems, and also used by then get used by both version.h and version-deprecated.h This avoids needing to use relative #include paths, which continued being a pitfall even after the recent improvements due to the mixup of headers with the same name (and relative path!) in the preprocessor search path e.g. wpe/version.h from WPEBackend-fdo.
1 parent 4090947 commit 0447b7a

File tree

10 files changed

+71
-45
lines changed

10 files changed

+71
-45
lines changed

CMakeLists.txt

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ cmake_policy(VERSION 3.0)
44
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
55
include(VersioningUtils)
66

7-
SET_PROJECT_VERSION(1 9 1)
7+
READ_VERSION_HEADER("" "WPE_[A-Z]+_VERSION" "${CMAKE_SOURCE_DIR}/include/wpe/libwpe-version.h")
8+
SET_PROJECT_VERSION(${WPE_MAJOR_VERSION} ${WPE_MINOR_VERSION} ${WPE_MICRO_VERSION})
89
set(WPE_API_VERSION "1.0")
910

1011
# Before making a release, the LT_VERSION string should be modified.
@@ -41,19 +42,16 @@ foreach (cflag -Wall)
4142
endif ()
4243
endforeach ()
4344

44-
set(DERIVED_SOURCES_DIR "${CMAKE_BINARY_DIR}/DerivedSources/wpe")
45-
configure_file(include/wpe/version.h.cmake ${DERIVED_SOURCES_DIR}/version.h @ONLY)
46-
configure_file(include/wpe/version-deprecated.h.cmake ${DERIVED_SOURCES_DIR}/version-deprecated.h @ONLY)
47-
4845
include(DistTargets)
4946
include(GNUInstallDirs)
5047

5148
find_package(EGL REQUIRED)
5249
find_package(Libxkbcommon REQUIRED)
5350

5451
set(WPE_PUBLIC_HEADERS
55-
${DERIVED_SOURCES_DIR}/version.h
56-
${DERIVED_SOURCES_DIR}/version-deprecated.h
52+
include/wpe/libwpe-version.h
53+
include/wpe/version.h
54+
include/wpe/version-deprecated.h
5755
include/wpe/export.h
5856
include/wpe/input.h
5957
include/wpe/keysyms.h
@@ -81,7 +79,6 @@ add_library(wpe SHARED
8179
target_include_directories(wpe PRIVATE
8280
"include"
8381
"src"
84-
${DERIVED_SOURCES_DIR}/..
8582
$<TARGET_PROPERTY:GL::egl,INTERFACE_INCLUDE_DIRECTORIES>
8683
)
8784
target_compile_definitions(wpe PRIVATE
@@ -145,10 +142,8 @@ IF(BUILD_DOCS)
145142
--sitemap=${CMAKE_SOURCE_DIR}/docs/sitemap.txt
146143
--output=${CMAKE_CURRENT_BINARY_DIR}/Documentation/
147144
--c-sources "${CMAKE_SOURCE_DIR}/include/wpe/*.h"
148-
"${DERIVED_SOURCES_DIR}/version.h"
149-
"${DERIVED_SOURCES_DIR}/version-deprecated.h"
150145
--extra-c-flags=-DWPE_COMPILATION=1
151-
--c-include-directories ${CMAKE_SOURCE_DIR}/include ${DERIVED_SOURCES_DIR}
146+
--c-include-directories ${CMAKE_SOURCE_DIR}/include
152147
--c-smart-index
153148
)
154149
ELSE()

cmake/VersioningUtils.cmake

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
function(READ_VERSION_HEADER var_prefix def_regex file_path)
2+
file(STRINGS "${file_path}" lines)
3+
foreach (line ${lines})
4+
if (line MATCHES "^#define[ \t]+(${def_regex})[ \t]+([0-9]+)$")
5+
set("${var_prefix}${CMAKE_MATCH_1}" "${CMAKE_MATCH_2}" PARENT_SCOPE)
6+
endif()
7+
endforeach()
8+
endfunction()
9+
110
macro(SET_PROJECT_VERSION major minor micro)
211
set(PROJECT_VERSION_MAJOR "${major}")
312
set(PROJECT_VERSION_MINOR "${minor}")

include/wpe/libwpe-version.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* libwpe-version.h
3+
* Copyright (C) 2021 Adrian Perez de Castro <[email protected]>
4+
*
5+
* Distributed under terms of the MIT license.
6+
*/
7+
8+
#ifndef LIBWPE_VERSION_H
9+
#define LIBWPE_VERSION_H
10+
11+
#define WPE_MAJOR_VERSION 1
12+
#define WPE_MINOR_VERSION 9
13+
#define WPE_MICRO_VERSION 1
14+
15+
#endif /* !LIBWPE_VERSION_H */

include/wpe/meson.build

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,17 @@ api_headers = [
22
'export.h',
33
'input.h',
44
'keysyms.h',
5+
'libwpe-version.h',
56
'loader.h',
67
'pasteboard.h',
78
'renderer-backend-egl.h',
89
'renderer-host.h',
10+
'version.h',
11+
'version-deprecated.h',
912
'view-backend.h',
1013
'wpe-egl.h',
1114
'wpe.h',
12-
13-
# Generated API headers.
14-
configure_file(
15-
input: 'version.h.cmake',
16-
output: 'version.h',
17-
configuration: version_info,
18-
),
19-
configure_file(
20-
input: 'version-deprecated.h.cmake',
21-
output: 'version-deprecated.h',
22-
configuration: version_info,
23-
),
2415
]
2516
install_headers(api_headers,
2617
subdir: join_paths('wpe-' + api_version, 'wpe'),
2718
)
28-
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,18 @@
3232
#define wpe_version_deprecated_h
3333

3434
#if defined(WPE_COMPILATION)
35-
#include "wpe/export.h"
35+
#include "export.h"
3636
#endif
3737

38+
#include "libwpe-version.h"
39+
3840
#ifdef __cplusplus
3941
extern "C" {
4042
#endif
4143

42-
#define WPE_BACKEND_MAJOR_VERSION (@PROJECT_VERSION_MAJOR@)
43-
#define WPE_BACKEND_MINOR_VERSION (@PROJECT_VERSION_MINOR@)
44-
#define WPE_BACKEND_MICRO_VERSION (@PROJECT_VERSION_PATCH@)
44+
#define WPE_BACKEND_MAJOR_VERSION WPE_MAJOR_VERSION
45+
#define WPE_BACKEND_MINOR_VERSION WPE_MINOR_VERSION
46+
#define WPE_BACKEND_MICRO_VERSION WPE_MICRO_VERSION
4547

4648
#define WPE_BACKEND_CHECK_VERSION(major, minor, micro) \
4749
(WPE_BACKEND_MAJOR_VERSION > (major) || \
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,15 @@
4242
*/
4343

4444
#if defined(WPE_COMPILATION)
45-
#include "wpe/export.h"
45+
#include "export.h"
4646
#endif
4747

48+
#include "libwpe-version.h"
49+
4850
#ifdef __cplusplus
4951
extern "C" {
5052
#endif
5153

52-
#define WPE_MAJOR_VERSION (@PROJECT_VERSION_MAJOR@)
53-
#define WPE_MINOR_VERSION (@PROJECT_VERSION_MINOR@)
54-
#define WPE_MICRO_VERSION (@PROJECT_VERSION_PATCH@)
55-
5654
#define WPE_CHECK_VERSION(major, minor, micro) \
5755
(WPE_MAJOR_VERSION > (major) || \
5856
(WPE_MAJOR_VERSION == (major) && WPE_MINOR_VERSION > (minor)) || \

include/wpe/wpe.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,9 @@
4141
#include "pasteboard.h"
4242
#include "renderer-host.h"
4343
#include "view-backend.h"
44-
45-
/*
46-
* The wpe/ prefix is needed for autogenerated headers to avoid
47-
* breaking building libwpe as a Meson subproject, because headers
48-
* in that case are uninstalled and will be picked from the directory
49-
* where they are generated (instead of where they are installed.)
50-
*/
51-
#include "wpe/version.h"
52-
#include "wpe/version-deprecated.h"
44+
#include "libwpe-version.h"
45+
#include "version.h"
46+
#include "version-deprecated.h"
5347

5448
#undef __WPE_H_INSIDE__
5549

meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ project('libwpe', 'cpp', 'c',
77
'cpp_std=c++11',
88
],
99
license: 'BSD-2-Clause',
10-
version: '1.9.1',
10+
version: run_command(join_paths('scripts', 'version.py')).stdout().strip(),
1111
)
1212

1313
# This refers to the API level provided. This is modified only with major,

scripts/version.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#! /usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
# vim:fenc=utf-8
4+
#
5+
# Copyright © 2021 Igalia S.L.
6+
#
7+
# Distributed under terms of the MIT license.
8+
9+
from os import environ, path
10+
import re
11+
12+
version = {}
13+
version_re = re.compile(r"^#define\s+WPE_([A-Z]+)_VERSION\s+(\d+)$")
14+
version_file = path.join(environ["MESON_SOURCE_ROOT"],
15+
"include", "wpe", "libwpe-version.h")
16+
17+
with open(version_file, "r") as f:
18+
for line in f.readlines():
19+
m = version_re.match(line)
20+
if m:
21+
version[m[1]] = m[2]
22+
23+
print("{}.{}.{}".format(version["MAJOR"], version["MINOR"], version["MICRO"]))

src/version.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2525
*/
2626

27-
#include "wpe/version.h"
28-
#include "wpe/version-deprecated.h"
27+
#include "../include/wpe/version.h"
28+
#include "../include/wpe/version-deprecated.h"
2929

3030
unsigned
3131
wpe_get_major_version(void)

0 commit comments

Comments
 (0)