From db829348437caa0146af256d6fa48bec9a21a92a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20DELRIEU?= Date: Tue, 19 Nov 2019 11:31:58 +0100 Subject: [PATCH 1/4] export operator<< in DLLs --- docopt.h | 14 +++++++------- docopt_value.h | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docopt.h b/docopt.h index c5ce97e..a59b5ed 100644 --- a/docopt.h +++ b/docopt.h @@ -9,13 +9,6 @@ #ifndef docopt__docopt_h_ #define docopt__docopt_h_ -#include "docopt_value.h" - -#include -#include -#include -#include - #ifdef DOCOPT_HEADER_ONLY #define DOCOPT_INLINE inline #define DOCOPT_API @@ -41,6 +34,13 @@ #endif #endif +#include "docopt_value.h" + +#include +#include +#include +#include + namespace docopt { // Usage string could not be parsed (ie, the developer did something wrong) diff --git a/docopt_value.h b/docopt_value.h index ff88625..e1c87e6 100644 --- a/docopt_value.h +++ b/docopt_value.h @@ -105,7 +105,7 @@ namespace docopt { }; /// Write out the contents to the ostream - std::ostream& operator<<(std::ostream&, value const&); + DOCOPT_API std::ostream& operator<<(std::ostream&, value const&); } namespace std { From 6d3b803d2b0e4bf8703bbfa51a67f378d6bd59f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20DELRIEU?= Date: Tue, 19 Nov 2019 14:58:59 +0100 Subject: [PATCH 2/4] only build one target, use BUILD_SHARED_LIBS where appropriate --- CMakeLists.txt | 39 ++++++--------------------------------- 1 file changed, 6 insertions(+), 33 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index feff32e..14c3420 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,33 +34,15 @@ set(docopt_HEADERS #============================================================================ # Compile targets #============================================================================ -if(MSVC OR XCODE) - # MSVC requires __declspec() attributes, which are achieved via the - # DOCOPT_DLL and DOCOPT_EXPORTS macros below. Since those macros are only - # defined when building a shared library, we must build the shared and - # static libraries completely separately. - # Xcode does not support libraries with only object files as sources. - # See https://cmake.org/cmake/help/v3.0/command/add_library.html?highlight=add_library - add_library(docopt SHARED ${docopt_SOURCES} ${docopt_HEADERS}) - add_library(docopt_s STATIC ${docopt_SOURCES} ${docopt_HEADERS}) -else() - # If not using MSVC or Xcode, we will create an intermediate object target - # to avoid compiling the source code twice. - add_library(docopt_o OBJECT ${docopt_SOURCES} ${docopt_HEADERS}) - set_target_properties(docopt_o PROPERTIES POSITION_INDEPENDENT_CODE TRUE) - - add_library(docopt SHARED $) - set_target_properties(docopt PROPERTIES - VERSION ${PROJECT_VERSION} - SOVERSION ${PROJECT_VERSION_MAJOR} - ) - add_library(docopt_s STATIC $) -endif() +add_library(docopt ${docopt_SOURCES} ${docopt_HEADERS}) +set_target_properties(docopt PROPERTIES + VERSION ${PROJECT_VERSION} + SOVERSION ${PROJECT_VERSION_MAJOR} +) target_include_directories(docopt PUBLIC $ $) -target_include_directories(docopt_s PUBLIC $ $) -if(MSVC) +if(MSVC AND BUILD_SHARED_LIBS) # DOCOPT_DLL: Must be specified when building *and* when using the DLL. # That's what the "PUBLIC" means. # DOCOPT_EXPORTS: Must use __declspec(dllexport) when building the DLL. @@ -69,11 +51,6 @@ if(MSVC) PRIVATE DOCOPT_EXPORTS) endif() -if(NOT MSVC) - set_target_properties(docopt PROPERTIES OUTPUT_NAME docopt) - set_target_properties(docopt_s PROPERTIES OUTPUT_NAME docopt) -endif() - if(USE_BOOST_REGEX) add_definitions("-DDOCTOPT_USE_BOOST_REGEX") # This is needed on Linux, where linking a static library into docopt.so @@ -82,9 +59,6 @@ if(USE_BOOST_REGEX) find_package(Boost 1.53 REQUIRED COMPONENTS regex) include_directories(${Boost_INCLUDE_DIRS}) target_link_libraries(docopt ${Boost_LIBRARIES}) - if(WITH_STATIC) - target_link_libraries(docopt_s ${Boost_LIBRARIES}) - endif() endif() #============================================================================ @@ -120,7 +94,6 @@ set(export_name "docopt-targets") install(TARGETS docopt EXPORT ${export_name} DESTINATION ${CMAKE_INSTALL_LIBDIR}) # Development package -install(TARGETS docopt_s EXPORT ${export_name} DESTINATION ${CMAKE_INSTALL_LIBDIR}) install(FILES ${docopt_HEADERS} DESTINATION include/docopt) # CMake Package From d6a0987631cb770fb9f0f7aac104bdcd38283474 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20DELRIEU?= Date: Tue, 19 Nov 2019 15:02:45 +0100 Subject: [PATCH 3/4] install dlls in CMAKE_INSTALL_BINDIR --- CMakeLists.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 14c3420..28da614 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -91,7 +91,10 @@ endif() set(export_name "docopt-targets") # Runtime package -install(TARGETS docopt EXPORT ${export_name} DESTINATION ${CMAKE_INSTALL_LIBDIR}) +install(TARGETS docopt EXPORT ${export_name} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) # Development package install(FILES ${docopt_HEADERS} DESTINATION include/docopt) From 400e6dd8e59196c914dcc2c56caf7dae7efa5eb3 Mon Sep 17 00:00:00 2001 From: Petr Mensik Date: Fri, 12 Nov 2021 14:05:32 +0100 Subject: [PATCH 4/4] Support python3 for running tests Simple change done by 2to3 python tool. Make prints compatible with both python3 and python2. Change default version to python3. Still can be run by python2 run_tests.py. Signed-off-by: Petr Mensik --- run_tests.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/run_tests.py b/run_tests.py index ef723b4..b75e176 100755 --- a/run_tests.py +++ b/run_tests.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 import re import sys @@ -56,17 +56,17 @@ def parse_test(raw): failures += 1 - print "="*40 - print doc - print ':'*20 - print prog, argv - print '-'*20 + print("="*40) + print(doc) + print(':'*20) + print(prog, argv) + print('-'*20) if out: - print out - print error + print(out) + print(error) if failures: - print "%d failures" % failures + print("%d failures" % failures) sys.exit(1) else: - print "PASS (%d)" % passes + print("PASS (%d)" % passes)