[CMake] Function for visibility definitions

Mike Jackson mike.jackson at bluequartz.net
Thu Feb 11 02:26:27 EST 2010


And what happens when a project wants to use my library? That project  
must now use Cmake and your macro. What if a project downstream can  
not use Cmake to define those macros? What then?

Mike Jackson

On Feb 11, 2010, at 2:04, Hilton Medeiros <medeiros.hilton at gmail.com>  
wrote:

> Hello Christian,
>
> thanks for the interest, let me explain:
>
> ## In your CMake file you could to do this:
> ...
> include (VisibilityDefinitions)
> add_visibility_definitions(PREFIX PROJECT)
> ...
> ##
>
> // In your project source, this:
> ...
> class PROJECT_EXPORTS ExampleClass {...};
> ...
> //
>
> It is really simple, the function will just add these
> definitions, through CMake of course, in compile time like this:
>
> g++ -DPROJECT_EXPORTS=__attribute__((visibility("default")))
>    -DPROJECT_PRIVATE=__attribute__((visibility("hidden")))
>    src/ExampleClass.cpp
>
> But of course you won't see anything like this while compiling because
> CMake shows only:
> "Building CXX object CMakeFiles/example.dir/src/ExampleClass.cpp.o"
>
> Also, by the signature of the function you could custom these
> definitions just like you want them, like this:
>
> add_visibility_definitions(PREFIX _MyLib
>                           EXPORT_SUFFIX Export
>                           PRIVATE_SUFFIX Private)
>
> And in your source code:
>
> class _MyLibExports ExampleClass {...};
> class _MyLibPrivate ExampleClass {...};
>
> Kind regards,
> Hilton
>
> On Thu, 11 Feb 2010 07:41:32 +0100
> Christian Ehrlicher <Ch.Ehrlicher at gmx.de> wrote:
>> Hilton Medeiros schrieb:
>>> Thanks for pointing that mistake, I fixed it.
>>>
>>> About g++: g++ is gcc with -lstdc++
>>>
>>> What is wrong with a simple CMake file?
>>> I know what is good about it, if CMake had it built in
>>> neither me nor any CMake user would need to write neither a simple
>>> header file nor a simple CMake file.
>>>
>> I don't see how this should work without a header file. How should i
>> use those defines in my source at all?
>> The better have a simple header-file...
>>
>>
>> Christian
>>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake


More information about the CMake mailing list