Skip to content

Commit 064bd78

Browse files
donny-dontaperezdc
authored andcommitted
Allow libwpe to be built statically
In the case where there will only ever be one WPE backend implemented for a platform the dynamic loading capabilities aren't needed. In this case allow the library to built statically. By convention a WPE backend sets `_wpe_loader_interface` so that is used as the name for the `wpe_loader_interface`. For CMake builds set `BUILD_SHARED_LIBS` to `OFF`. For Meson builds set `default_library` to `static`.
1 parent d2525f9 commit 064bd78

File tree

3 files changed

+85
-13
lines changed

3 files changed

+85
-13
lines changed

CMakeLists.txt

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ calculate_library_versions_from_libtool_triple(LIBWPE 6 0 5)
1919

2020
project(libwpe VERSION "${PROJECT_VERSION}")
2121

22+
set(BUILD_SHARED_LIBS
23+
ON
24+
CACHE BOOL "Build libwpe as a shared library"
25+
)
2226
set(WPE_BACKEND
2327
""
2428
CACHE STRING "Name of the backend library to load, instead of libWPEBackend-default.so"
@@ -71,10 +75,9 @@ set(WPE_PUBLIC_HEADERS
7175
)
7276

7377
add_library(
74-
wpe SHARED
78+
wpe
7579
src/input-xkb.c
7680
src/key-unicode.c
77-
src/loader.c
7881
src/pasteboard.c
7982
src/pasteboard-generic.cpp
8083
src/pasteboard-noop.cpp
@@ -83,6 +86,23 @@ add_library(
8386
src/version.c
8487
src/view-backend.c
8588
)
89+
90+
if (BUILD_SHARED_LIBS)
91+
target_sources(wpe PRIVATE src/loader.c)
92+
93+
set_target_properties(
94+
wpe
95+
PROPERTIES
96+
C_VISIBILITY_PRESET hidden
97+
CXX_VISIBILITY_PRESET hidden
98+
OUTPUT_NAME wpe-${WPE_API_VERSION}
99+
VERSION ${LIBWPE_VERSION}
100+
SOVERSION ${LIBWPE_VERSION_MAJOR}
101+
)
102+
else ()
103+
target_sources(wpe PRIVATE src/loader-static.c)
104+
endif ()
105+
86106
target_include_directories(
87107
wpe PRIVATE "include" "src" $<TARGET_PROPERTY:GL::egl,INTERFACE_INCLUDE_DIRECTORIES>
88108
)
@@ -105,16 +125,6 @@ if (WPE_ENABLE_XKB)
105125
set(WPE_PC_REQUIRES xkbcommon)
106126
endif ()
107127

108-
set_target_properties(
109-
wpe
110-
PROPERTIES
111-
C_VISIBILITY_PRESET hidden
112-
CXX_VISIBILITY_PRESET hidden
113-
OUTPUT_NAME wpe-${WPE_API_VERSION}
114-
VERSION ${LIBWPE_VERSION}
115-
SOVERSION ${LIBWPE_VERSION_MAJOR}
116-
)
117-
118128
install(
119129
TARGETS wpe
120130
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}

meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,14 @@ endif
9393
libwpe = library('wpe-' + api_version,
9494
'src/input-xkb.c',
9595
'src/key-unicode.c',
96-
'src/loader.c',
9796
'src/pasteboard.c',
9897
'src/pasteboard-generic.cpp',
9998
'src/pasteboard-noop.cpp',
10099
'src/renderer-backend-egl.c',
101100
'src/renderer-host.c',
102101
'src/version.c',
103102
'src/view-backend.c',
103+
get_option('default_library') == 'shared' ? 'src/loader.c' : 'src/loader-static.c',
104104
install: true,
105105
dependencies: dependencies,
106106
version: soversion,

src/loader-static.c

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright (C) 2022 Igalia S.L.
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions
7+
* are met:
8+
* 1. Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
* 2. Redistributions in binary form must reproduce the above copyright
11+
* notice, this list of conditions and the following disclaimer in the
12+
* documentation and/or other materials provided with the distribution.
13+
*
14+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
17+
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
18+
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
20+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25+
*/
26+
27+
#include "loader-private.h"
28+
29+
#include <stdio.h>
30+
#include <stdlib.h>
31+
32+
extern struct wpe_loader_interface* _wpe_loader_interface;
33+
34+
bool
35+
wpe_loader_init(const char* impl_library_name)
36+
{
37+
return true;
38+
}
39+
40+
const char*
41+
wpe_loader_get_loaded_implementation_library_name(void)
42+
{
43+
#ifdef WPE_BACKEND
44+
return WPE_BACKEND;
45+
#else
46+
return NULL;
47+
#endif
48+
}
49+
50+
void*
51+
wpe_load_object(const char* object_name)
52+
{
53+
if (_wpe_loader_interface) {
54+
if (!_wpe_loader_interface->load_object) {
55+
fprintf(stderr, "wpe_load_object: failed to load object with name '%s': backend doesn't implement load_object vfunc\n", object_name);
56+
abort();
57+
}
58+
return _wpe_loader_interface->load_object(object_name);
59+
}
60+
61+
return NULL;
62+
}

0 commit comments

Comments
 (0)