import os from conan import ConanFile from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout from conan.tools.files import copy, get, replace_in_file, rmdir required_conan_version = ">=1.52.0" class EAThreadConan(ConanFile): name = "eathread" description = "EAThread is a C++ library that provides a platform-independent interface for threading." topics = ("eastl", "threading") license = "BSD-3-Clause" url = "https://github.com/conan-io/conan-center-index" homepage = "https://github.com/electronicarts/EAThread" package_type = "library" settings = "os", "arch", "compiler", "build_type" options = { "shared": [True, False], "fPIC": [True, False], } default_options = { "shared": False, "fPIC": True, } def config_options(self): if self.settings.os == "Windows": del self.options.fPIC def configure(self): if self.options.shared: self.options.rm_safe("fPIC") def layout(self): cmake_layout(self, src_folder="src") def requirements(self): self.requires(f"eabase/01082025@{self.user}/{self.channel}", transitive_headers=True) def source(self): get(self, **self.conan_data["sources"][self.version], strip_root=True) def generate(self): tc = CMakeToolchain(self) tc.generate() CMakeDeps(self).generate() def _patch_sources(self): cmakelists = os.path.join(self.source_folder, "CMakeLists.txt") replace_in_file(self, cmakelists, "include(CommonCppFlags)", "") # The upstream CMakeLists.txt pulls EABase in via FetchContent from a pinned commit - # replace it with Conan's EABase, and add install rules (upstream has none). replace_in_file( self, cmakelists, "FetchContent_Declare(\n" " EABase\n" " GIT_REPOSITORY https://github.com/electronicarts/EABase.git\n" " GIT_TAG 123363eb82e132c0181ac53e43226d8ee76dea12\n" " GIT_SUBMODULES \"\" # This should be temporary until we update the cyclic submodule dependencies in EABase.\n" ")\n" "\n" "FetchContent_MakeAvailable(EABase)\n" "\n" "target_link_libraries(EAThread EABase)\n", "find_package(EABase REQUIRED CONFIG)\n" "target_link_libraries(EAThread EABase::EABase)\n" "\n" "include(GNUInstallDirs)\n" "install(TARGETS EAThread\n" " RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}\n" " LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}\n" " ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})\n" "install(DIRECTORY include/eathread DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})\n", ) def build(self): self._patch_sources() cmake = CMake(self) cmake.configure() cmake.build() def package(self): copy( self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"), ) cmake = CMake(self) cmake.install() rmdir(self, os.path.join(self.package_folder, "doc")) def package_info(self): self.cpp_info.libs = ["EAThread"] if self.settings.os in ["Linux", "FreeBSD"]: self.cpp_info.system_libs.append("pthread") self.cpp_info.set_property("cmake_file_name", "EAThread") self.cpp_info.set_property("cmake_target_name", "EAThread::EAThread") # TODO: to remove in conan v2 once cmake_find_package_* generators removed self.cpp_info.filenames["cmake_find_package"] = "EAThread" self.cpp_info.filenames["cmake_find_package_multi"] = "EAThread" self.cpp_info.names["cmake_find_package"] = "EAThread" self.cpp_info.names["cmake_find_package_multi"] = "EAThread"