8000 only build one target, use BUILD_SHARED_LIBS where appropriate · docopt/docopt.cpp@6d3b803 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6d3b803

Browse files
theodelrieujaredgrubb
authored andcommitted
only build one target, use BUILD_SHARED_LIBS where appropriate
1 parent db82934 commit 6d3b803

File tree

1 file changed

+6
-33
lines changed

1 file changed

+6
-33
lines changed

CMakeLists.txt

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -34,33 +34,15 @@ set(docopt_HEADERS
3434
#============================================================================
3535
# Compile targets
3636
#============================================================================
37-
if(MSVC OR XCODE)
38-
# MSVC requires __declspec() attributes, which are achieved via the
39-
# DOCOPT_DLL and DOCOPT_EXPORTS macros below. Since those macros are only
40-
# defined when building a shared library, we must build the shared and
41-
# static libraries completely separately.
42-
# Xcode does not support libraries with only object files as sources.
43-
# See https://cmake.org/cmake/help/v3.0/command/add_library.html?highlight=add_library
44-
add_library(docopt SHARED ${docopt_SOURCES} ${docopt_HEADERS})
45-
add_library(docopt_s STATIC ${docopt_SOURCES} ${docopt_HEADERS})
46-
else()
47-
# If not using MSVC or Xcode, we will create an intermediate object target
48-
# to avoid compiling the source code twice.
49-
add_library(docopt_o OBJECT ${docopt_SOURCES} ${docopt_HEADERS})
50-
set_target_properties(docopt_o PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
51-
52-
add_library(docopt SHARED $<TARGET_OBJECTS:docopt_o>)
53-
set_target_properties(docopt PROPERTIES
54-
VERSION ${PROJECT_VERSION}
55-
SOVERSION ${PROJECT_VERSION_MAJOR}
56-
)
57-
add_library(docopt_s STATIC $<TARGET_OBJECTS:docopt_o>)
58-
endif()
37+
add_library(docopt ${docopt_SOURCES} ${docopt_HEADERS})
38+
set_target_properties(docopt PROPERTIES
39+
VERSION ${PROJECT_VERSION}
40+
SOVERSION ${PROJECT_VERSION_MAJOR}
41+
)
5942

6043
target_include_directories(docopt PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}> $<INSTALL_INTERFACE:include/docopt>)
61-
target_include_directories(docopt_s PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}> $<INSTALL_INTERFACE:include/docopt>)
6244

63-
if(MSVC)
45+
if(MSVC AND BUILD_SHARED_LIBS)
6446
# DOCOPT_DLL: Must be specified when building *and* when using the DLL.
6547
# That's what the "PUBLIC" means.
6648
# DOCOPT_EXPORTS: Must use __declspec(dllexport) when building the DLL.
@@ -69,11 +51,6 @@ if(MSVC)
6951
PRIVATE DOCOPT_EXPORTS)
7052
endif()
7153

72-
if(NOT MSVC)
73-
set_target_properties(docopt PROPERTIES OUTPUT_NAME docopt)
74-
set_target_properties(docopt_s PROPERTIES OUTPUT_NAME docopt)
75-
endif()
76-
7754
if(USE_BOOST_REGEX)
7855
add_definitions("-DDOCTOPT_USE_BOOST_REGEX")
7956
# This is needed on Linux, where linking a static library into docopt.so
@@ -82,9 +59,6 @@ if(USE_BOOST_REGEX)
8259
find_package(Boost 1.53 REQUIRED COMPONENTS regex)
8360
include_directories(${Boost_INCLUDE_DIRS})
8461
target_link_libraries(docopt ${Boost_LIBRARIES})
85-
if(WITH_STATIC)
86-
target_link_libraries(docopt_s ${Boost_LIBRARIES})
87-
endif()
8862
endif()
8963

9064
#============================================================================
@@ -120,7 +94,6 @@ set(export_name "docopt-targets")
12094
install(TARGETS docopt EXPORT ${export_name} DESTINATION ${CMAKE_INSTALL_LIBDIR})
12195

12296
# Development package
123-
install(TARGETS docopt_s EXPORT ${export_name} DESTINATION ${CMAKE_INSTALL_LIBDIR})
12497
install(FILES ${docopt_HEADERS} DESTINATION include/docopt)
12598

12699
# CMake Package

0 commit comments

Comments
 (0)
0