Skip to content

Commit

Permalink
libev for msvc
Browse files Browse the repository at this point in the history
  • Loading branch information
xakod committed Nov 10, 2022
1 parent 1998229 commit 0ce2955
Show file tree
Hide file tree
Showing 3 changed files with 303 additions and 21 deletions.
7 changes: 7 additions & 0 deletions recipes/libev/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,10 @@ sources:
"4.25":
sha256: 78757e1c27778d2f3795251d9fe09715d51ce0422416da4abb34af3929c02589
url: http://dist.schmorp.de/libev/Attic/libev-4.25.tar.gz
patches:
"4.33":
- patch_file: "patches/0001-cmake-for-msvc.patch"
"4.27":
- patch_file: "patches/0001-cmake-for-msvc.patch"
"4.25":
- patch_file: "patches/0001-cmake-for-msvc.patch"
63 changes: 42 additions & 21 deletions recipes/libev/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from conans import ConanFile, AutoToolsBuildEnvironment, tools
from conan import ConanFile
from conan.tools.gnu import Autotools
from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps, cmake_layout
from conans.errors import ConanInvalidConfiguration
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, replace_in_file, rmdir, rm
import functools
import os

required_conan_version = ">=1.33.0"
required_conan_version = ">=1.51.0"


class LibevConan(ConanFile):
Expand All @@ -24,9 +27,9 @@ class LibevConan(ConanFile):
"fPIC": True,
}

@property
def _source_subfolder(self):
return "source_subfolder"

def export_sources(self):
export_conandata_patches(self)

@property
def _is_msvc(self):
Expand All @@ -47,31 +50,34 @@ def configure(self):
del self.settings.compiler.cppstd

def validate(self):
if self._is_msvc:
raise ConanInvalidConfiguration("libev is not supported by Visual Studio")
# if self._is_msvc:
# raise ConanInvalidConfiguration("libev is not supported by Visual Studio")
if self.settings.os == "Windows" and self.options.shared:
# libtool: error: can't build i686-pc-mingw32 shared library unless -no-undefined is specified
raise ConanInvalidConfiguration("libev can't be built as shared on Windows")

def build_requirements(self):
if self._settings_build.os == "Windows" and not tools.get_env("CONAN_BASH_PATH"):
if self._settings_build.os == "Windows" and not self._is_msvc:
self.build_requires("msys2/cci.latest")

def source(self):
tools.get(**self.conan_data["sources"][self.version],
destination=self._source_subfolder, strip_root=True)
get(self, **self.conan_data["sources"][self.version],
destination=self.source_folder, strip_root=True)

def layout(self):
cmake_layout(self)

