conanfile.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. from dependencies.conanfile import VCMI
  2. from conan.tools.cmake import CMakeToolchain
  3. from conan.tools.files import save
  4. from glob import glob
  5. import os
  6. class VCMIApp(VCMI):
  7. generators = "CMakeDeps"
  8. def _pathForCmake(self, path: str) -> str:
  9. # CMake doesn't like \ in strings
  10. return path.replace(os.path.sep, os.path.altsep) if os.path.altsep else path
  11. def _generateRuntimeLibsFile(self) -> str:
  12. # create file with list of libs to copy to the package for distribution
  13. runtimeLibsFile = self._pathForCmake(os.path.join(self.build_folder, "_runtime_libs.txt"))
  14. runtimeLibExtension = {
  15. "Android": "so",
  16. "iOS": "dylib",
  17. "Macos": "dylib",
  18. "Windows": "dll",
  19. }.get(str(self.settings.os))
  20. runtimeLibs = []
  21. for _, dep in self.dependencies.host.items():
  22. # Qt libs are copied using *deployqt
  23. if dep.ref.name == "qt":
  24. continue
  25. runtimeLibDir = ''
  26. if self.settings.os == "Windows":
  27. if len(dep.cpp_info.bindirs) > 0:
  28. runtimeLibDir = dep.cpp_info.bindir
  29. elif len(dep.cpp_info.libdirs) > 0:
  30. runtimeLibDir = dep.cpp_info.libdir
  31. if len(runtimeLibDir) > 0:
  32. runtimeLibs += map(self._pathForCmake, glob(os.path.join(runtimeLibDir, f"*.{runtimeLibExtension}")))
  33. save(self, runtimeLibsFile, "\n".join(runtimeLibs))
  34. return runtimeLibsFile
  35. def generate(self):
  36. tc = CMakeToolchain(self)
  37. tc.variables["USING_CONAN"] = True
  38. tc.variables["CONAN_RUNTIME_LIBS_FILE"] = self._generateRuntimeLibsFile()
  39. if self.settings.os == "Android":
  40. tc.variables["CMAKE_ANDROID_API"] = str(self.settings.os.api_level)
  41. tc.variables["SDL_JAVA_SRC_DIR"] = os.path.join(self.dependencies.host["sdl"].package_folder, "share", "java", "SDL2")
  42. elif self.settings.os == "Windows":
  43. tc.variables["CONAN_RUNENV_SCRIPT"] = self._pathForCmake(os.path.join(self.build_folder, "conanrun"))
  44. tc.generate()