diff --git a/CMakeLists.txt b/CMakeLists.txt index d14cc81..4f84d23 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,6 +57,9 @@ endif() target_include_directories(docopt PUBLIC $ $) target_include_directories(docopt_s PUBLIC $ $) +# To control the exporting of symbols (on Windows). +set_target_properties(docopt PROPERTIES DEFINE_SYMBOL DOCOPT_EXPORTS) + if(NOT MSVC) set_target_properties(docopt PROPERTIES OUTPUT_NAME docopt) set_target_properties(docopt_s PROPERTIES OUTPUT_NAME docopt) diff --git a/docopt.h b/docopt.h index 5a65e10..0acd843 100644 --- a/docopt.h +++ b/docopt.h @@ -16,9 +16,22 @@ #include #ifdef DOCOPT_HEADER_ONLY -#define DOCOPT_INLINE inline + #define DOCOPT_INLINE inline + #define DOCOPTAPI #else -#define DOCOPT_INLINE + #define DOCOPT_INLINE + + // On Windows, export certain symbols so they are available + // to users of docopt.dll (shared library). + #ifdef WIN32 + #ifdef DOCOPT_EXPORTS + #define DOCOPTAPI __declspec(dllexport) + #else + #define DOCOPTAPI __declspec(dllimport) + #endif + #else + #define DOCOPTAPI + #endif #endif namespace docopt { @@ -48,7 +61,7 @@ namespace docopt { /// @throws DocoptExitHelp if 'help' is true and the user has passed the '--help' argument /// @throws DocoptExitVersion if 'version' is true and the user has passed the '--version' argument /// @throws DocoptArgumentError if the user's argv did not match the usage patterns - std::map docopt_parse(std::string const& doc, + std::map DOCOPTAPI docopt_parse(std::string const& doc, std::vector const& argv, bool help = true, bool version = true, @@ -61,7 +74,7 @@ namespace docopt { /// * DocoptExitHelp - print usage string and terminate (with exit code 0) /// * DocoptExitVersion - print version and terminate (with exit code 0) /// * DocoptArgumentError - print error and usage string and terminate (with exit code -1) - std::map docopt(std::string const& doc, + std::map DOCOPTAPI docopt(std::string const& doc, std::vector const& argv, bool help = true, std::string const& version = {}, @@ -69,7 +82,7 @@ namespace docopt { } #ifdef DOCOPT_HEADER_ONLY -#include "docopt.cpp" + #include "docopt.cpp" #endif #endif /* defined(docopt__docopt_h_) */