def _patch_sources(self):
# relocatable shared lib on macOS
tools.replace_in_file(
replace_in_file(
os.path.join(self._source_subfolder, "configure"),
"-install_name \\$rpath/",
"-install_name @rpath/",
)

@functools.lru_cache(1)
def _configure_autotools(self):
autotools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows)
autotools = Autotools(self, win_bash = self._settings_build.os == "Windows")
yes_no = lambda v: "yes" if v else "no"
args = [
"--enable-shared={}".format(yes_no(self.options.shared)),
Expand All @@ -80,18 +86,33 @@ def _configure_autotools(self):
autotools.configure(args=args, configure_dir=self._source_subfolder)
return autotools

def generate(self):
tc = CMakeToolchain(self)
tc.generate()
tc = CMakeDeps(self)
tc.generate()


def build(self):
self._patch_sources()
autotools = self._configure_autotools()
autotools.make()
apply_conandata_patches(self)
if self._is_msvc:
cmake = CMake(self)
cmake.configure()
cmake.build()
else:
autotools = self._configure_autotools()
autotools.make()

def package(self):
self.copy(pattern="LICENSE", dst="licenses", src=self._source_subfolder)
autotools = self._configure_autotools()
autotools.install()

tools.rmdir(os.path.join(self.package_folder, "share"))
tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*.la")
copy(self, "COPYING", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
if self._is_msvc:
cmake = CMake(self)
cmake.install()
else:
autotools = self._configure_autotools()
autotools.install()
rmdir(self, os.path.join(self.package_folder, "share"))
rm(self,"*.la",os.path.join(self.package_folder, "lib"))

def package_info(self):
self.cpp_info.libs = ["ev"]
Expand Down
254 changes: 254 additions & 0 deletions recipes/libev/all/patches/0001-cmake-for-msvc.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,254 @@
From bb07532831ddb1fb379e2314d96b54e9dd601049 Mon Sep 17 00:00:00 2001
From: Jihadist <tomasiche@gmail.com>
Date: Wed, 9 Nov 2022 20:48:19 +0300
Subject: [PATCH 2/2] cmake for msvc

---
CMakeLists.txt | 30 ++++++++++
config.h | 128 +++++++++++++++++++++++++++++++++++++++++++
internal_utils.cmake | 65 ++++++++++++++++++++++
3 files changed, 223 insertions(+)
create mode 100644 CMakeLists.txt
create mode 100644 config.h
create mode 100644 internal_utils.cmake

diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..9a94160
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,26 @@
+cmake_minimum_required(VERSION 3.14)
+project(ev C)
+
+include(internal_utils.cmake)
+config_compiler_and_linker()
+
+set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
+
+set(LIBEV_PUBLIC_HEADERS
+ ev.h
+ config.h)
+add_library(ev ev.c ${LIBEV_PUBLIC_HEADERS})
+target_link_libraries(ev PUBLIC ws2_32)
+target_compile_definitions(ev PRIVATE HAVE_CONFIG_H=1)
+target_include_directories(ev PUBLIC ${PROJECT_SOURCE_DIR})
+
+
+set_target_properties(ev PROPERTIES PUBLIC_HEADER "${LIBEV_PUBLIC_HEADERS}")
+include(GNUInstallDirs)
+
+install(TARGETS ev
+ EXPORT ${EXPORT_NAME}Targets DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT runtime
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT devel
+ PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT devel
+)
diff --git a/config.h b/config.h
new file mode 100644
index 0000000..0832712
--- /dev/null
+++ b/config.h
@@ -0,0 +1,128 @@
+/* config.h.in. Generated from configure.ac by autoheader. */
+
+/* Define to 1 if you have the `clock_gettime' function. */
+#undef HAVE_CLOCK_GETTIME
+
+/* Define to 1 to use the syscall interface for clock_gettime */
+#undef HAVE_CLOCK_SYSCALL
+
+/* Define to 1 if you have the <dlfcn.h> header file. */
+#undef HAVE_DLFCN_H
+
+/* Define to 1 if you have the `epoll_ctl' function. */
+#undef HAVE_EPOLL_CTL
+
+/* Define to 1 if you have the `eventfd' function. */
+#undef HAVE_EVENTFD
+
+/* Define to 1 if the floor function is available */
+#undef HAVE_FLOOR
+
+/* Define to 1 if you have the `inotify_init' function. */
+#undef HAVE_INOTIFY_INIT
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+#undef HAVE_INTTYPES_H
+
+/* Define to 1 if you have the `kqueue' function. */
+#undef HAVE_KQUEUE
+
+/* Define to 1 if you have the `rt' library (-lrt). */
+#undef HAVE_LIBRT
+
+/* Define to 1 if you have the <memory.h> header file. */
+#undef HAVE_MEMORY_H
+
+/* Define to 1 if you have the `nanosleep' function. */
+#undef HAVE_NANOSLEEP
+
+/* Define to 1 if you have the `poll' function. */
+#undef HAVE_POLL
+
+/* Define to 1 if you have the <poll.h> header file. */
+#undef HAVE_POLL_H
+
+/* Define to 1 if you have the `port_create' function. */
+#undef HAVE_PORT_CREATE
+
+/* Define to 1 if you have the <port.h> header file. */
+#undef HAVE_PORT_H
+
+/* Define to 1 if you have the `select' function. */
+#undef HAVE_SELECT
+
+/* Define to 1 if you have the `signalfd' function. */
+#undef HAVE_SIGNALFD
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#undef HAVE_STDINT_H
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#undef HAVE_STDLIB_H
+
+/* Define to 1 if you have the <strings.h> header file. */
+#undef HAVE_STRINGS_H
+
+/* Define to 1 if you have the <string.h> header file. */
+#undef HAVE_STRING_H
+
+/* Define to 1 if you have the <sys/epoll.h> header file. */
+#undef HAVE_SYS_EPOLL_H
+
+/* Define to 1 if you have the <sys/eventfd.h> header file. */
+#undef HAVE_SYS_EVENTFD_H
+
+/* Define to 1 if you have the <sys/event.h> header file. */
+#undef HAVE_SYS_EVENT_H
+
+/* Define to 1 if you have the <sys/inotify.h> header file. */
+#undef HAVE_SYS_INOTIFY_H
+
+/* Define to 1 if you have the <sys/select.h> header file. */
+#undef HAVE_SYS_SELECT_H
+
+/* Define to 1 if you have the <sys/signalfd.h> header file. */
+#undef HAVE_SYS_SIGNALFD_H
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#undef HAVE_SYS_STAT_H
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#undef HAVE_SYS_TYPES_H
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#undef HAVE_UNISTD_H
+
+/* Define to the sub-directory in which libtool stores uninstalled libraries.
+ */
+#undef LT_OBJDIR
+
+/* Name of package */
+#undef PACKAGE
+
+/* Define to the address where bug reports for this package should be sent. */
+#undef PACKAGE_BUGREPORT
+
+/* Define to the full name of this package. */
+#undef PACKAGE_NAME
+
+/* Define to the full name and version of this package. */
+#undef PACKAGE_STRING
+
+/* Define to the one symbol short name of this package. */
+#undef PACKAGE_TARNAME
+
+/* Define to the home page for this package. */
+#undef PACKAGE_URL
+
+/* Define to the version of this package. */
+#undef PACKAGE_VERSION
+
+/* Define to 1 if you have the ANSI C header files. */
+#undef STDC_HEADERS
+
+/* Version number of package */
+#undef VERSION
+
+#define HAVE_SELECT 1
+#define HAVE_SYS_SELECT_H 1
diff --git a/internal_utils.cmake b/internal_utils.cmake
new file mode 100644
index 0000000..f738e79
--- /dev/null
+++ b/internal_utils.cmake
@@ -0,0 +1,65 @@
+macro(fix_default_compiler_settings_)
+ if (MSVC)
+ foreach (flag_var
+ CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
+ CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
+ # We prefer more strict warning checking for building Google Test.
+ # Replaces /W3 with /W4 in defaults.
+ string(REPLACE "/W3" "/W4" ${flag_var} "${${flag_var}}")
+ endforeach()
+ endif()
+endmacro()
+
+# Defines the compiler/linker flags used to build
+macro(config_compiler_and_linker)
+ # Defines CMAKE_USE_PTHREADS_INIT and CMAKE_THREAD_LIBS_INIT.
+ find_package(Threads)
+ fix_default_compiler_settings_()
+
+ if (MSVC)
+ set(cxx_base_flags "-GS -W4 -wd4251 -wd4275 -nologo -J -Zi -DWIN32")
+ if (MSVC_VERSION LESS 1400) # 1400 is Visual Studio 2005
+ # Suppress spurious warnings MSVC 7.1 sometimes issues.
+ # Forcing value to bool.
+ set(cxx_base_flags "${cxx_base_flags} -wd4800")
+ # Copy constructor and assignment operator could not be generated.
+ set(cxx_base_flags "${cxx_base_flags} -wd4511 -wd4512")
+ # Compatibility warnings not applicable to Google Test.
+ # Resolved overload was found by argument-dependent lookup.
+ set(cxx_base_flags "${cxx_base_flags} -wd4675")
+ endif()
+ if (MSVC_VERSION LESS 1500) # 1500 is Visual Studio 2008
+ # Conditional expression is constant.
+ # When compiling with /W4, we get several instances of C4127
+ # (Conditional expression is constant). In our code, we disable that
+ # warning on a case-by-case basis. However, on Visual Studio 2005,
+ # the warning fires on std::list. Therefore on that compiler and earlier,
+ # we disable the warning project-wide.
+ set(cxx_base_flags "${cxx_base_flags} -wd4127")
+ endif()
+ if (NOT (MSVC_VERSION LESS 1700)) # 1700 is Visual Studio 2012.
+ # Suppress "unreachable code" warning on VS 2012 and later.
+ # http://stackoverflow.com/questions/3232669 explains the issue.
+ set(cxx_base_flags "${cxx_base_flags} -wd4702")
+ endif()
+# if (NOT (MSVC_VERSION GREATER 1900)) # 1900 is Visual Studio 2015
+# # BigObj required for tests.
+# set(cxx_base_flags "${cxx_base_flags} -bigobj")
+# endif()
+
+ set(cxx_flags "${cxx_base_flags} -D_UNICODE -DUNICODE -DWIN32 -D_WIN32")
+ set(cxx_flags "${cxx_base_flags} -DSTRICT -DWIN32_LEAN_AND_MEAN")
+ set(c_flags "${cxx_flags}")
+ set(CMAKE_CXX_FLAGS "${cxx_flags}")
+ set(CMAKE_C_FLAGS "${c_flags}")
+
+ elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang" OR ${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
+ set(base_flags "-fpic -pthread -O2 -g -fno-strict-aliasing -fwrapv -Wall -Wextra")
+ set(base_flags "${base_flags} -Wno-unused-parameter -Wno-unused-variable -Wno-unused-but-set-variable -Wno-unused-function")
+ set(cxx_flags "-std=c++11 ${base_flags}")
+ set(c_flags "-std=gnu11 ${base_flags}")
+ set(CMAKE_CXX_FLAGS "${cxx_flags}")
+ set(CMAKE_C_FLAGS "${c_flags}")
+ endif()
+endmacro()
+
--
2.34.1.windows.1

0 comments on commit 0ce2955

Please sign in to comment.