[CMake] An example of DEFINE_SYMBOL please

Mike Jackson mike.jackson at imts.us
Fri Jul 11 11:40:41 EDT 2008



On Jul 11, 2008, at 11:34 AM, Mehdi Rabah wrote:

>
>
> On Thu, Jul 10, 2008 at 12:43 PM, Yuri Timenkov  
> <ytimenkov at parallels.com> wrote:
>
>
> On Monday 07 July 2008 19:59:24 Mehdi Rabah wrote:
> > Hi,
> >
> > I need to set multiple symbols in one of my target of my project.  
> I can't
> > use add_definitions because I don't want to define those variable  
> for all
> > my targets, so I tried custom properties.
> >
> > set_target_properties( target PROPERTIES DEFINE_SYMBOL  VALUE1  
> VALUE2 )
> > doesn't work : the function doesn't expect this number of variables.
> >
> > if I try :
> >
> > set( var "VALUE1 VALUE2" ).
> > set_target_properties( target PROPERTIES DEFINE_SYMBOL  ${var} )
> >
> > I get
> >
> > c1xx : fatal error C1083: 'VALUE2': No such file or directory
> >
> > I'm working with the microsoft compiler, and cmake 2.6.
> I just discovered nice feature: COMPILE_DEFINITIONS property.
> That is you can add custom defines to source files, targets or  
> directories (with
> commands set_source_files_properties, set_target_properties and
> set_directory_properties commands accordingly).
>
> Moreover, COMPILE_DEFINITIONS can be configuration-specific, like
> COMPILE_DEFINITIONS_DEBUG.
>
> Thanks,
>
> I also discovered (in the doc) that cmake automatically define the  
> targetName_EXPORTS when compiling. I didn't tried it yet but it's  
> exactly what I need.
>

Yes, when you are on Windows (MSVC and MINGW at least) AND building a  
SHARED library, then cmake will add the targetName_EXPORTS when  
compiling. It is up to you to add the proper code into a header file  
to make user of that information. An example of this would be:

//////////////////////////////////////////////////////////////////////// 
///////
//
//  Copyright (c) 2007, mjackson
//  All rights reserved.
//  BSD License: http://www.opensource.org/licenses/bsd-license.html
//
//  This code was written under United States Air Force Contract number
//                           FA8650-04-C-5229
//
//////////////////////////////////////////////////////////////////////// 
///////
#ifndef _MXA_DLL_EXPORT_H_
#define _MXA_DLL_EXPORT_H_

/* Cmake will define MXADataModel_EXPORTS on Windows when it
configures to build a shared library. If you are going to use
another build system on windows or create the visual studio
projects by hand you need to define MXADataModel_EXPORTS when
building a DLL on windows.
*/

#if defined (WIN32) && defined (BUILD_SHARED_LIBS)
#if defined (_MSC_VER)
#pragma warning(disable: 4251)
#endif
   #if defined(MXADataModel_EXPORTS)
     #define  MXA_EXPORT __declspec(dllexport)
   #else
     #define  MXA_EXPORT __declspec(dllimport)
   #endif /* MXADataModel_EXPORTS */
#else /* defined (_WIN32) && defined (MXA_BUILD_SHARED_LIBS)  */
  #define MXA_EXPORT
#endif
#endif /* _MXA_DLL_EXPORT_H_ */

I also use the following in my CMakeLists.txt code:

# Build shared libraries
OPTION (BUILD_SHARED_LIBS "Build Shared Libraries" OFF)
SET (LIB_TYPE STATIC)
SET (MXA_BUILT_AS_DYNAMIC_LIB)
IF (BUILD_SHARED_LIBS)
   SET (LIB_TYPE SHARED)
   SET (MXA_BUILT_AS_DYNAMIC_LIB 1)
   IF (WIN32)
     ADD_DEFINITIONS("-DBUILD_SHARED_LIBS")
   ENDIF (WIN32)
ENDIF (BUILD_SHARED_LIBS)


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20080711/30ba11b1/attachment.htm>


More information about the CMake mailing list