def package(self): with tools.chdir(self._filename): self.output.info(F"Patching and installing lcov") tools.replace_path_in_file("Makefile", "/usr/local", self.package_folder) env_build = AutoToolsBuildEnvironment(self) env_build.make(target="install")
def build(self): for patch in self.conan_data.get("patches", {}).get(self.version, []): tools.patch(**patch) if microsoft.is_msvc(self) and self.settings.arch == "x86": tools.replace_path_in_file(os.path.join(self._source_subfolder, "CMakeLists.txt"), "mimalloc-redirect.lib", "mimalloc-redirect32.lib") with tools.vcvars(self.settings) if microsoft.is_msvc(self) else tools.no_op(): cmake = self._configure_cmake() cmake.build()
def source(self): git = tools.Git(folder="11zip") git.clone("https://github.com/Sygmei/11Zip.git") if self.settings.os != "Windows": git = tools.Git(folder="11zip/include/tinydir") git.clone("https://github.com/cxong/tinydir.git") tools.replace_path_in_file("11zip/CMakeLists.txt", "target_link_libraries(elzip tinydir)", "add_subdirectory(include/tinydir)")
def content(self): ret = dict() prefix_pat = re.compile('^prefix=(.*)$') for dep_name in self.conanfile.deps_cpp_info.deps: print('dep_name={}'.format(dep_name)) rootpath = self.conanfile.deps_cpp_info[dep_name].rootpath print('rootpath={}'.format(rootpath)) pkgconfig_path = os.path.join(rootpath, 'lib', 'pkgconfig') dst_pkgconfig_dir = os.path.join(self.output_path, 'pkgconfig') os.makedirs(dst_pkgconfig_dir, exist_ok=True) pc_file_list = [] modified_list = [] prefix_set = set() for pc_file in glob.glob(os.path.join(pkgconfig_path, '*.pc')): print('pc_file={}'.format(pc_file)) if os.path.isfile(pc_file): pc_filename = os.path.basename(pc_file) pkg_name = os.path.splitext(pc_filename)[0] dst = os.path.join(dst_pkgconfig_dir, pc_filename) shutil.copy(pc_file, dst) prefix = None with open(pc_file) as _f: _lines = _f.readlines() for _line in _lines: _line = _line.strip() _match = prefix_pat.match(_line) if _match: prefix = _match.group(1) break if prefix: prefix_set.add(prefix) if os.path.exists(prefix): self.conanfile.output.info('{} exists, do not modify {}'.format(prefix, pc_file)) else: self.conanfile.output.warn('{} does not exist, replace it with {} in {}'.format(prefix, rootpath, pc_file)) # use replace path instead of replace prefix # to fix some legacy pc file which does not # use ${prefix} in other variable tools.replace_path_in_file( file_path=dst, search=prefix, replace=rootpath, strict=False ) modified_list.append(pc_filename) pc_file_list.append(pc_filename) data_dict = dict( all=pc_file_list, modified=modified_list, old_prefixs=list(prefix_set) ) ret['pclist-%s.json'%dep_name] = json.dumps(data_dict, indent=4, sort_keys=True) return ret
def _configure_cmake(self): if self._cmake: return self._cmake # KB-H016: do not install Find*.cmake tools.replace_path_in_file( os.path.join(self._source_subfolder, "CMakeLists.txt"), "install(FILES ${installFindModuleFiles} DESTINATION ${FIND_MODULES_INSTALL_DIR})", "") self._cmake = CMake(self) self._cmake.definitions["BUILD_HTML_DOCS"] = False self._cmake.definitions["BUILD_QTHELP_DOCS"] = False self._cmake.definitions["BUILD_MAN_DOCS"] = False self._cmake.definitions["SHARE_INSTALL_DIR"] = os.path.join( self.package_folder, "res") self._cmake.configure(source_folder=os.path.join( self.source_folder, self._source_subfolder)) return self._cmake
def build(self): pass cmake = self._configure_cmake() tools.replace_path_in_file("src/asl/CMakeLists.txt", "${CMAKE_CURRENT_BINARY_DIR}/arith.h", "${CMAKE_CURRENT_BINARY_DIR}/asl/include/arith.h") tools.replace_path_in_file("src/asl/CMakeLists.txt", "solvers/opcode.hd", "") tools.replace_path_in_file("src/asl/CMakeLists.txt", "solvers/r_opn.hd", "") cmake.build()
def _patch_sources(self): for patch in self.conan_data["patches"][self.version]: tools.patch(**patch) tools.replace_path_in_file( os.path.join(self._source_subfolder, "CMakeLists.txt"), "include(CommonCppFlags)", "")
def patch_config_paths(self): """ changes references to the absolute path of the installed package and its dependencies in exported cmake config files to the appropriate conan variable. This makes most (sensible) cmake config files portable. For example, if a package foo installs a file called "fooConfig.cmake" to be used by cmake's find_package method, normally this file will contain absolute paths to the installed package folder, for example it will contain a line such as: SET(Foo_INSTALL_DIR /home/developer/.conan/data/Foo/1.0.0/...) This will cause cmake find_package() method to fail when someone else installs the package via conan. This function will replace such mentions to SET(Foo_INSTALL_DIR ${CONAN_FOO_ROOT}) which is a variable that is set by conanbuildinfo.cmake, so that find_package() now correctly works on this conan package. For dependent packages, if a package foo installs a file called "fooConfig.cmake" to be used by cmake's find_package method and if it depends to a package bar, normally this file will contain absolute paths to the bar package folder, for example it will contain a line such as: SET_TARGET_PROPERTIES(foo PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "/home/developer/.conan/data/Bar/1.0.0/user/channel/id/include") This function will replace such mentions to SET_TARGET_PROPERTIES(foo PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${CONAN_BAR_ROOT}/include") If the install() method of the CMake object in the conan file is used, this function should be called _after_ that invocation. For example: def build(self): cmake = CMake(self) cmake.configure() cmake.build() cmake.install() cmake.patch_config_paths() """ if not self._conanfile.should_install: return if not self._conanfile.name: raise ConanException( "cmake.patch_config_paths() can't work without package name. " "Define name in your recipe") pf = self.definitions.get(cmake_install_prefix_var_name) replstr = "${CONAN_%s_ROOT}" % self._conanfile.name.upper() allwalk = chain(walk(self._conanfile.build_folder), walk(self._conanfile.package_folder)) for root, _, files in allwalk: for f in files: if f.endswith(".cmake"): path = os.path.join(root, f) tools.replace_path_in_file(path, pf, replstr, strict=False) # patch paths of dependent packages that are found in any cmake files of the # current package for dep in self._conanfile.deps_cpp_info.deps: from_str = self._conanfile.deps_cpp_info[dep].rootpath dep_str = "${CONAN_%s_ROOT}" % dep.upper() ret = tools.replace_path_in_file(path, from_str, dep_str, strict=False) if ret: self._conanfile.output.info( "Patched paths for %s: %s to %s" % (dep, from_str, dep_str))
def replace_path_in_files(pattern: str, *args, **kwargs): for file_path in glob.glob(pattern, recursive=True): print(file_path) tools.replace_path_in_file(file_path, *args, **kwargs)