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
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)
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")
```
# 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