[CMake] can't get compile_definitions working quite right

Christopher Harvey chris at basementcode.com
Thu Sep 4 20:24:02 EDT 2008


Hello list,

I'll just start off by pasting my CMakeLists.txt, and I'll explain the 
problem right after.

CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
ADD_LIBRARY(Portal SHARED
                          BSPWorld.cc
              Polygon3D.cc)
SET_TARGET_PROPERTIES(Portal PROPERTIES
                 COMPILE_FLAGS "-fvisibility=hidden -g"
#                            COMPILE_FLAGS "-O3"
                 LIBRARY_OUTPUT_DIRECTORY ../bin)

SET_DIRECTORY_PROPERTIES(PROPERTIES
                                   COMPILE_DEFINITIONS 
"DLLEXPORT=__attribute__ ((visibility("default")))"
                   #DLLLOCAL="__attribute__ ((visibility(\"hidden\")))")
)

Basically, I'd like to have DLLEXPORT in the source code replaced with 
__attribute__ ((visibility("default")))
when looking at the verbose output of the unix makefile I see this in 
the compile command:

 /usr/bin/c++   -D"DLLEXPORT=__attribute__ ((visibility("

I see why that's happening, but it's not what I want and I'm not sure 
what to do about it.

And the grand goal is to avoid putting this in my code:

#ifdef _MSC_VER
  #ifdef BUILDING_DLL
    #define DLLEXPORT __declspec(dllexport)
  #else
    #define DLLEXPORT __declspec(dllimport)
  #endif
  #define DLLLOCAL
#else
  #ifdef HAVE_GCCVISIBILITYPATCH
    #define DLLEXPORT __attribute__ ((visibility("default")))
    #define DLLLOCAL __attribute__ ((visibility("hidden")))
  #else
    #define DLLEXPORT
    #define DLLLOCAL
  #endif


#endif

Thanks for reading,
Chris.


More information about the CMake mailing list