0001-only-build-one-target-use-BUILD_SHARED_LIBS-where-appropriate.patch 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. From 6d3b803d2b0e4bf8703bbfa51a67f378d6bd59f6 Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Th=C3=A9o=20DELRIEU?= <theo.delrieu@tanker.io>
  3. Date: Tue, 19 Nov 2019 14:58:59 +0100
  4. Subject: [PATCH] only build one target, use BUILD_SHARED_LIBS where
  5. appropriate
  6. [Retrieved from:
  7. https://github.com/docopt/docopt.cpp/commit/6d3b803d2b0e4bf8703bbfa51a67f378d6bd59f6]
  8. Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
  9. ---
  10. CMakeLists.txt | 39 ++++++---------------------------------
  11. 1 file changed, 6 insertions(+), 33 deletions(-)
  12. diff --git a/CMakeLists.txt b/CMakeLists.txt
  13. index feff32e..14c3420 100644
  14. --- a/CMakeLists.txt
  15. +++ b/CMakeLists.txt
  16. @@ -34,33 +34,15 @@ set(docopt_HEADERS
  17. #============================================================================
  18. # Compile targets
  19. #============================================================================
  20. -if(MSVC OR XCODE)
  21. - # MSVC requires __declspec() attributes, which are achieved via the
  22. - # DOCOPT_DLL and DOCOPT_EXPORTS macros below. Since those macros are only
  23. - # defined when building a shared library, we must build the shared and
  24. - # static libraries completely separately.
  25. - # Xcode does not support libraries with only object files as sources.
  26. - # See https://cmake.org/cmake/help/v3.0/command/add_library.html?highlight=add_library
  27. - add_library(docopt SHARED ${docopt_SOURCES} ${docopt_HEADERS})
  28. - add_library(docopt_s STATIC ${docopt_SOURCES} ${docopt_HEADERS})
  29. -else()
  30. - # If not using MSVC or Xcode, we will create an intermediate object target
  31. - # to avoid compiling the source code twice.
  32. - add_library(docopt_o OBJECT ${docopt_SOURCES} ${docopt_HEADERS})
  33. - set_target_properties(docopt_o PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
  34. -
  35. - add_library(docopt SHARED $<TARGET_OBJECTS:docopt_o>)
  36. - set_target_properties(docopt PROPERTIES
  37. - VERSION ${PROJECT_VERSION}
  38. - SOVERSION ${PROJECT_VERSION_MAJOR}
  39. - )
  40. - add_library(docopt_s STATIC $<TARGET_OBJECTS:docopt_o>)
  41. -endif()
  42. +add_library(docopt ${docopt_SOURCES} ${docopt_HEADERS})
  43. +set_target_properties(docopt PROPERTIES
  44. + VERSION ${PROJECT_VERSION}
  45. + SOVERSION ${PROJECT_VERSION_MAJOR}
  46. +)
  47. target_include_directories(docopt PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}> $<INSTALL_INTERFACE:include/docopt>)
  48. -target_include_directories(docopt_s PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}> $<INSTALL_INTERFACE:include/docopt>)
  49. -if(MSVC)
  50. +if(MSVC AND BUILD_SHARED_LIBS)
  51. # DOCOPT_DLL: Must be specified when building *and* when using the DLL.
  52. # That's what the "PUBLIC" means.
  53. # DOCOPT_EXPORTS: Must use __declspec(dllexport) when building the DLL.
  54. @@ -69,11 +51,6 @@ if(MSVC)
  55. PRIVATE DOCOPT_EXPORTS)
  56. endif()
  57. -if(NOT MSVC)
  58. - set_target_properties(docopt PROPERTIES OUTPUT_NAME docopt)
  59. - set_target_properties(docopt_s PROPERTIES OUTPUT_NAME docopt)
  60. -endif()
  61. -
  62. if(USE_BOOST_REGEX)
  63. add_definitions("-DDOCTOPT_USE_BOOST_REGEX")
  64. # This is needed on Linux, where linking a static library into docopt.so
  65. @@ -82,9 +59,6 @@ if(USE_BOOST_REGEX)
  66. find_package(Boost 1.53 REQUIRED COMPONENTS regex)
  67. include_directories(${Boost_INCLUDE_DIRS})
  68. target_link_libraries(docopt ${Boost_LIBRARIES})
  69. - if(WITH_STATIC)
  70. - target_link_libraries(docopt_s ${Boost_LIBRARIES})
  71. - endif()
  72. endif()
  73. #============================================================================
  74. @@ -120,7 +94,6 @@ set(export_name "docopt-targets")
  75. install(TARGETS docopt EXPORT ${export_name} DESTINATION ${CMAKE_INSTALL_LIBDIR})
  76. # Development package
  77. -install(TARGETS docopt_s EXPORT ${export_name} DESTINATION ${CMAKE_INSTALL_LIBDIR})
  78. install(FILES ${docopt_HEADERS} DESTINATION include/docopt)
  79. # CMake Package