You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

144 lines
6.6KB

  1. import os
  2. from conans import ConanFile, CMake
  3. from conans.tools import os_info, SystemPackageTool, ConanException
  4. from conans import tools, VisualStudioBuildEnvironment
  5. from conans.tools import build_sln_command, vcvars_command, replace_in_file, download, unzip
  6. class GlewConan(ConanFile):
  7. name = "glew"
  8. version = "master"
  9. source_directory = "%s-%s" % (name, version) if version != "master" else "."
  10. description = "The GLEW library"
  11. generators = "cmake", "txt"
  12. settings = "os", "arch", "build_type", "compiler"
  13. options = {"shared": [True, False]}
  14. default_options = "shared=False"
  15. url="http://github.com/nigels-com/glew"
  16. license="https://github.com/nigels-com/glew#copyright-and-licensing"
  17. if version == "master":
  18. if os.path.isfile("Makefile"):
  19. exports_sources = "*"
  20. else:
  21. exports_sources = os.sep.join(["..", "..", "*"])
  22. else:
  23. exports = "FindGLEW.cmake"
  24. def system_requirements(self):
  25. if os_info.is_linux:
  26. if os_info.with_apt:
  27. installer = SystemPackageTool()
  28. if self.version == "master":
  29. installer.install("build-essential")
  30. installer.install("libxmu-dev")
  31. installer.install("libxi-dev")
  32. installer.install("libgl-dev")
  33. installer.install("libosmesa-dev")
  34. installer.install("libglu1-mesa-dev")
  35. elif os_info.with_yum:
  36. installer = SystemPackageTool()
  37. if self.version == "master":
  38. installer.install("libXmu-devel")
  39. installer.install("libXi-devel")
  40. installer.install("libGL-devel")
  41. installer.install("mesa-libGLU-devel")
  42. else:
  43. self.output.warn("Could not determine Linux package manager, skipping system requirements installation.")
  44. def configure(self):
  45. del self.settings.compiler.libcxx
  46. def source(self):
  47. if self.version != "master":
  48. zip_name = "%s.tgz" % self.source_directory
  49. download("https://sourceforge.net/projects/glew/files/glew/%s/%s/download" % (self.version, zip_name), zip_name)
  50. unzip(zip_name)
  51. os.unlink(zip_name)
  52. def build(self):
  53. if self.settings.os == "Windows" and self.version == "master":
  54. raise ConanException("Trunk builds are not supported on Windows (cannot build directly from master git repository).")
  55. if self.settings.compiler == "Visual Studio":
  56. env = VisualStudioBuildEnvironment(self)
  57. with tools.environment_append(env.vars):
  58. version = min(12, int(self.settings.compiler.version.value))
  59. version = 10 if version == 11 else version
  60. cd_build = "cd %s\\%s\\build\\vc%s" % (self.conanfile_directory, self.source_directory, version)
  61. build_command = build_sln_command(self.settings, "glew.sln")
  62. vcvars = vcvars_command(self.settings)
  63. self.run("%s && %s && %s" % (vcvars, cd_build, build_command.replace("x86", "Win32")))
  64. else:
  65. if self.settings.os == "Windows":
  66. replace_in_file("%s/build/cmake/CMakeLists.txt" % self.source_directory, \
  67. "if(WIN32 AND (NOT MSVC_VERSION LESS 1600)", \
  68. "if(WIN32 AND MSVC AND (NOT MSVC_VERSION LESS 1600)")
  69. if self.version == "master":
  70. self.run("make extensions")
  71. cmake = CMake(self)
  72. cmake.configure(source_dir="%s/build/cmake" % self.source_directory, defs={"BUILD_UTILS": "OFF"})
  73. cmake.build()
  74. def package(self):
  75. find_glew_dir = "%s/build/conan" % self.conanfile_directory if self.version == "master" else "."
  76. self.copy("FindGLEW.cmake", ".", find_glew_dir, keep_path=False)
  77. self.copy("include/*", ".", "%s" % self.source_directory, keep_path=True)
  78. self.copy("%s/license*" % self.source_directory, dst="licenses", ignore_case=True, keep_path=False)
  79. if self.settings.os == "Windows":
  80. if self.settings.compiler == "Visual Studio":
  81. self.copy(pattern="*.pdb", dst="bin", keep_path=False)
  82. if self.options.shared:
  83. self.copy(pattern="*32.lib", dst="lib", keep_path=False)
  84. self.copy(pattern="*32d.lib", dst="lib", keep_path=False)
  85. self.copy(pattern="*.dll", dst="bin", keep_path=False)
  86. else:
  87. self.copy(pattern="*32s.lib", dst="lib", keep_path=False)
  88. self.copy(pattern="*32sd.lib", dst="lib", keep_path=False)
  89. else:
  90. if self.options.shared:
  91. self.copy(pattern="*32.dll.a", dst="lib", keep_path=False)
  92. self.copy(pattern="*32d.dll.a", dst="lib", keep_path=False)
  93. self.copy(pattern="*.dll", dst="bin", keep_path=False)
  94. else:
  95. self.copy(pattern="*32.a", dst="lib", keep_path=False)
  96. self.copy(pattern="*32d.a", dst="lib", keep_path=False)
  97. elif self.settings.os == "Macos":
  98. if self.options.shared:
  99. self.copy(pattern="*.dylib", dst="lib", keep_path=False)
  100. else:
  101. self.copy(pattern="*.a", dst="lib", keep_path=False)
  102. else:
  103. if self.options.shared:
  104. self.copy(pattern="*.so", dst="lib", keep_path=False)
  105. else:
  106. self.copy(pattern="*.a", dst="lib", keep_path=False)
  107. def package_info(self):
  108. if self.settings.os == "Windows":
  109. self.cpp_info.libs = ['glew32']
  110. if not self.options.shared:
  111. self.cpp_info.defines.append("GLEW_STATIC")
  112. if self.settings.compiler == "Visual Studio":
  113. if not self.options.shared:
  114. self.cpp_info.libs[0] += "s"
  115. self.cpp_info.libs.append("OpenGL32.lib")
  116. if self.settings.compiler.runtime != "MT":
  117. self.cpp_info.exelinkflags.append('-NODEFAULTLIB:LIBCMTD')
  118. self.cpp_info.exelinkflags.append('-NODEFAULTLIB:LIBCMT')
  119. else:
  120. self.cpp_info.libs.append("opengl32")
  121. else:
  122. self.cpp_info.libs = ['GLEW']
  123. if self.settings.os == "Macos":
  124. self.cpp_info.exelinkflags.append("-framework OpenGL")
  125. elif not self.options.shared:
  126. self.cpp_info.libs.append("GL")
  127. if self.settings.build_type == "Debug":
  128. self.cpp_info.libs[0] += "d"