freeglut/3.2.1

Open-source alternative to the OpenGL Utility Toolkit (GLUT) library
X11
License
3.2.1
Version
162
Downloads
Loading...
Loading...
1
from conans import ConanFile, CMake, tools
2
from conans.errors import ConanInvalidConfiguration
3
import os
4
5
required_conan_version = ">=1.43.0"
6
7
8
class freeglutConan(ConanFile):
9
    name = "freeglut"
10
    description = "Open-source alternative to the OpenGL Utility Toolkit (GLUT) library"
11
    topics = ("freeglut", "opengl", "gl", "glut", "utility", "toolkit", "graphics")
12
    url = "https://github.com/conan-io/conan-center-index"
13
    homepage = "http://freeglut.sourceforge.net"
14
    license = "X11"
15
16
    settings = "os", "arch", "compiler", "build_type"
17
    options = {
18
        "shared": [True, False],
19
        "fPIC": [True, False],
20
        "gles": [True, False],
21
        "print_errors_at_runtime": [True, False],
22
        "print_warnings_at_runtime": [True, False],
23
        "replace_glut": [True, False],
24
    }
25
    default_options = {
26
        "shared": False,
27
        "fPIC": True,
28
        "gles": False,
29
        "print_errors_at_runtime": True,
30
        "print_warnings_at_runtime": True,
31
        "replace_glut": True,
32
    }
33
34
    generators = "cmake"
35
    _cmake = None
36
37
    @property
38
    def _source_subfolder(self):
39
        return "source_subfolder"
40
41
    @property
42
    def _build_subfolder(self):
43
        return "build_subfolder"
44
45
    def export_sources(self):
46
        self.copy("CMakeLists.txt")
47
        for patch in self.conan_data.get("patches", {}).get(self.version, []):
48
            self.copy(patch["patch_file"])
49
50
    def config_options(self):
51
        if self.settings.os == "Windows":
52
            del self.options.fPIC
53
54
    def configure(self):
55
        if self.options.shared:
56
            del self.options.fPIC
57
        del self.settings.compiler.libcxx
58
        del self.settings.compiler.cppstd
59
60
    def requirements(self):
61
        self.requires("opengl/system")
62
        self.requires("glu/system")
63
        if self.settings.os == "Linux":
64
            self.requires("xorg/system")
65
66
    def validate(self):
67
        if self.settings.os == "Macos":
68
            # see https://github.com/dcnieho/FreeGLUT/issues/27
69
            # and https://sourceforge.net/p/freeglut/bugs/218/
70
            # also, it seems to require `brew cask install xquartz`
71
            raise ConanInvalidConfiguration("%s does not support macos" % self.name)
72
        if (self.settings.compiler == "gcc" and self.settings.compiler.version >= tools.Version("10.0")) or \
73
            (self.settings.compiler == "clang" and self.settings.compiler.version >= tools.Version("11.0")):
74
            # see https://github.com/dcnieho/FreeGLUT/issues/86
75
            raise ConanInvalidConfiguration("%s does not support gcc >= 10 and clang >= 11" % self.name)
76
77
    def source(self):
78
        tools.get(**self.conan_data["sources"][self.version],
79
                  strip_root=True, destination=self._source_subfolder)
80
81
    def _configure_cmake(self):
82
        if self._cmake:
83
            return self._cmake
84
85
        # See https://github.com/dcnieho/FreeGLUT/blob/44cf4b5b85cf6037349c1c8740b2531d7278207d/README.cmake
86
        self._cmake = CMake(self, set_cmake_flags=True)
87
88
        self._cmake.definitions["FREEGLUT_BUILD_DEMOS"] = False
89
        self._cmake.definitions["FREEGLUT_BUILD_STATIC_LIBS"] = not self.options.shared
90
        self._cmake.definitions["FREEGLUT_BUILD_SHARED_LIBS"] = self.options.shared
91
        self._cmake.definitions["FREEGLUT_GLES"] = self.options.gles
92
        self._cmake.definitions["FREEGLUT_PRINT_ERRORS"] = self.options.print_errors_at_runtime
93
        self._cmake.definitions["FREEGLUT_PRINT_WARNINGS"] = self.options.print_warnings_at_runtime
94
        self._cmake.definitions["FREEGLUT_INSTALL_PDB"] = False
95
        self._cmake.definitions["INSTALL_PDB"] = False
96
        self._cmake.definitions["FREEGLUT_REPLACE_GLUT"] = self.options.replace_glut
97
        # cmake.definitions["FREEGLUT_WAYLAND"] = "ON" if self.options.wayland else "OFF" # nightly version only as of now
98
99
        self._cmake.configure(build_folder=self._build_subfolder)
100
        return self._cmake
101
102
    def build(self):
103
        cmake = self._configure_cmake()
104
        cmake.build()
105
106
    def package(self):
107
        self.copy(pattern="COPYING", dst="licenses", src=self._source_subfolder)
108
        cmake = self._configure_cmake()
109
        cmake.install()
110
        tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
111
        tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
112
113
    def package_info(self):
114
        config_target = "freeglut" if self.options.shared else "freeglut_static"
115
        pkg_config = "freeglut" if self.settings.os == "Windows" else "glut"
116
117
        self.cpp_info.set_property("cmake_find_mode", "both")
118
        self.cpp_info.set_property("cmake_module_file_name", "GLUT")
119
        self.cpp_info.set_property("cmake_module_target_name", "GLUT::GLUT")
120
        self.cpp_info.set_property("cmake_file_name", "FreeGLUT")
121
        self.cpp_info.set_property("cmake_target_name", "FreeGLUT::{}".format(config_target))
122
        self.cpp_info.set_property("pkg_config_name", pkg_config)
123
124
        # TODO: back to global scope in conan v2 once cmake_find_package_* generators removed
125
        self.cpp_info.components["freeglut_"].libs = tools.collect_libs(self)
126
        if self.settings.os == "Linux":
127
            self.cpp_info.components["freeglut_"].system_libs.extend(["pthread", "m", "dl", "rt"])
128
        elif self.settings.os == "Windows":
129
            if not self.options.shared:
130
                self.cpp_info.components["freeglut_"].defines.append("FREEGLUT_STATIC=1")
131
            self.cpp_info.components["freeglut_"].defines.append("FREEGLUT_LIB_PRAGMAS=0")
132
            self.cpp_info.components["freeglut_"].system_libs.extend(["glu32", "gdi32", "winmm", "user32"])
133
134
        # TODO: to remove in conan v2 once cmake_find_package_* & pkg_config generators removed
135
        self.cpp_info.names["cmake_find_package"] = "GLUT"
136
        self.cpp_info.names["cmake_find_package_multi"] = "FreeGLUT"
137
        self.cpp_info.names["pkg_config"] = pkg_config
138
        self.cpp_info.components["freeglut_"].names["cmake_find_package"] = "GLUT"
139
        self.cpp_info.components["freeglut_"].set_property("cmake_module_target_name", "GLUT::GLUT")
140
        self.cpp_info.components["freeglut_"].names["cmake_find_package_multi"] = config_target
141
        self.cpp_info.components["freeglut_"].set_property("cmake_target_name", "FreeGLUT::{}".format(config_target))
142
        self.cpp_info.components["freeglut_"].set_property("pkg_config_name", pkg_config)
143
        self.cpp_info.components["freeglut_"].requires.extend(["opengl::opengl", "glu::glu"])
144
        if self.settings.os == "Linux":
145
            self.cpp_info.components["freeglut_"].requires.append("xorg::xorg")
146
147