8000 Merge pull request #60 from chrisdembia/windows-export-symbols · lineCode/docopt.cpp@725519e · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 725519e

Browse files
authored
Merge pull request docopt#60 from chrisdembia/windows-export-symbols
Export symbols on windows.
2 parents b8710d7 + 3475d45 commit 725519e

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ endif()
5757
target_include_directories(docopt PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}> $<INSTALL_INTERFACE:include/docopt>)
5858
target_include_directories(docopt_s PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}> $<INSTALL_INTERFACE:include/docopt>)
5959

60+
# To control the exporting of symbols (on Windows).
61+
set_target_properties(docopt PROPERTIES DEFINE_SYMBOL DOCOPT_EXPORTS)
62+
6063
if(NOT MSVC)
6164
set_target_properties(docopt PROPERTIES OUTPUT_NAME docopt)
6265
set_target_properties(docopt_s PROPERTIES OUTPUT_NAME docopt)

docopt.h

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,22 @@
1616
#include <string>
1717

1818
#ifdef DOCOPT_HEADER_ONLY
19-
#define DOCOPT_INLINE inline
19+
#define DOCOPT_INLINE inline
20+
#define DOCOPTAPI
2021
#else
21-
#define DOCOPT_INLINE
22+
#define DOCOPT_INLINE
23+
24+
// On Windows, export certain symbols so they are available
25+
// to users of docopt.dll (shared library).
26+
#ifdef WIN32
27+
#ifdef DOCOPT_EXPORTS
28+
#define DOCOPTAPI __declspec(dllexport)
29+
#else
30+
#define DOCOPTAPI __declspec(dllimport)
31+
#endif
32+
#else
33+
#define DOCOPTAPI
34+
#endif
2235
#endif
2336

2437
namespace docopt {
@@ -48,7 +61,7 @@ namespace docopt {
4861
/// @throws DocoptExitHelp if 'help' is true and the user has passed the '--help' argument
4962
/// @throws DocoptExitVersion if 'version' is true and the user has passed the '--version' argument
5063
/// @throws DocoptArgumentError if the user's argv did not match the usage patterns
51-
std::map<std::string, value> docopt_parse(std::string const& doc,
64+
std::map<std::string, value> DOCOPTAPI docopt_parse(std::string const& doc,
5265
std::vector<std::string> const& argv,
5366
bool help = true,
5467
bool version = true,
@@ -61,15 +74,15 @@ namespace docopt {
6174
/// * DocoptExitHelp - print usage string and terminate (with exit code 0)
6275
/// * DocoptExitVersion - print version and terminate (with exit code 0)
6376
/// * DocoptArgumentError - print error and usage string and terminate (with exit code -1)
64-
std::map<std::string, value> docopt(std::string const& doc,
77+
std::map<std::string, value> DOCOPTAPI docopt(std::string const& doc,
6578
std::vector<std::string> const& argv,
6679
bool help = true,
6780
std::string const& version = {},
6881
bool options_first = false) noexcept;
6982
}
7083

7184
#ifdef DOCOPT_HEADER_ONLY
72-
#include "docopt.cpp"
85+
#include "docopt.cpp"
7386
#endif
7487

7588
#endif /* defined(docopt__docopt_h_) */

0 commit comments

Comments
 (0)
0