diff --git a/CMakeLists.txt b/CMakeLists.txt index feff32e..28da614 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() #============================================================================ @@ -117,10 +91,12 @@ 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(TARGETS docopt_s EXPORT ${export_name} DESTINATION ${CMAKE_INSTALL_LIBDIR}) install(FILES ${docopt_HEADERS} DESTINATION include/docopt) # CMake Package diff --git a/docopt.cpp b/docopt.cpp index c2c2008..c6ee9b9 100644 --- a/docopt.cpp +++ b/docopt.cpp @@ -523,7 +523,7 @@ static PatternList parse_argv(Tokens tokens, std::vector