17

CMake adds the following compile definition to all source code files automatically when simply compiling a target:

-Dlibname_EXPORTS

Why is this done and how can I disable it?

Baradé
  • 1,290
  • 1
  • 15
  • 35

1 Answers1

20

cmake add <libname>_EXPORTS macros only for shared libraries. It's useful when exporting API's in Windows DLL.

#if defined(_WINDOWS) && defined(testlib_EXPORTS)
#   define API_DLL extern "C" __declspec(dllexport)
#else
#   define API_DLL
#endif

API_DLL void foo();

It could be disabled by setting the DEFINE_SYMBOL property of target to empty.

# disable the <libname>_EXPORTS
set_target_properties(sharedlib
  PROPERTIES
  DEFINE_SYMBOL ""
  )

Reference

maxint
  • 1,005
  • 8
  • 12