diff --git a/recipes/tesseract/all/CMakeLists.txt b/recipes/tesseract/all/CMakeLists.txt index 7025b41a71fae..c986d294c7547 100644 --- a/recipes/tesseract/all/CMakeLists.txt +++ b/recipes/tesseract/all/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.8) +cmake_minimum_required(VERSION 3.1) project(cmake_wrapper) include(conanbuildinfo.cmake) diff --git a/recipes/tesseract/all/conandata.yml b/recipes/tesseract/all/conandata.yml index d7407873bb615..12bbe5a0ea990 100644 --- a/recipes/tesseract/all/conandata.yml +++ b/recipes/tesseract/all/conandata.yml @@ -2,3 +2,9 @@ sources: "4.1.1": url: "https://github.com/tesseract-ocr/tesseract/archive/4.1.1.tar.gz" sha256: "2a66ff0d8595bff8f04032165e6c936389b1e5727c3ce5a27b3e059d218db1cb" +patches: + "4.1.1": + - patch_file: "patches/0001-Remove-config.patch" + base_path: "source_subfolder" + - patch_file: "patches/0002-Link-with-targets.patch" + base_path: "source_subfolder" diff --git a/recipes/tesseract/all/conanfile.py b/recipes/tesseract/all/conanfile.py index de364c67b64f9..63fbd097be2b6 100644 --- a/recipes/tesseract/all/conanfile.py +++ b/recipes/tesseract/all/conanfile.py @@ -1,5 +1,6 @@ import os from conans import ConanFile, CMake, tools +from conans.tools import Version from conans.errors import ConanInvalidConfiguration @@ -10,18 +11,33 @@ class TesseractConan(ConanFile): topics = ("conan", "ocr", "image", "multimedia", "graphics") license = "Apache-2.0" homepage = "https://github.com/tesseract-ocr/tesseract" - exports_sources = ["CMakeLists.txt"] + exports_sources = ["CMakeLists.txt", "patches/*"] generators = "cmake", "cmake_find_package" settings = "os", "arch", "compiler", "build_type" options = {"shared": [True, False], "fPIC": [True, False], + "with_auto_optimize": [True, False], + "with_march_native": [True, False], "with_training": [True, False]} - default_options = {'shared': False, 'fPIC': True, 'with_training': False} - _source_subfolder = "source_subfolder" - _build_subfolder = "build_subfolder" + default_options = {"shared": False, + "fPIC": True, + "with_auto_optimize": False, + "with_march_native": False, + "with_training": False} + _cmake = None - requires = "leptonica/1.79.0" + @property + def _source_subfolder(self): + return "source_subfolder" + + @property + def _build_subfolder(self): + return "build_subfolder" + + def requirements(self): + self.requires("leptonica/1.80.0") + self.requires("libarchive/3.5.1") def source(self): tools.get(**self.conan_data["sources"][self.version]) @@ -31,50 +47,57 @@ def source(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 if self.options.with_training: # do not enforce failure and allow user to build with system cairo, pango, fontconfig self.output.warn("*** Build with training is not yet supported, continue on your own") - def configure(self): - # Exclude old compilers not supported by tesseract - compiler_version = tools.Version(self.settings.compiler.version) - if (self.settings.compiler == "gcc" and compiler_version < "5") or \ - (self.settings.compiler == "clang" and compiler_version < "5"): - raise ConanInvalidConfiguration("tesseract/{} requires Clang >= 5".format(self.version)) + # Check compiler version + compiler = str(self.settings.compiler) + compiler_version = Version(self.settings.compiler.version.value) + + minimal_version = { + "Visual Studio": "14", + "gcc": "5", + "clang": "5", + "apple-clang": "6" + } + if compiler not in minimal_version: + self.output.warn( + "%s recipe lacks information about the %s compiler standard version support" % (self.name, compiler)) + elif compiler_version < minimal_version[compiler]: + raise ConanInvalidConfiguration("{} requires a {} version >= {}".format(self.name, compiler, compiler_version)) def _configure_cmake(self): if self._cmake: return self._cmake cmake = self._cmake = CMake(self) - cmake.definitions['BUILD_TRAINING_TOOLS'] = self.options.with_training + cmake.definitions["BUILD_TRAINING_TOOLS"] = self.options.with_training cmake.definitions["STATIC"] = not self.options.shared # Use CMake-based package build and dependency detection, not the pkg-config, cppan or SW - cmake.definitions['CPPAN_BUILD'] = False - cmake.definitions['SW_BUILD'] = False + cmake.definitions["CPPAN_BUILD"] = False + cmake.definitions["SW_BUILD"] = False - # avoid accidentally picking up system libarchive - cmake.definitions['CMAKE_DISABLE_FIND_PACKAGE_LIBARCHIVE'] = True + cmake.definitions["AUTO_OPTIMIZE"] = self.options.with_auto_optimize # Set Leptonica_DIR to ensure that find_package will be called in original CMake file - cmake.definitions['Leptonica_DIR'] = self.deps_cpp_info['leptonica'].rootpath + cmake.definitions["Leptonica_DIR"] = self.deps_cpp_info["leptonica"].rootpath cmake.configure(build_folder=self._build_subfolder) return cmake def _patch_sources(self): - # Use generated cmake module files - tools.replace_in_file( - os.path.join(self._source_subfolder, "CMakeLists.txt"), - "find_package(Leptonica ${MINIMUM_LEPTONICA_VERSION} REQUIRED CONFIG)", - "find_package(Leptonica ${MINIMUM_LEPTONICA_VERSION} REQUIRED)") - # Variable Leptonica_LIBRARIES does not know about its dependencies which are handled only - # by exported cmake/pc files which are not used by Conan. - # Therefore link with exported target from the autogenerated CMake file by the cmake_find_package - # that contains information about all dependencies - tools.replace_in_file( - os.path.join(self._source_subfolder, "CMakeLists.txt"), - "${Leptonica_LIBRARIES}", - "Leptonica::Leptonica") + for patch in self.conan_data.get("patches", {}).get(self.version, []): + tools.patch(**patch) + + if not self.options.with_march_native: + tools.replace_in_file( + os.path.join(self._source_subfolder, "CMakeLists.txt"), + "if(COMPILER_SUPPORTS_MARCH_NATIVE)", + "if(False)") def build(self): self._patch_sources() @@ -92,13 +115,21 @@ def package(self): tools.rmdir(os.path.join(self.package_folder, 'lib', 'pkgconfig')) # remove cmake tools.rmdir(os.path.join(self.package_folder, 'cmake')) + # required for 5.0 + tools.rmdir(os.path.join(self.package_folder, 'lib', 'cmake')) def package_info(self): - self.cpp_info.libs = tools.collect_libs(self) - if self.settings.os == "Linux": - self.cpp_info.system_libs = ["pthread"] - elif self.settings.compiler == "Visual Studio": - if not self.options.shared: - self.cpp_info.system_libs = ["ws2_32"] self.cpp_info.names["cmake_find_package"] = "Tesseract" self.cpp_info.names["cmake_find_package_multi"] = "Tesseract" + + self.cpp_info.components["libtesseract"].libs = tools.collect_libs(self) + self.cpp_info.components["libtesseract"].requires = ["leptonica::leptonica", "libarchive::libarchive" ] + + self.cpp_info.components["libtesseract"].names["cmake_find_package"] = "libtesseract" + self.cpp_info.components["libtesseract"].names["cmake_find_package_multi"] = "libtesseract" + self.cpp_info.components["libtesseract"].names["pkg_config"] = "libtesseract" + + if self.settings.os == "Linux": + self.cpp_info.components["libtesseract"].system_libs = ["pthread"] + elif self.settings.compiler == "Visual Studio": + self.cpp_info.components["libtesseract"].system_libs = ["ws2_32"] diff --git a/recipes/tesseract/all/patches/0001-Remove-config.patch b/recipes/tesseract/all/patches/0001-Remove-config.patch new file mode 100644 index 0000000000000..07bbc0dbbf5fd --- /dev/null +++ b/recipes/tesseract/all/patches/0001-Remove-config.patch @@ -0,0 +1,13 @@ +Use generated cmake module files +diff --git a/CMakeLists.txt b/CMakeLists.txt +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -221,7 +221,7 @@ else() + pkg_check_modules(Leptonica REQUIRED lept>=${MINIMUM_LEPTONICA_VERSION}) + link_directories(${Leptonica_LIBRARY_DIRS}) + else() +- find_package(Leptonica ${MINIMUM_LEPTONICA_VERSION} REQUIRED CONFIG) ++ find_package(Leptonica ${MINIMUM_LEPTONICA_VERSION} REQUIRED) + endif() + if (NOT Leptonica_FOUND) + message(FATAL_ERROR "Cannot find required library Leptonica. Quitting!") diff --git a/recipes/tesseract/all/patches/0002-Link-with-targets.patch b/recipes/tesseract/all/patches/0002-Link-with-targets.patch new file mode 100644 index 0000000000000..d266163cf6b57 --- /dev/null +++ b/recipes/tesseract/all/patches/0002-Link-with-targets.patch @@ -0,0 +1,18 @@ +Variable Leptonica_LIBRARIES does not know about its dependencies which are handled only +by exported cmake/pc files which are not used by Conan. +Therefore link with exported target from the autogenerated CMake file by the cmake_find_package +that contains information about all dependencies +diff --git a/CMakeLists.txt b/CMakeLists.txt +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -491,8 +491,8 @@ elseif (SW_BUILD) + export(TARGETS libtesseract APPEND FILE ${CMAKE_CURRENT_BINARY_DIR}/TesseractTargets.cmake) + else() + target_link_libraries (libtesseract PUBLIC +- ${Leptonica_LIBRARIES} +- ${LibArchive_LIBRARIES} ++ Leptonica::Leptonica ++ LibArchive::LibArchive + ) + export(TARGETS libtesseract FILE ${CMAKE_CURRENT_BINARY_DIR}/TesseractTargets.cmake) + endif() diff --git a/recipes/tesseract/all/test_package/CMakeLists.txt b/recipes/tesseract/all/test_package/CMakeLists.txt index 33ae887aa6aea..be3b3ec31eb9a 100644 --- a/recipes/tesseract/all/test_package/CMakeLists.txt +++ b/recipes/tesseract/all/test_package/CMakeLists.txt @@ -4,6 +4,8 @@ project(test_package) include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) conan_basic_setup() +find_package(Tesseract REQUIRED CONFIG) + add_executable(${PROJECT_NAME} test_package.cpp) -target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS}) +target_link_libraries(${PROJECT_NAME} Tesseract::libtesseract) set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11) diff --git a/recipes/tesseract/all/test_package/conanfile.py b/recipes/tesseract/all/test_package/conanfile.py index bd7165a553cf4..7e2dfe859bb27 100644 --- a/recipes/tesseract/all/test_package/conanfile.py +++ b/recipes/tesseract/all/test_package/conanfile.py @@ -4,7 +4,7 @@ class TestPackageConan(ConanFile): settings = "os", "compiler", "build_type", "arch" - generators = "cmake" + generators = "cmake", "cmake_find_package_multi" def build(self): cmake = CMake(self)