1 From 045b035bd9ebbd45f40dda36b143ede869eb5f16 Mon Sep 17 00:00:00 2001
2 From: Sagaert Johan <sagaert.johan@skynet.be>
3 Date: Fri, 31 Oct 2014 12:25:48 +0100
4 Subject: [PATCH 2/2] cmake: disable shared library build when
5 BUILD_SHARED_LIBS is off
7 Original patch from Samuel Martin, reworked by Sagaert Johan when
8 updating libwebsockets.
10 Signed-off-by: Samuel Martin <s.martin49@gmail.com>
11 Signed-off-by: Sagaert Johan <sagaert.johan@skynet.be>
12 [yann.morin.1998@free.fr: further fix after the version bumped]
13 Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
15 CMakeLists.txt | 17 ++++++++++++-----
16 1 file changed, 12 insertions(+), 5 deletions(-)
18 diff --git a/CMakeLists.txt b/CMakeLists.txt
19 index 7978845..89853ce 100644
22 @@ -372,14 +372,19 @@ source_group("Sources" FILES ${SOURCES})
26 +set(_libs_websockets websockets)
27 add_library(websockets STATIC
32 +if(BUILD_SHARED_LIBS)
33 +list(APPEND _libs_websockets websockets_shared)
34 add_library(websockets_shared SHARED
41 # On Windows libs have the same file ending (.lib)
42 @@ -400,15 +405,17 @@ endif(WIN32)
44 # We want the shared lib to be named "libwebsockets"
45 # not "libwebsocket_shared".
46 +if(BUILD_SHARED_LIBS)
47 set_target_properties(websockets_shared
50 OUTPUT_NAME websockets)
53 # Set the so version of the lib.
54 # Equivalent to LDFLAGS=-version-info x:x:x
55 if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
56 - foreach(lib websockets websockets_shared)
57 - set_target_properties(${lib}
58 + foreach(lib ${_libs_websockets})
59 + set_target_properties(${lib}
61 SOVERSION ${SOVERSION})
63 @@ -460,7 +467,7 @@ if (NOT LWS_WITHOUT_EXTENSIONS)
66 # Make sure ZLib is compiled before the libs.
67 - foreach (lib websockets websockets_shared)
68 + foreach (lib ${_libs_websockets})
69 add_dependencies(${lib} ZLIB)
72 @@ -524,7 +531,7 @@ if (UNIX)
75 # Setup the linking for all libs.
76 -foreach (lib websockets websockets_shared)
77 +foreach (lib ${_libs_websockets})
78 target_link_libraries(${lib} ${LIB_LIST})
82 set(LWS_INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH "Installation directory for CMake files")
84 # Export targets (This is used for other CMake projects to easily find the libraries and include files).
85 -export(TARGETS websockets websockets_shared
86 +export(TARGETS ${_libs_websockets}
87 FILE "${PROJECT_BINARY_DIR}/LibwebsocketsTargets.cmake")
88 export(PACKAGE libwebsockets)
91 ${PROJECT_BINARY_DIR}/LibwebsocketsConfigVersion.cmake
94 -set_target_properties(websockets websockets_shared
95 +set_target_properties(${_libs_websockets}
96 PROPERTIES PUBLIC_HEADER "${HDR_PUBLIC}")
102 # Install libs and headers.
103 -install(TARGETS websockets websockets_shared
104 +install(TARGETS ${_libs_websockets}
105 EXPORT LibwebsocketsTargets
106 LIBRARY DESTINATION "${LWS_INSTALL_LIB_DIR}${LIB_SUFFIX}" COMPONENT libraries
107 ARCHIVE DESTINATION "${LWS_INSTALL_LIB_DIR}${LIB_SUFFIX}" COMPONENT libraries