Skip to content

Commit

Permalink
(conan-io#14138) libev: msvc support
Browse files Browse the repository at this point in the history
* libev for msvc

* * remove cmake from patch

* Apply suggestions from code review

Co-authored-by: SpaceIm <30052553+SpaceIm@users.noreply.github.com>

* * remove config from patch

* * conanfile depended export

* * remove patches

* do not copy CMakeLists to src folder

* Apply suggestions from code review

Co-authored-by: SpaceIm <30052553+SpaceIm@users.noreply.github.com>

Co-authored-by: SpaceIm <30052553+SpaceIm@users.noreply.github.com>
  • Loading branch information
2 people authored and StellaSmith committed Feb 2, 2023
1 parent bf7beae commit a308ef4
Show file tree
Hide file tree
Showing 3 changed files with 181 additions and 13 deletions.
22 changes: 22 additions & 0 deletions recipes/libev/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
cmake_minimum_required(VERSION 3.14)
project(ev C)

set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)

set(EV_PUBLIC_HEADERS
"${EV_SRC_DIR}/ev.h"
"${EV_SRC_DIR}/config.h")
add_library(ev "${EV_SRC_DIR}/ev.c")
target_link_libraries(ev PUBLIC ws2_32)
target_compile_definitions(ev PRIVATE HAVE_CONFIG_H=1)
target_include_directories(ev PUBLIC ${EV_SRC_DIR})

set_target_properties(ev PROPERTIES PUBLIC_HEADER "${EV_PUBLIC_HEADERS}")
include(GNUInstallDirs)

install(TARGETS ev
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
44 changes: 31 additions & 13 deletions recipes/libev/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from conan.tools.env import VirtualBuildEnv
from conan.tools.files import copy, get, rm, rmdir
from conan.tools.gnu import Autotools, AutotoolsToolchain
from conan.tools.cmake import CMake, CMakeToolchain
from conan.tools.layout import basic_layout
from conan.tools.microsoft import is_msvc, unix_path
import os
Expand Down Expand Up @@ -33,6 +34,10 @@ class LibevConan(ConanFile):
def _settings_build(self):
return getattr(self, "settings_build", self.settings)

def export_sources(self):
copy(self, "CMakeLists.txt", self.recipe_folder, dst=self.export_sources_folder)
copy(self, "config.h", self.recipe_folder, self.export_sources_folder)

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
Expand All @@ -47,14 +52,12 @@ def layout(self):
basic_layout(self, src_folder="src")

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

def build_requirements(self):
if self._settings_build.os == "Windows":
if self._settings_build.os == "Windows" and not is_msvc(self):
self.win_bash = True
if not self.conf.get("tools.microsoft.bash:path", check_type=str):
self.tool_requires("msys2/cci.latest")
Expand All @@ -64,21 +67,36 @@ def source(self):
destination=self.source_folder, strip_root=True)

def generate(self):
env = VirtualBuildEnv(self)
env.generate()
tc = AutotoolsToolchain(self)
tc.generate()
if is_msvc(self):
tc = CMakeToolchain(self)
tc.variables["EV_SRC_DIR"] = self.source_folder.replace("\\", "/")
tc.generate()
else:
env = VirtualBuildEnv(self)
env.generate()
tc = AutotoolsToolchain(self)
tc.generate()

def build(self):
autotools = Autotools(self)
autotools.configure()
autotools.make()
if is_msvc(self):
base_folder = os.path.join(self.source_folder, os.pardir)
copy(self, "config.h", src=base_folder, dst=self.source_folder)
cmake = CMake(self)
cmake.configure(build_script_folder=base_folder)
cmake.build()
else:
autotools = Autotools(self)
autotools.configure()
autotools.make()

def package(self):
copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
autotools = Autotools(self)
# TODO: replace by autotools.install() once https://github.com/conan-io/conan/issues/12153 fixed
autotools.install(args=[f"DESTDIR={unix_path(self, self.package_folder)}"])
if is_msvc(self):
cmake = CMake(self)
cmake.install()
else:
autotools = Autotools(self)
autotools.install(args=[f"DESTDIR={unix_path(self, self.package_folder)}"])
rmdir(self, os.path.join(self.package_folder, "share"))
rm(self, "*.la", os.path.join(self.package_folder, "lib"))
fix_apple_shared_install_name(self)
Expand Down
128 changes: 128 additions & 0 deletions recipes/libev/all/config.h
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit a308ef4

Please sign in to comment.