]> granicus.if.org Git - libevent/commitdiff
cmake: do not build both (SHARED and STATIC) for MSVC/win32
authorAzat Khuzhin <a3at.mail@gmail.com>
Thu, 22 Nov 2018 21:29:55 +0000 (00:29 +0300)
committerAzat Khuzhin <a3at.mail@gmail.com>
Thu, 22 Nov 2018 21:41:18 +0000 (00:41 +0300)
MSVC does not support SHARED and STATIC libraries with the same name,
so let's just build SHARED libraries by default instead (yes we can add
prefix but let's stick with this).

The reason for this is that in windows shared libraries requires .lib
file too, but this is not static library it is imported library for
shared (doh...), for more info [1] and [2].

  [1]: https://docs.microsoft.com/en-us/windows/desktop/dlls/dynamic-link-library-creation
  [2]: https://blogs.msdn.microsoft.com/oldnewthing/20091013-00/?p=16403

And when we build both static library can and will override shared
library imported part, let's take a look at event_extra.lib:

- before patch [3]:
  $ less libevent-fail/lib/Debug/event_extra.lib | head
  ==> use library:contained_file to view a file in the archive
  rw-rw-rw- 100666/100666  59568 Nov 21 23:55 2018 event_extra_static.dir/Debug/evrpc.obj
  rw-rw-rw- 100666/100666 252219 Nov 21 23:55 2018 event_extra_static.dir/Debug/evdns.obj
  rw-rw-rw- 100666/100666 203850 Nov 21 23:55 2018 event_extra_static.dir/Debug/http.obj
  rw-rw-rw- 100666/100666  25907 Nov 21 23:55 2018 event_extra_static.dir/Debug/event_tagging.obj

  [3]: https://ci.appveyor.com/project/azat/libevent/builds/20472024/job/t0o93v042jai0dj7

- "after patch" [4] (not after but the same effect):
  $ less libevent-ok/lib/Debug/event_extra.lib | head
  ==> use library:contained_file to view a file in the archive
  --------- 0/0    509 Nov 21 23:38 2018 event_extra.dll
  ...

  [4]: https://ci.appveyor.com/project/azat/libevent/builds/20478998/job/ca9k3c76amc4qr76

Refs: #691

CMakeLists.txt
README.md

index c6026a34fd3c9f0a61fc3092eafff36238193e75..d41e25fa827bd13383fc69c2f363fe2ad3c2aa74 100644 (file)
@@ -42,7 +42,7 @@ string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWER)
 set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "Limited configurations" FORCE)
 
 set(EVENT__LIBRARY_TYPE DEFAULT CACHE STRING
-    "Set library type to SHARED/STATIC/BOTH (default BOTH)")
+    "Set library type to SHARED/STATIC/BOTH (default SHARED for MSVC, otherwise BOTH)")
 
 project(libevent C)
 
@@ -179,21 +179,35 @@ endif()
 
 set(GNUC 0)
 set(CLANG 0)
+set(MSVC 0)
 if (("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang") OR
     ("${CMAKE_C_COMPILER_ID}" STREQUAL "AppleClang"))
     set(CLANG 1)
 endif()
-if ((${CMAKE_C_COMPILER_ID} STREQUAL GNU) OR (${CLANG}))
+if (("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") OR (${CLANG}))
     set(GNUC 1)
 endif()
+if (("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC") OR (${CLANG}))
+    set(MSVC 1)
+endif()
 
 # Detect library type
 set(EVENT_LIBRARY_TYPE)
 if ("${EVENT__LIBRARY_TYPE}" STREQUAL "DEFAULT")
-    set(EVENT_LIBRARY_TYPE BOTH)
+    if (${MSVC})
+        set(EVENT_LIBRARY_TYPE SHARED)
+    else()
+        set(EVENT_LIBRARY_TYPE BOTH)
+    endif()
 else()
     string(TOUPPER "${EVENT__LIBRARY_TYPE}" EVENT_LIBRARY_TYPE)
 endif()
+if ((${MSVC}) AND ("${EVENT_LIBRARY_TYPE}" STREQUAL "BOTH"))
+    message(WARNING
+      "Building SHARED and STATIC is not supported for MSVC "
+      "(due to conflicts in library name"
+      " between STATIC library and IMPORTED library for SHARED libraries)")
+endif()
 set(EVENT_LIBRARY_STATIC OFF)
 set(EVENT_LIBRARY_SHARED OFF)
 if ("${EVENT_LIBRARY_TYPE}" STREQUAL "BOTH")
index 61735731f65b17b8520c3888e1470badc7e08051..5d66021c73947d4f03d38bb670c5c28b6988fe80 100644 (file)
--- a/README.md
+++ b/README.md
@@ -28,7 +28,7 @@ the default).
 
 ```
 # Type of the library to build (SHARED or STATIC)
-# Default is to build BOTH
+# Default is: SHARED for MSVC, otherwise BOTH
 EVENT__LIBRARY_TYPE:STRING=DEFAULT
 
 # Installation directory for CMake files