[PATCH] build: revise visibility attributes usage in autotools and cmake
Ozkan Sezer <[email protected]> Wed, 4 Jun 2025 08:28:21 +0300
| Newsgroups | gmane.comp.fonts.freetype.devel |
|---|---|
| Message-ID | <CAA2C=vDTC16O3MjiWycNpgaMPk-JpEYmCUCBAEBqfAsSuXky_w@mail.gmail.com> |
* cmake: set C_VISIBILITY_PRESET to hidden for non-windows only. windows handles exports with DLL_EXPORT defined, and old mingw toolchains emit a lot of warnings about visibility attributes not being supported in this configuration. * autotools: revise visibility attributes checks by compiling a better test program with `-Werror` in CFLAGS, so that warnings will correctly indicate unsupported configurations. Motivation for this patch was annoying warnings from my mingw toolchains with gcc 7.5 and gcc 4.5 P.S.: I don't know how to do this in meson, and it's probably not worth it. -- O.S.
0001-build-revise-visibility-attributes-usage-in-autotool.patch
(application/octet-stream, 2.3 KB)
From 0f13fc0e2ceda67c8648b05df18eddfc8bbd6103 Mon Sep 17 00:00:00 2001 From: Ozkan Sezer <[email protected]> Date: Wed, 4 Jun 2025 08:21:50 +0300 Subject: [PATCH] build: revise visibility attributes usage in autotools and cmake * cmake: set C_VISIBILITY_PRESET to hidden for non-windows only. windows handles exports with DLL_EXPORT defined, and old mingw toolchains emit a lot of warnings about visibility attributes not being supported in this configuration. * autotools: revise visibility attributes checks by compiling a better test program with `-Werror` in CFLAGS, so that warnings will correctly indicate unsupported configurations. --- CMakeLists.txt | 9 +++++---- builds/unix/configure.raw | 9 +++++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b14e813..1ae550a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -450,10 +450,6 @@ add_library(freetype ${BASE_SRCS} ) -set_target_properties( - freetype PROPERTIES - C_VISIBILITY_PRESET hidden) - target_compile_definitions( freetype PRIVATE FT2_BUILD_LIBRARY) @@ -464,6 +460,11 @@ if (WIN32) target_compile_definitions( freetype PRIVATE DLL_EXPORT) endif () +else () + # windows handles exports with DLL_EXPORT defined above. + set_target_properties( + freetype PROPERTIES + C_VISIBILITY_PRESET hidden) endif () if (BUILD_SHARED_LIBS) diff --git a/builds/unix/configure.raw b/builds/unix/configure.raw index f18c8a0..03d8206 100644 --- a/builds/unix/configure.raw +++ b/builds/unix/configure.raw @@ -239,9 +239,14 @@ AC_SUBST([XX_ANSIFLAGS]) found_visibility_flag=no AC_MSG_CHECKING([for -fvisibility=hidden compiler flag]) orig_CFLAGS="${CFLAGS}" -CFLAGS="${CFLAGS} -fvisibility=hidden" -AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])], +CFLAGS="${CFLAGS} -fvisibility=hidden -Werror" +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([ +__attribute__((visibility("default"))) int foo(void); +__attribute__((visibility("hidden"))) int bar(void); +int foo(void) { return 0; } +int bar(void) { return 1; }], [])], [found_visibility_flag=yes + CFLAGS="${orig_CFLAGS} -fvisibility=hidden" AC_MSG_RESULT(yes)], [CFLAGS="${orig_CFLAGS}" AC_MSG_RESULT(no)]) -- 1.7.1