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