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 EAAssertConan(ConanFile): name = "eaassert" description = "EAAssert is a lightweight EA runtime assertion library." topics = ("eastl", "assert") license = "BSD-3-Clause" url = "https://github.com/conan-io/conan-center-index" homepage = "https://github.com/electronicarts/EAAssert" 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") # The upstream CMakeLists.txt expects a EASTL git submodule for CommonCppFlags and a bare # "EABase" target from the same submodule setup - neither of which exist when building from # the release archive via Conan. Point it at Conan's EABase instead, and add install rules # (upstream has none). # 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)", "") replace_in_file( self, cmakelists, "target_link_libraries(EAAssert EABase)", "find_package(EABase REQUIRED CONFIG)\n" "target_link_libraries(EAAssert EABase::EABase)\n" "\n" "include(GNUInstallDirs)\n" "install(TARGETS EAAssert\n" " RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}\n" " LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}\n" " ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})\n" "install(DIRECTORY include/EAAssert 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 = ["EAAssert"] self.cpp_info.set_property("cmake_file_name", "EAAssert") self.cpp_info.set_property("cmake_target_name", "EAAssert::EAAssert") # TODO: to remove in conan v2 once cmake_find_package_* generators removed self.cpp_info.filenames["cmake_find_package"] = "EAAssert" self.cpp_info.filenames["cmake_find_package_multi"] = "EAAssert" self.cpp_info.names["cmake_find_package"] = "EAAssert" self.cpp_info.names["cmake_find_package_multi"] = "EAAssert"