[CMake] Eclipse generator - basic macros
Benjamin Schindler
bschindler at inf.ethz.ch
Wed Jul 15 02:42:57 EDT 2009
Hei, thanks for the thorough review and hints. I'll surely apply them
Thanks
Benjamin
Hendrik Sattler wrote:
> Zitat von Benjamin Schindler <bschindler at inf.ethz.ch>:
>> I'm working on a project which builds both on linux and windows. I
>> generated an eclipse project out of it which works basically fine but
>> it's not able to recognize i.e. the __GNUC__ macro (and probably any
>> other macro defined per default on gcc) are not recognized by eclipse.
>> That means that by using a header like:
>>
>> #if defined(_MSC_VER) && (_MSC_VER >= 1300)
>> #ifdef FLOW_DLL_EXPORT
>> #define FLOW_DLL _declspec(dllexport)
>> #else
>> #define FLOW_DLL _declspec(dllimport)
>> #endif
>> #else
>> #ifdef __GNUC__
>> #define FLOW_DLL
>> #endif
>> #endif
>
> I know that it's unrelated to your question but this code is slightly
> wrong.
> For the windows version of gcc, it also understands the _declspec()
> thing. You don't make it compiler-specific but system-specific.
> Additionally, on non-windows systems, you can use the visibility
> attribute to achieve something similar.
> That's why the gcc people suggest the following at
> http://gcc.gnu.org/wiki/Visibility (I simplified it):
> #if defined _WIN32 || defined __CYGWIN__
> #ifdef FLOW_DLL_EXPORT
> #define FLOW_DLL __declspec(dllexport)
> #else
> #define FLOW_DLL __declspec(dllimport)
> #endif
> #elif __GNUC__ >= 4
> #define FLOW_DLL __attribute__ ((visibility("default")))
> #define DLL_LOCAL __attribute__ ((visibility("hidden")))
> #endif
> #ifndef FLOW_DLL
> #define FLOW_DLL
> #endif
> #ifndef DLL_LOCAL
> #define DLL_LOCAL
> #endif
>
> You only need to add -fvisibility=hidden to gcc command line on
> non-windows systems.
> The above still has the flaw you use _declspec(dllimport) when
> compiling the library as static library. That's ok if you don't intend
> to do so else easy to fix.
>
> Additionally, eclipse may not select the right choice but the macros
> will not error out as they are _always_ defined in some way.
>
> Have fun
>
> HS
>
>
> _______________________________________________
> 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