On 2013-10-31 05:26, Cyrille Faucheux wrote:
Can you tell me a bit more about "implicit compile flags [...] for imported
tagets"?

See documentation on target_compile_definitions.

On the library I'm currently working on, with Visual Studio, I have to
declare some compile definition in order to get the proper
"__declspec(dllimport)" or "__declspec(dllexport)" defined (or not defined
when compiling/using a static version of this library).

This sounds like you're doing it wrong.

When building with CMake, the preferred way is to unconditionally define an ABI export symbol via a header which exists for that purpose (e.g. config.h, my_package_exports.h, etc.). The value of the definition however is conditional on a symbol that is only defined when building the library, to choose between import and export as appropriate.

Even better, CMake will define <target>_EXPORTS for you when building a library, so you shouldn't need to manually specify any definitions at all.

IOW you libraries headers would somewhere contain:

#if defined(_WIN32)
#  define MYPROJECT_ABI_EXPORT __declspec(dllexport)
#  define MYPROJECT_ABI_IMPORT __declspec(dllimport)
#elif __GNUC__ >= 4
#  define MYPROJECT_ABI_EXPORT __attribute__ ((visibility("default")))
#  define MYPROJECT_ABI_IMPORT __attribute__ ((visibility("default")))
#else
#  define MYPROJECT_ABI_EXPORT
#  define MYPROJECT_ABI_IMPORT
#endif

...and:

#ifdef mylibrary_EXPORTS
#  define MYLIBRARY_EXPORT MYPROJECT_ABI_EXPORT
#else
#  define MYLIBRARY_EXPORT MYPROJECT_ABI_IMPORT
#endif


That said...

Does "implicit compile flags" means that those compile definition could be
automatically declared by the imported target?

...this was my understanding of how target_compile_definitions(PUBLIC) is supposed to work. (Note: I haven't actually used this feature myself yet.)

--
Matthew

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to