1#!/usr/bin/env python
2# -*- coding: utf-8 -*
3from conans import ConanFile, tools, CMake
4
5
6class civetwebConan(ConanFile):
7    name = "civetweb"
8    license = "MIT"
9    url = "https://github.com/civetweb/civetweb"
10    description = "Embedded C/C++ web server"
11    author = "Bernhard Lehner <bel2125@gmail.com>"
12    topics = ("conan", "civetweb", "web-server", "embedded")
13    exports = ("LICENSE.md", "README.md")
14    exports_sources = ("src/*", "cmake/*", "include/*", "CMakeLists.txt")
15    generators = "cmake"
16    settings = "os", "compiler", "build_type", "arch"
17    options = {
18        "shared"            : [True, False],
19        "fPIC"              : [True, False],
20        "enable_ssl"        : [True, False],
21        "enable_websockets" : [True, False],
22        "enable_ipv6"       : [True, False],
23        "enable_cxx"        : [True, False]
24    }
25    default_options = {
26        "shared"            : False,
27        "fPIC"              : True,
28        "enable_ssl"        : True,
29        "enable_websockets" : True,
30        "enable_ipv6"       : True,
31        "enable_cxx"        : True
32    }
33
34    def config_options(self):
35        if self.settings.os == 'Windows':
36            del self.options.fPIC
37
38    def configure(self):
39        if not self.options.enable_cxx:
40            del self.settings.compiler.libcxx
41
42    def requirements(self):
43        if self.options.enable_ssl:
44            self.requires("OpenSSL/1.0.2q@conan/stable")
45
46    def _configure_cmake(self):
47        cmake = CMake(self)
48        cmake.verbose = True
49        cmake.definitions["CIVETWEB_ENABLE_SSL"] = self.options.enable_ssl
50        cmake.definitions["CIVETWEB_ENABLE_WEBSOCKETS"] = self.options.enable_websockets
51        cmake.definitions["CIVETWEB_ENABLE_IPV6"] = self.options.enable_ipv6
52        cmake.definitions["CIVETWEB_ENABLE_CXX"] = self.options.enable_cxx
53        cmake.definitions["CIVETWEB_BUILD_TESTING"] = False
54        cmake.definitions["CIVETWEB_ENABLE_ASAN"] = False
55        cmake.configure(build_dir="build_subfolder")
56        return cmake
57
58    def build(self):
59        tools.replace_in_file(file_path="CMakeLists.txt",
60                              search="project (civetweb)",
61                              replace="""project (civetweb)
62                                 include(conanbuildinfo.cmake)
63                                 conan_basic_setup()""")
64        cmake = self._configure_cmake()
65        cmake.build()
66
67    def package(self):
68        self.copy("LICENSE.md", dst="licenses")
69        cmake = self._configure_cmake()
70        cmake.install()
71
72    def package_info(self):
73        self.cpp_info.libs = tools.collect_libs(self)
74        if self.settings.os == "Linux":
75            self.cpp_info.libs.extend(["dl", "rt", "pthread"])
76            if self.options.enable_cxx:
77                self.cpp_info.libs.append("m")
78        elif self.settings.os == "Macos":
79            self.cpp_info.exelinkflags.append("-framework Cocoa")
80            self.cpp_info.sharedlinkflags = self.cpp_info.exelinkflags
81            self.cpp_info.defines.append("USE_COCOA")
82        elif self.settings.os == "Windows":
83            self.cpp_info.libs.append("Ws2_32")
84        if self.options.enable_websockets:
85            self.cpp_info.defines.append("USE_WEBSOCKET")
86        if self.options.enable_ipv6:
87            self.cpp_info.defines.append("USE_IPV6")
88        if not self.options.enable_ssl:
89            self.cpp_info.defines.append("NO_SSL")
90