Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake adds -Dlibname_EXPORTS compile definition

Tags:

cmake

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?

like image 566
Baradé Avatar asked Dec 11 '14 18:12

Baradé


1 Answers

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

  • http://www.cmake.org/cmake/help/v3.0/prop_tgt/DEFINE_SYMBOL.html
like image 96
maxint Avatar answered Oct 05 '22 22:10

maxint