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 EAStdCConan(ConanFile): name = "eastdc" description = "EAStdC (EA Standard C) is a package that implements much of the functionality of standard C " \ "and C++ libraries, but with an emphasis on speed and efficiency and, secondarily, safety." topics = ("eastl", "stdc") license = "BSD-3-Clause" url = "https://github.com/conan-io/conan-center-index" homepage = "https://github.com/electronicarts/EAStdC" 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) self.requires(f"eaassert/25082026@{self.user}/{self.channel}", transitive_headers=True) self.requires(f"eathread/25082026@{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") # CMake >= 4 dropped support for the compatibility policies VERSION 3.1 requires. replace_in_file(self, cmakelists, "cmake_minimum_required(VERSION 3.1)", "cmake_minimum_required(VERSION 3.5)") replace_in_file(self, cmakelists, "include(CommonCppFlags)", "") # The upstream CMakeLists.txt expects bare "EABase"/"EAAssert"/"EAThread" targets from a git # submodule setup that doesn't exist when building from the release archive via Conan. Point # it at Conan's packages instead, and add install rules (upstream has none). replace_in_file( self, cmakelists, "target_link_libraries(EAStdC EABase)\n" "target_link_libraries(EAStdC EAAssert)\n" "target_link_libraries(EAStdC EAThread)\n", "find_package(EABase REQUIRED CONFIG)\n" "find_package(EAAssert REQUIRED CONFIG)\n" "find_package(EAThread REQUIRED CONFIG)\n" "target_link_libraries(EAStdC EABase::EABase EAAssert::EAAssert EAThread::EAThread)\n" "\n" "include(GNUInstallDirs)\n" "install(TARGETS EAStdC\n" " RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}\n" " LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}\n" " ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})\n" "install(DIRECTORY include/EAStdC 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 = ["EAStdC"] self.cpp_info.set_property("cmake_file_name", "EAStdC") self.cpp_info.set_property("cmake_target_name", "EAStdC::EAStdC") # TODO: to remove in conan v2 once cmake_find_package_* generators removed self.cpp_info.filenames["cmake_find_package"] = "EAStdC" self.cpp_info.filenames["cmake_find_package_multi"] = "EAStdC" self.cpp_info.names["cmake_find_package"] = "EAStdC" self.cpp_info.names["cmake_find_package_multi"] = "EAStdC"