-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
conanfile.py
154 lines (134 loc) · 6.3 KB
/
conanfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
from conan.tools.microsoft import msvc_runtime_flag
from conans import ConanFile, CMake, tools
import os
import textwrap
required_conan_version = ">=1.43.0"
class GlfwConan(ConanFile):
name = "glfw"
description = "GLFW is a free, Open Source, multi-platform library for OpenGL, OpenGL ES and Vulkan" \
"application development. It provides a simple, platform-independent API for creating" \
"windows, contexts and surfaces, reading input, handling events, etc."
license = "Zlib"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/glfw/glfw"
topics = ("graphics", "opengl", "vulkan", "opengl-es")
settings = "os", "arch", "build_type", "compiler"
options = {
"shared": [True, False],
"fPIC": [True, False],
"vulkan_static": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"vulkan_static": False,
}
generators = "cmake"
_cmake = None
@property
def _source_subfolder(self):
return "source_subfolder"
@property
def _is_msvc(self):
return str(self.settings.compiler) in ["Visual Studio", "msvc"]
def export_sources(self):
self.copy("CMakeLists.txt")
for patch in self.conan_data.get("patches", {}).get(self.version, []):
self.copy(patch["patch_file"])
def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
def configure(self):
if self.options.shared:
del self.options.fPIC
del self.settings.compiler.libcxx
del self.settings.compiler.cppstd
def requirements(self):
self.requires("opengl/system")
if self.options.vulkan_static:
self.requires("vulkan-loader/1.2.198.0")
if self.settings.os == "Linux":
self.requires("xorg/system")
def source(self):
tools.get(**self.conan_data["sources"][self.version],
destination=self._source_subfolder, strip_root=True)
def _patch_sources(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
# don't force PIC
tools.replace_in_file(os.path.join(self._source_subfolder, "src", "CMakeLists.txt"),
"POSITION_INDEPENDENT_CODE ON", "")
# Allow to link vulkan-loader into shared glfw
if self.options.vulkan_static:
cmakelists = os.path.join(self._source_subfolder, "CMakeLists.txt")
tools.replace_in_file(cmakelists,
'message(FATAL_ERROR "You are trying to link the Vulkan loader static library into the GLFW shared library")',
"")
tools.replace_in_file(cmakelists,
'list(APPEND glfw_PKG_DEPS "vulkan")',
('list(APPEND glfw_PKG_DEPS "vulkan")\n'
'list(APPEND glfw_LIBRARIES "{}")').format(self.deps_cpp_info["vulkan-loader"].libs[0]))
def _configure_cmake(self):
if not self._cmake:
self._cmake = CMake(self)
self._cmake.definitions["GLFW_BUILD_EXAMPLES"] = False
self._cmake.definitions["GLFW_BUILD_TESTS"] = False
self._cmake.definitions["GLFW_BUILD_DOCS"] = False
self._cmake.definitions["GLFW_INSTALL"] = True
self._cmake.definitions["GLFW_VULKAN_STATIC"] = self.options.vulkan_static
if self._is_msvc:
self._cmake.definitions["USE_MSVC_RUNTIME_LIBRARY_DLL"] = "MD" in msvc_runtime_flag(self)
self._cmake.configure()
return self._cmake
def build(self):
self._patch_sources()
cmake = self._configure_cmake()
cmake.build()
def package(self):
self.copy("LICENSE*", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
cmake.install()
tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
self._create_cmake_module_alias_targets(
os.path.join(self.package_folder, self._module_file_rel_path),
{"glfw": "glfw::glfw"}
)
@staticmethod
def _create_cmake_module_alias_targets(module_file, targets):
content = ""
for alias, aliased in targets.items():
content += textwrap.dedent("""\
if(TARGET {aliased} AND NOT TARGET {alias})
add_library({alias} INTERFACE IMPORTED)
set_property(TARGET {alias} PROPERTY INTERFACE_LINK_LIBRARIES {aliased})
endif()
""".format(alias=alias, aliased=aliased))
tools.save(module_file, content)
@property
def _module_file_rel_path(self):
return os.path.join("lib", "cmake", "conan-official-{}-targets.cmake".format(self.name))
def package_info(self):
self.cpp_info.set_property("cmake_file_name", "glfw3")
self.cpp_info.set_property("cmake_target_name", "glfw")
self.cpp_info.set_property("pkg_config_name", "glfw3")
libname = "glfw"
if self.settings.os == "Windows" or not self.options.shared:
libname += "3"
if self._is_msvc and self.options.shared:
libname += "dll"
self.cpp_info.libs = [libname]
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs.extend(["m", "pthread", "dl", "rt"])
elif self.settings.os == "Windows":
self.cpp_info.system_libs.append("gdi32")
elif self.settings.os == "Macos":
self.cpp_info.frameworks.extend(["Cocoa", "IOKit", "CoreFoundation"])
# backward support of cmake_find_package, cmake_find_package_multi & pkg_config generators
self.cpp_info.filenames["cmake_find_package"] = "glfw3"
self.cpp_info.filenames["cmake_find_package_multi"] = "glfw3"
self.cpp_info.names["cmake_find_package"] = "glfw"
self.cpp_info.names["cmake_find_package_multi"] = "glfw"
self.cpp_info.build_modules["cmake_find_package"] = [self._module_file_rel_path]
self.cpp_info.build_modules["cmake_find_package_multi"] = [self._module_file_rel_path]
self.cpp_info.names["pkg_config"] = "glfw3"