more sensible build macros on windows

master
Daniel Kolesa 2018-01-17 22:56:39 +01:00
parent 827aed2bb9
commit 45161b9837
2 changed files with 18 additions and 18 deletions

View File

@ -5,9 +5,6 @@
* COPYING.md file further information. * COPYING.md file further information.
*/ */
/* for Windows so that we avoid dllimport/dllexport */
#define OSTD_BUILD_LIB
#include <string> #include <string>
#include <vector> #include <vector>
#include <stdexcept> #include <stdexcept>
@ -331,9 +328,9 @@ int main(int argc, char **argv) {
} }
if (lib) { if (lib) {
args.push_back("-DOSTD_BUILD_LIB"); args.push_back("-DOSTD_BUILD");
if (shared) { if (shared) {
args.push_back("-DOSTD_BUILD_DLL"); args.push_back("-DOSTD_DLL");
} }
} }

View File

@ -85,16 +85,19 @@
/** @brief Use this to annotate externally visible API. /** @brief Use this to annotate externally visible API.
* *
* On Windows, this will expand differently when building a library and when * On Windows, this will expand differently when building a library and when
* using the resulting API. You can define `OSTD_BUILD_LIB` to declare that * using the resulting API. You can define `OSTD_BUILD` to declare that you
* you're currently building a static library (in which case this macro will * are currently building the library, this is only useful for build systems
* expand to nothing) or `OSTD_BUILD_DLL` to declare you're building a DLL * that build libostd itself, never for library usage. You can also define
* (in which case it will expand to `__declspec(dllexport)`). * `OSTD_DLL` to declare the libostd library is a dynamic one, when both
* * using and building the library. If `OSTD_DLL` is defined, then this
* When not building a library, this will expand to `__declspec(dllimport)`. * will be either `__declspec(dllexport)` or `__declspec(dllimport)`,
* * depending on whether `OSTD_BUILD` is defined, otherwise it will be
* empty regardless of `OSTD_BUILD`.
* On POSIX compliant systems, there are two possibilities. If your compiler * On POSIX compliant systems, there are two possibilities. If your compiler
* supports it, it can expand to `__attribute__((visibility("default")))`. * supports it, it can expand to `__attribute__((visibility("default")))`.
* Otherwise, it will be empty. * Otherwise, it will be empty. The `OSTD_BUILD` macro is not used then,
* neither is `OSTD_DLL`.
* *
* ~~~{.cc} * ~~~{.cc}
* OSTD_EXPORT void foo(); * OSTD_EXPORT void foo();
@ -198,18 +201,18 @@
#endif #endif
#ifdef OSTD_PLATFORM_WIN32 #ifdef OSTD_PLATFORM_WIN32
# if defined(OSTD_BUILD_LIB) || defined(OSTD_BUILD_DLL) # ifdef OSTD_DLL
# ifdef OSTD_BUILD_DLL # ifdef OSTD_BUILD
# define OSTD_EXPORT __declspec(dllexport) # define OSTD_EXPORT __declspec(dllexport)
# else # else
# define OSTD_EXPORT # define OSTD_EXPORT __declspec(dllimport)
# endif # endif
# else # else
# define OSTD_EXPORT __declspec(dllimport) # define OSTD_EXPORT
# endif # endif
# define OSTD_LOCAL # define OSTD_LOCAL
#else #else
# if defined(OSTD_BUILD_LIB) || defined(OSTD_BUILD_DLL) # if defined(OSTD_BUILD) || defined(OSTD_DLL)
/* -Wunused-macros */ /* -Wunused-macros */
# endif # endif
# if __GNUC__ >= 4 # if __GNUC__ >= 4