hidden visibility

Alexander Neundorf neundorf at kde.org
Fri Feb 17 17:31:58 UTC 2012


On Friday 17 February 2012, Stephen Kelly wrote:
> Alexander Neundorf wrote:
> > Hi Stephen,
> > 
> > with your export header stuff you did for cmake 2.8.7, you must have done
> > a lot with the symbol visibility stuff.
> > 
> > Is there now a cmake module which I can use to check whether visibility
> > is supported by the current compiler ?
> 
> The current implementation is there since 2.8.6 in
> Modules/GenerateExportHeader.cmake.
> 
> COMPILER_HAS_HIDDEN_VISIBILITY
> 
> is true if it has visibility.
> 
> USE_COMPILER_HIDDEN_VISIBILITY
> 
> is an option the user can set to disable using it (default ON).

In FindKDE4Internal.cmake we also have checks for visibility support:

set(_GCC_COMPILED_WITH_BAD_ALLOCATOR FALSE)
exec_program(${CMAKE_C_COMPILER} ARGS ${CMAKE_C_COMPILER_ARG1} -v
                                OUTPUT_VARIABLE _gcc_alloc_info)
string(REGEX MATCH "(--enable-libstdcxx-allocator=mt)"
             _GCC_COMPILED_WITH_BAD_ALLOCATOR "${_gcc_alloc_info}")

if (__KDE_HAVE_GCC_VISIBILITY AND NOT _GCC_COMPILED_WITH_BAD_ALLOCATOR
                              AND NOT WIN32)
   set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
   set (KDE4_C_FLAGS "-fvisibility=hidden")

...some Qt related check

    set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=return-type
                                             -fvisibility-inlines-hidden")

else()
...


It would be nice if we could get rid of this code, and use what is in 
GenerateExportHeader.cmake instead.

Can you maybe refactor GenerateExportHeader.cmake a bit so that I could do 
something like

check_visibility_support(success_var flag_var)

which returns TRUE/FALSE in success_var and the flag for the current compiler 
in flag_var ?

I'm not quite sure in the code above in which cases there is a "bad 
allocator", and whether "-Werror=return-type -fvisibility-inlines-hidden" is 
something everybody should do or not.

Alex


More information about the Kde-buildsystem mailing list