Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eastl: add Conan v2 support #17414

Merged
merged 11 commits into from
Jul 2, 2023
9 changes: 0 additions & 9 deletions recipes/eastl/all/CMakeLists.txt

This file was deleted.

10 changes: 0 additions & 10 deletions recipes/eastl/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,18 @@ sources:
patches:
"3.18.00":
- patch_file: "patches/3.17.03-0001-cmake-shared-use-conan-add-install.patch"
base_path: "source_subfolder"
- patch_file: "patches/3.17.03-0002-revert-c++14-constexpr.patch"
base_path: "source_subfolder"
"3.17.06":
- patch_file: "patches/3.17.03-0001-cmake-shared-use-conan-add-install.patch"
base_path: "source_subfolder"
- patch_file: "patches/3.17.03-0002-revert-c++14-constexpr.patch"
base_path: "source_subfolder"
"3.17.03":
- patch_file: "patches/3.17.03-0001-cmake-shared-use-conan-add-install.patch"
base_path: "source_subfolder"
- patch_file: "patches/3.17.03-0002-revert-c++14-constexpr.patch"
base_path: "source_subfolder"
"3.16.07":
- patch_file: "patches/3.15.00-0001-cmake-shared-use-conan-add-install.patch"
base_path: "source_subfolder"
"3.16.05":
- patch_file: "patches/3.15.00-0001-cmake-shared-use-conan-add-install.patch"
base_path: "source_subfolder"
"3.16.01":
- patch_file: "patches/3.15.00-0001-cmake-shared-use-conan-add-install.patch"
base_path: "source_subfolder"
"3.15.00":
- patch_file: "patches/3.15.00-0001-cmake-shared-use-conan-add-install.patch"
base_path: "source_subfolder"
138 changes: 84 additions & 54 deletions recipes/eastl/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
import os

required_conan_version = ">=1.33.0"
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain
from conan.tools.files import (
apply_conandata_patches,
copy,
export_conandata_patches,
get,
replace_in_file,
)
from conan.tools.layout import basic_layout
from conan.tools.scm import Version

required_conan_version = ">=1.52.0"


class EastlConan(ConanFile):
name = "eastl"
description = "EASTL stands for Electronic Arts Standard Template Library. " \
"It is an extensive and robust implementation that has an " \
"emphasis on high performance."
description = (
"EASTL stands for Electronic Arts Standard Template Library. "
"It is an extensive and robust implementation that has an "
"emphasis on high performance."
)
topics = ("eastl", "stl", "high-performance")
license = "BSD-3-Clause"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/electronicarts/EASTL"

package_type = "header-library"
valgur marked this conversation as resolved.
Show resolved Hide resolved
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
Expand All @@ -25,92 +40,107 @@ class EastlConan(ConanFile):
"fPIC": True,
}

generators = "cmake"
_cmake = None

@property
def _source_subfolder(self):
return "source_subfolder"

@property
def _build_subfolder(self):
return "build_subfolder"

@property
def _minimum_cpp_standard(self):
def _min_cppstd(self):
return 14

@property
def _minimum_compilers_version(self):
def _compilers_minimum_version(self):
return {
"Visual Studio": "14",
"gcc": "5",
"clang": "3.2",
"apple-clang": "4.3",
"gcc": "6",
valgur marked this conversation as resolved.
Show resolved Hide resolved
"clang": "6",
"apple-clang": "6",
}

def export_sources(self):
self.copy("CMakeLists.txt")
for patch in self.conan_data.get("patches", {}).get(self.version, []):
self.copy(patch["patch_file"])
export_conandata_patches(self)

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
if self.options.shared:
del self.options.fPIC
self.options.rm_safe("fPIC")

def layout(self):
basic_layout(self, src_folder="src")
valgur marked this conversation as resolved.
Show resolved Hide resolved

def requirements(self):
self.requires("eabase/2.09.06")
self.requires("eabase/2.09.12")

def package_id(self):
self.info.clear()
valgur marked this conversation as resolved.
Show resolved Hide resolved

def validate(self):
if self.settings.compiler.get_safe("cppstd"):
tools.check_min_cppstd(self, self._minimum_cpp_standard)

mininum_compiler_version = self._minimum_compilers_version.get(str(self.settings.compiler))
if mininum_compiler_version and tools.Version(self.settings.compiler.version) < mininum_compiler_version:
raise ConanInvalidConfiguration("Compiler is too old for c++ {}".format(self._minimum_cpp_standard))
check_min_cppstd(self, self._min_cppstd)
minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False)
if minimum_version and Version(self.settings.compiler.version) < minimum_version:
raise ConanInvalidConfiguration(
f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support."
)

