From def54d45cb610c6ece4518a2dd9d45842b18ae6e Mon Sep 17 00:00:00 2001 From: Dmitriy Vetutnev Date: Thu, 5 Sep 2019 15:29:25 +0300 Subject: [PATCH 01/14] Add __declspec(dllexport) for docopt::operator<< (compotibility for MSVC shared library) --- CMakeLists.txt | 1 + docopt.cpp | 16 +++++++++------- docopt.h | 32 +++++--------------------------- docopt_api.h | 37 +++++++++++++++++++++++++++++++++++++ docopt_value.h | 4 +++- 5 files changed, 55 insertions(+), 35 deletions(-) create mode 100644 docopt_api.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 23da468..89c6361 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,6 +29,7 @@ set(docopt_HEADERS docopt_private.h docopt_util.h docopt_value.h + docopt_api.h ) #============================================================================ diff --git a/docopt.cpp b/docopt.cpp index 937845d..bce61b8 100644 --- a/docopt.cpp +++ b/docopt.cpp @@ -21,10 +21,10 @@ #include #include -using namespace docopt; +namespace docopt { DOCOPT_INLINE -std::ostream& docopt::operator<<(std::ostream& os, value const& val) +std::ostream& operator<<(std::ostream& os, value const& val) { if (val.isBool()) { bool b = val.asBool(); @@ -660,11 +660,11 @@ docopt::docopt_parse(std::string const& doc, DOCOPT_INLINE std::map -docopt::docopt(std::string const& doc, - std::vector const& argv, - bool help, - std::string const& version, - bool options_first) noexcept +docopt(std::string const& doc, + std::vector const& argv, + bool help, + std::string const& version, + bool options_first) noexcept { try { return docopt_parse(doc, argv, help, !version.empty(), options_first); @@ -685,3 +685,5 @@ docopt::docopt(std::string const& doc, std::exit(-1); } /* Any other exception is unexpected: let std::terminate grab it */ } + +} /* namespace docopt */ \ No newline at end of file diff --git a/docopt.h b/docopt.h index 4c40741..e4d494e 100644 --- a/docopt.h +++ b/docopt.h @@ -9,37 +9,13 @@ #ifndef docopt__docopt_h_ #define docopt__docopt_h_ +#include "docopt_api.h" #include "docopt_value.h" #include #include #include -#ifdef DOCOPT_HEADER_ONLY - #define DOCOPT_INLINE inline - #define DOCOPT_API -#else - #define DOCOPT_INLINE - - // With Microsoft Visual Studio, export certain symbols so they - // are available to users of docopt.dll (shared library). The DOCOPT_DLL - // macro should be defined if building a DLL (with Visual Studio), - // and by clients using the DLL. The CMakeLists.txt and the - // docopt-config.cmake it generates handle this. - #ifdef DOCOPT_DLL - // Whoever is *building* the DLL should define DOCOPT_EXPORTS. - // The CMakeLists.txt that comes with docopt does this. - // Clients of docopt.dll should NOT define DOCOPT_EXPORTS. - #ifdef DOCOPT_EXPORTS - #define DOCOPT_API __declspec(dllexport) - #else - #define DOCOPT_API __declspec(dllimport) - #endif - #else - #define DOCOPT_API - #endif -#endif - namespace docopt { // Usage string could not be parsed (ie, the developer did something wrong) @@ -67,7 +43,8 @@ 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_API docopt_parse(std::string const& doc, + DOCOPT_API + std::map docopt_parse(std::string const& doc, std::vector const& argv, bool help = true, bool version = true, @@ -80,7 +57,8 @@ 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_API docopt(std::string const& doc, + DOCOPT_API + std::map docopt(std::string const& doc, std::vector const& argv, bool help = true, std::string const& version = {}, diff --git a/docopt_api.h b/docopt_api.h new file mode 100644 index 0000000..625b28c --- /dev/null +++ b/docopt_api.h @@ -0,0 +1,37 @@ +// +// docopt.h +// docopt +// +// Created by Dmitriy Vetutnev on 2019-09-05. +// Copyright (c) 2019 Dmitriy Vetutnev. All rights reserved. +// + +#ifndef docopt__api_h_ +#define docopt__api_h_ + +#ifdef DOCOPT_HEADER_ONLY + #define DOCOPT_INLINE inline + #define DOCOPT_API +#else + #define DOCOPT_INLINE + + // With Microsoft Visual Studio, export certain symbols so they + // are available to users of docopt.dll (shared library). The DOCOPT_DLL + // macro should be defined if building a DLL (with Visual Studio), + // and by clients using the DLL. The CMakeLists.txt and the + // docopt-config.cmake it generates handle this. + #ifdef DOCOPT_DLL + // Whoever is *building* the DLL should define DOCOPT_EXPORTS. + // The CMakeLists.txt that comes with docopt does this. + // Clients of docopt.dll should NOT define DOCOPT_EXPORTS. + #ifdef DOCOPT_EXPORTS + #define DOCOPT_API __declspec(dllexport) + #else + #define DOCOPT_API __declspec(dllimport) + #endif + #else + #define DOCOPT_API + #endif +#endif + +#endif /* defined(docopt__api_h_) */ \ No newline at end of file diff --git a/docopt_value.h b/docopt_value.h index 829ee55..852c52c 100644 --- a/docopt_value.h +++ b/docopt_value.h @@ -9,6 +9,8 @@ #ifndef docopt__value_h_ #define docopt__value_h_ +#include "docopt_api.h" + #include #include #include @@ -105,7 +107,7 @@ namespace docopt { }; /// Write out the contents to the ostream - std::ostream& operator<<(std::ostream&, value const&); + DOCOPT_API std::ostream& operator<<(std::ostream&, const value&); } namespace std { From 915e57e4d4d2ffd49e194764f35ecdb034a43515 Mon Sep 17 00:00:00 2001 From: Dmitriy Vetutnev Date: Thu, 5 Sep 2019 15:36:09 +0300 Subject: [PATCH 02/14] Remove namespace-prefix from docopt_parse (GCC compatibility) --- docopt.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docopt.cpp b/docopt.cpp index bce61b8..105d5b3 100644 --- a/docopt.cpp +++ b/docopt.cpp @@ -610,7 +610,7 @@ static std::pair> create_pattern_tree(std::string DOCOPT_INLINE std::map -docopt::docopt_parse(std::string const& doc, +docopt_parse(std::string const& doc, std::vector const& argv, bool help, bool version, @@ -686,4 +686,5 @@ docopt(std::string const& doc, } /* Any other exception is unexpected: let std::terminate grab it */ } -} /* namespace docopt */ \ No newline at end of file +} /* namespace docopt */ + From c36c797987ac268aba0003210163b4ff0647dc97 Mon Sep 17 00:00:00 2001 From: Dmitriy Vetutnev Date: Thu, 5 Sep 2019 19:44:52 +0300 Subject: [PATCH 03/14] Remove copyrigth from docopt_api --- docopt_api.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/docopt_api.h b/docopt_api.h index 625b28c..8d774e9 100644 --- a/docopt_api.h +++ b/docopt_api.h @@ -1,9 +1,7 @@ // -// docopt.h +// docopt_api.h // docopt // -// Created by Dmitriy Vetutnev on 2019-09-05. -// Copyright (c) 2019 Dmitriy Vetutnev. All rights reserved. // #ifndef docopt__api_h_ From 27a3c75a40804ebdf11c8e4c195748149ce67d72 Mon Sep 17 00:00:00 2001 From: Dmitriy Vetutnev Date: Thu, 5 Sep 2019 19:57:24 +0300 Subject: [PATCH 04/14] Use previous stile --- docopt.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/docopt.cpp b/docopt.cpp index 105d5b3..937845d 100644 --- a/docopt.cpp +++ b/docopt.cpp @@ -21,10 +21,10 @@ #include #include -namespace docopt { +using namespace docopt; DOCOPT_INLINE -std::ostream& operator<<(std::ostream& os, value const& val) +std::ostream& docopt::operator<<(std::ostream& os, value const& val) { if (val.isBool()) { bool b = val.asBool(); @@ -610,7 +610,7 @@ static std::pair> create_pattern_tree(std::string DOCOPT_INLINE std::map -docopt_parse(std::string const& doc, +docopt::docopt_parse(std::string const& doc, std::vector const& argv, bool help, bool version, @@ -660,11 +660,11 @@ docopt_parse(std::string const& doc, DOCOPT_INLINE std::map -docopt(std::string const& doc, - std::vector const& argv, - bool help, - std::string const& version, - bool options_first) noexcept +docopt::docopt(std::string const& doc, + std::vector const& argv, + bool help, + std::string const& version, + bool options_first) noexcept { try { return docopt_parse(doc, argv, help, !version.empty(), options_first); @@ -685,6 +685,3 @@ docopt(std::string const& doc, std::exit(-1); } /* Any other exception is unexpected: let std::terminate grab it */ } - -} /* namespace docopt */ - From 682acc26718b7f48b9360fd6319b16f79716fd91 Mon Sep 17 00:00:00 2001 From: Dmitriy Vetutnev Date: Thu, 5 Sep 2019 20:02:03 +0300 Subject: [PATCH 05/14] Use previous style (value const&) --- docopt_value.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docopt_value.h b/docopt_value.h index 852c52c..ce7f280 100644 --- a/docopt_value.h +++ b/docopt_value.h @@ -107,7 +107,7 @@ namespace docopt { }; /// Write out the contents to the ostream - DOCOPT_API std::ostream& operator<<(std::ostream&, const value&); + DOCOPT_API std::ostream& operator<<(std::ostream&, value const&); } namespace std { From 591799bf99d3bc6388d0719bc46f1f113f337208 Mon Sep 17 00:00:00 2001 From: Dmitriy Vetutnev Date: Tue, 10 Sep 2019 02:44:16 +0300 Subject: [PATCH 06/14] Add Appveyor --- appveyor.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 appveyor.yml diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..ab8eab1 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,18 @@ +skip_tags: true + +environment: + PYTHON: C:\\Python27-x64 + + matrix: + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 + CMAKE_GENERATOR: Visual Studio 2017 Win64 + +install: + - set PATH=%PYTHON%;%PYTHON%\\Scripts\\;%PATH% + +build: + - cmake -G%CMAKE_GENERATOR% .. + - cmake --build . --config Debug + +test_script: false + From 578ec0f41ab273fd3d489d110bcb5bb58048f6d1 Mon Sep 17 00:00:00 2001 From: Dmitriy Vetutnev Date: Tue, 10 Sep 2019 02:46:34 +0300 Subject: [PATCH 07/14] Appveyor script mode --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index ab8eab1..b08dd69 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -10,7 +10,7 @@ environment: install: - set PATH=%PYTHON%;%PYTHON%\\Scripts\\;%PATH% -build: +build_script: - cmake -G%CMAKE_GENERATOR% .. - cmake --build . --config Debug From eb6958016da345530104502e9e437d32096384a4 Mon Sep 17 00:00:00 2001 From: Dmitriy Vetutnev Date: Tue, 10 Sep 2019 02:48:32 +0300 Subject: [PATCH 08/14] Appveyor script mode, 2 --- appveyor.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/appveyor.yml b/appveyor.yml index b08dd69..e04bd5a 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -10,6 +10,8 @@ environment: install: - set PATH=%PYTHON%;%PYTHON%\\Scripts\\;%PATH% +build: false + build_script: - cmake -G%CMAKE_GENERATOR% .. - cmake --build . --config Debug From 56d671acdc8f65a36b762de6eca229bf08e23d23 Mon Sep 17 00:00:00 2001 From: Dmitriy Vetutnev Date: Tue, 10 Sep 2019 02:53:49 +0300 Subject: [PATCH 09/14] Appveyor, fix generator --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index e04bd5a..003067a 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -5,7 +5,7 @@ environment: matrix: - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 - CMAKE_GENERATOR: Visual Studio 2017 Win64 + CMAKE_GENERATOR: Visual Studio 15 2017 Win64 install: - set PATH=%PYTHON%;%PYTHON%\\Scripts\\;%PATH% From 2f5d711693d15c1e3397e13e7305e699a0867179 Mon Sep 17 00:00:00 2001 From: Dmitriy Vetutnev Date: Tue, 10 Sep 2019 02:55:24 +0300 Subject: [PATCH 10/14] Appveyor, fix generator, 2 --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 003067a..6134e51 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -5,7 +5,7 @@ environment: matrix: - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 - CMAKE_GENERATOR: Visual Studio 15 2017 Win64 + CMAKE_GENERATOR: "Visual Studio 15 2017 Win64" install: - set PATH=%PYTHON%;%PYTHON%\\Scripts\\;%PATH% From 77c03181c61847e5a1f7b66e6535590b31bec13d Mon Sep 17 00:00:00 2001 From: Dmitriy Vetutnev Date: Tue, 10 Sep 2019 02:56:22 +0300 Subject: [PATCH 11/14] Appveyor, fix generator, 3 --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 6134e51..a33cdaa 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -5,7 +5,7 @@ environment: matrix: - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 - CMAKE_GENERATOR: "Visual Studio 15 2017 Win64" + CMAKE_GENERATOR: \"Visual Studio 15 2017 Win64\" install: - set PATH=%PYTHON%;%PYTHON%\\Scripts\\;%PATH% From e2fa032a63aaa78f44e0cfa04067d984746a4a9e Mon Sep 17 00:00:00 2001 From: Dmitriy Vetutnev Date: Tue, 10 Sep 2019 02:58:15 +0300 Subject: [PATCH 12/14] Appveyor, fix generator, 4 --- appveyor.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index a33cdaa..03a5e95 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -2,10 +2,7 @@ skip_tags: true environment: PYTHON: C:\\Python27-x64 - - matrix: - - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 - CMAKE_GENERATOR: \"Visual Studio 15 2017 Win64\" + APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 install: - set PATH=%PYTHON%;%PYTHON%\\Scripts\\;%PATH% @@ -13,7 +10,7 @@ install: build: false build_script: - - cmake -G%CMAKE_GENERATOR% .. + - cmake -G "Visual Studio 15 2017 Win64" .. - cmake --build . --config Debug test_script: false From d5da55cf4c203f636fe8e6d5d47e84d8f06c87a1 Mon Sep 17 00:00:00 2001 From: Dmitriy Vetutnev Date: Tue, 10 Sep 2019 02:59:25 +0300 Subject: [PATCH 13/14] Appveyor, build folder --- appveyor.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/appveyor.yml b/appveyor.yml index 03a5e95..842bdff 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -10,6 +10,7 @@ install: build: false build_script: + - mkdir build && cd build - cmake -G "Visual Studio 15 2017 Win64" .. - cmake --build . --config Debug From 125faf3f624728129ae09a55de3d6e8529fbf1a6 Mon Sep 17 00:00:00 2001 From: Dmitriy Vetutnev Date: Tue, 10 Sep 2019 03:01:21 +0300 Subject: [PATCH 14/14] Appveyor, remove test_script --- appveyor.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 842bdff..4c81b4c 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -14,5 +14,3 @@ build_script: - cmake -G "Visual Studio 15 2017 Win64" .. - cmake --build . --config Debug -test_script: false -