[kdelibs/frameworks] tier4/kde4support/src: Check for visibility support on gcc

Aurélien Gâteau agateau at kde.org
Mon Dec 2 15:23:05 UTC 2013


On Sun, 01 Dec 2013 10:29:03 +0100, David Faure wrote:
> On Thursday 28 November 2013 17:03:04 Aurélien Gâteau wrote:
>> Git commit 3bc8af3ec4477b5ff7acedd74b27d0d359e8bd1f by Aurélien 
>> Gâteau.
>> Committed on 28/11/2013 at 17:02.
>> Pushed by gateau into branch 'frameworks'.
>>
>> Check for visibility support on gcc
>>
>> __KDE_HAVE_GCC_VISIBILITY was not defined in kdemacros.h.cmake, 
>> causing
>> KDE_EXPORT and KDE_IMPORT to be no-ops, breaking builds of 
>> kde-runtime,
>> kde-workspace and friends.
>>
>> Don't know what to do for other compilers.
>
> Looking at FindKDE4Internal.cmake in master, where this originally
> comes from,
> you need two more things:
> * setting it to TRUE for Clang.
> * actually passing the flag (-fvisibility=hidden) to the compiler !

Oups, good point :)

> Interestingly tier1/kjs/src/kjs/CMakeLists.txt has another solution: 
> running
> the test for all compilers. It also forgets to pass the flag to the
> compiler,
> though.
>
> In fact, with the gcc version we require now, we might not even need 
> to run
> this test, we could just set the flag? Then this can just become:
>
> if (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL 
> "Clang")
>   set(__KDE_HAVE_GCC_VISIBILITY TRUE)
>   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
> endif()
>
> An alternative is the more feature-based approach, to support any 
> gcc-like
> compiler automatically (e.g. icc?)
>
> check_cxx_compiler_flag(-fvisibility=hidden 
> __KDE_HAVE_GCC_VISIBILITY)
> if ( __KDE_HAVE_GCC_VISIBILITY)
>   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
> endif()
>
> [in which case we could also replace GCC with COMPILER....]

I choose your second solution, but I kept the __KDE_HAVE_GCC_VISIBILITY
define. Since this code is in the KDE4Support framework, I think it
makes more sense to keep defines as close as possible to what was
available in KDE4, even if code using the __KDE_HAVE_GCC_VISIBILITY is
probably doing something wrong :)

Aurélien



More information about the Kde-frameworks-devel mailing list