def source(self):
tools.get(**self.conan_data["sources"][self.version],
destination=self._source_subfolder, strip_root=True)

def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.definitions["EASTL_BUILD_BENCHMARK"] = False
self._cmake.definitions["EASTL_BUILD_TESTS"] = False
self._cmake.configure(build_folder=self._build_subfolder)
return self._cmake
get(
self,
**self.conan_data["sources"][self.version],
destination=self.source_folder,
strip_root=True,
)

def generate(self):
tc = CMakeToolchain(self)
tc.variables["EASTL_BUILD_BENCHMARK"] = False
tc.variables["EASTL_BUILD_TESTS"] = False
valgur marked this conversation as resolved.
Show resolved Hide resolved
tc.generate()
CMakeDeps(self).generate()

def _patch_sources(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
tools.replace_path_in_file(os.path.join(self._source_subfolder, "CMakeLists.txt"),
"include(CommonCppFlags)",
"")
apply_conandata_patches(self)
replace_in_file(
self,
os.path.join(self.source_folder, "CMakeLists.txt"),
"include(CommonCppFlags)",
"",
)

def build(self):
self._patch_sources()
cmake = self._configure_cmake()
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
self.copy("LICENSE", src=self._source_subfolder, dst="licenses")
self.copy("3RDPARTYLICENSES.TXT", src=self._source_subfolder, dst="licenses")
cmake = self._configure_cmake()
copy(
self,
"LICENSE",
src=self.source_folder,
dst=os.path.join(self.package_folder, "licenses"),
)
copy(
self,
"3RDPARTYLICENSES.TXT",
src=self.source_folder,
dst=os.path.join(self.package_folder, "licenses"),
)
cmake = CMake(self)
cmake.install()

def package_info(self):
self.cpp_info.libs = ["EASTL"]
self.cpp_info.bindirs = []
self.cpp_info.libdirs = []
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs.append("pthread")
if self.options.shared:
self.cpp_info.defines.append("EA_DLL")

# Do not use these names in set_property, it was a mistake, eastl doesn't export its target
self.cpp_info.set_property("cmake_file_name", "EASTL")
self.cpp_info.set_property("cmake_target_name", "EASTL::EASTL")

# TODO: to remove in conan v2 once cmake_find_package_* generators removed
self.cpp_info.filenames["cmake_find_package"] = "EASTL"
self.cpp_info.filenames["cmake_find_package_multi"] = "EASTL"
self.cpp_info.names["cmake_find_package"] = "EASTL"
self.cpp_info.names["cmake_find_package_multi"] = "EASTL"
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -46,5 +46,18 @@ target_include_directories(EASTL PUBLIC include)
@@ -46,5 +46,19 @@ target_include_directories(EASTL PUBLIC include)
#-------------------------------------------------------------------------------------------
# Dependencies
#-------------------------------------------------------------------------------------------
-target_link_libraries(EASTL EABase)
+target_link_libraries(EASTL CONAN_PKG::eabase)
+find_package(EABase REQUIRED CONFIG)
+target_link_libraries(EASTL EABase::EABase)

+if(BUILD_SHARED_LIBS)
+ target_compile_definitions(EASTL PUBLIC EASTL_DLL)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -47,8 +47,21 @@
@@ -47,8 +47,22 @@
# Dependencies
#-------------------------------------------------------------------------------------------
if (NOT TARGET EABase)
Expand All @@ -9,7 +9,8 @@
endif()

-target_link_libraries(EASTL EABase)
+target_link_libraries(EASTL CONAN_PKG::eabase)
+find_package(EABase REQUIRED CONFIG)
+target_link_libraries(EASTL EABase::EABase)

+if(BUILD_SHARED_LIBS)
+ target_compile_definitions(EASTL PUBLIC EASTL_DLL)
Expand Down
11 changes: 5 additions & 6 deletions recipes/eastl/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)
cmake_minimum_required(VERSION 3.15)
project(test_package CXX)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
find_package(EASTL REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 14)
target_link_libraries(${PROJECT_NAME} EASTL::EASTL)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14)
19 changes: 14 additions & 5 deletions recipes/eastl/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
from conans import ConanFile, CMake, tools
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
test_type = "explicit"

def requirements(self):
self.requires(self.tested_reference_str)

def layout(self):
cmake_layout(self)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindir, "test_package")
self.run(bin_path, env="conanrun")