Skip to content

Commit

Permalink
(#7986) glfw: add 3.3.5 + modernize
Browse files Browse the repository at this point in the history
* add glfw/3.3.5

* modernize

* bump vulkan-loader
  • Loading branch information
SpaceIm authored Nov 8, 2021
1 parent 43d973c commit e9ff3b4
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 27 deletions.
3 changes: 3 additions & 0 deletions recipes/glfw/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
sources:
"3.3.5":
url: "https://github.com/glfw/glfw/archive/refs/tags/3.3.5.tar.gz"
sha256: "32fdb8705784adfe3082f97e0d41e7c515963e977b5a14c467a887cf0da827b5"
"3.3.4":
url: "https://github.com/glfw/glfw/archive/3.3.4.tar.gz"
sha256: "cc8ac1d024a0de5fd6f68c4133af77e1918261396319c24fd697775a6bc93b63"
Expand Down
52 changes: 27 additions & 25 deletions recipes/glfw/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import os
import glob
from conans import ConanFile, CMake, tools
import os
import textwrap

required_conan_version = ">=1.28.0"
required_conan_version = ">=1.36.0"


class GlfwConan(ConanFile):
Expand All @@ -13,7 +13,7 @@ class GlfwConan(ConanFile):
license = "Zlib"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/glfw/glfw"
topics = ("conan", "gflw", "opengl", "vulkan", "opengl-es")
topics = ("graphics", "opengl", "vulkan", "opengl-es")

settings = "os", "arch", "build_type", "compiler"
options = {
Expand All @@ -27,14 +27,18 @@ class GlfwConan(ConanFile):
"vulkan_static": False,
}

exports_sources = ["CMakeLists.txt", "patches/**"]
generators = "cmake"
_cmake = None

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

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
Expand All @@ -48,14 +52,13 @@ def configure(self):
def requirements(self):
self.requires("opengl/system")
if self.options.vulkan_static:
self.requires("vulkan-loader/1.2.162.0")
self.requires("vulkan-loader/1.2.182")
if self.settings.os == "Linux":
self.requires("xorg/system")

def source(self):
tools.get(**self.conan_data["sources"][self.version])
extracted_dir = "{}-{}".format(self.name, self.version)
os.rename(extracted_dir, self._source_subfolder)
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, []):
Expand Down Expand Up @@ -99,40 +102,39 @@ def package(self):
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_subfolder, self._module_file),
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 += (
"if(TARGET {aliased} AND NOT TARGET {alias})\n"
" add_library({alias} INTERFACE IMPORTED)\n"
" set_property(TARGET {alias} PROPERTY INTERFACE_LINK_LIBRARIES {aliased})\n"
"endif()\n"
).format(alias=alias, aliased=aliased)
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_subfolder(self):
return os.path.join("lib", "cmake")

@property
def _module_file(self):
return "conan-official-{}-targets.cmake".format(self.name)
def _module_file_rel_path(self):
return os.path.join(self._module_subfolder,
"conan-official-{}-targets.cmake".format(self.name))

def package_info(self):
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.names["pkg_config"] = "glfw3"
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")
self.cpp_info.builddirs.append(self._module_subfolder)
self.cpp_info.build_modules = [os.path.join(self._module_subfolder, self._module_file)]
self.cpp_info.set_property("cmake_build_modules", [self._module_file_rel_path])
self.cpp_info.libs = tools.collect_libs(self)
if self.settings.os == "Linux":
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")
Expand Down
4 changes: 2 additions & 2 deletions recipes/glfw/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package_multi"

def build(self):
Expand All @@ -12,6 +12,6 @@ def build(self):
cmake.build()

def test(self):
if not tools.cross_building(self.settings):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
2 changes: 2 additions & 0 deletions recipes/glfw/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
versions:
"3.3.5":
folder: all
"3.3.4":
folder: all
"3.3.3":
Expand Down

0 comments on commit e9ff3b4

Please sign in to comment.