docopt / docopt.cpp

C++11 port of docopt
Boost Software License 1.0
1.05k stars 146 forks source link

Fix support for building static library with Visual Studio #61

Closed chrisdembia closed 8 years ago

chrisdembia commented 8 years ago

In PR #60, I tried to improve support for using docopt with Visual Studio when building/using the shared library docopt.dll. In doing so, I introduced a bug when trying to build/use docopt as a static library (docopt_s.lib) in Visual Studio.

Basically, I had been defining DOCOPTAPI to be __declspec(dllimport) when building the static library. But when building a static library, neither __declspec(dllimport) nor __declspec(dllexport) should be used.

This PR fixes the bug. The new behavior is as follows. When building the shared library, one must define both DOCOPT_DLL and DOCOPT_API. When using the shared library, one must define DOCOPT_DLL. The user need not worry about these macros at all; they are handled by CMake. For example, a client project with the following CMakeLists.txt will cause DOCOPT_DLL to automatically be defined when compiling foo.cpp.

project(ClientToDocopt)
cmake_minimum_required(VERSION 3.1)
find_package(docopt)
add_executable(foo foo.cpp)
target_link_libraries(foo docopt)

Locally, I tested both the shared library docopt.dll and the static library docopt_s.lib with a small CMake client project.

jaredgrubb commented 8 years ago

Looks ok to me but I know nothing about Windows :) This has been up a week and no one has objected so let's merge it.

chrisdembia commented 8 years ago

Thank you! I will be happy to address any issues that arise from this PR.

jaredgrubb commented 8 years ago

Thanks for your contributions!

chrisdembia commented 8 years ago

And thank you for making a great library :)