-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Description
When some libraries like fontconfig or zlib generate CMakeLists.txt files, they add the 'module' prefix in find_package(). Some errors:
CMake Error at CMakeLists.txt:18 (find_package):
By not providing "Findmodule-ZLIB.cmake" in CMAKE_MODULE_PATH this project
has asked CMake to find a package configuration file provided by
"module-ZLIB", but CMake did not find one.
Could not find a package configuration file provided by "module-ZLIB" with
any of the following names:
module-ZLIBConfig.cmake
module-zlib-config.cmake
Add the installation prefix of "module-ZLIB" to CMAKE_PREFIX_PATH or set
"module-ZLIB_DIR" to a directory containing one of the above files. If
"module-ZLIB" provides a separate development package or SDK, be sure it
has been installed.
-- Configuring incomplete, errors occurred!
error config cmake failed
This is the content in toml file
[package]
name = "learning"
version = "0.1.0"
std = 20
[dependencies]
zlib = "1.3.1"
This is the content in CMakeList.txt when running "cppship run"
# Package finders
find_package(module-ZLIB REQUIRED)
When running "cppship cmake" to generate CMakeLists.txt, the problems also appears. If I delete the "module" prefix, it can be build and run well.
How to fix the bug?
This is the main.cpp example content.
#include <iostream>
#include <string>
#include <zlib.h>
// 简单封装一下,方便调用
std::string compress_string(const std::string& str)
{
z_stream zs{};
zs.zalloc = Z_NULL;
zs.zfree = Z_NULL;
zs.opaque = Z_NULL;
// 推荐用 ZLIB_DEFAULT_COMPRESSION,或者 1~9 自定义级别
if (deflateInit(&zs, Z_BEST_COMPRESSION) != Z_OK) {
throw std::runtime_error("deflateInit failed");
}
zs.next_in = (Bytef*)str.data();
zs.avail_in = (uInt)str.size();
int ret;
char outbuffer[32768];
std::string outstring;
do {
zs.next_out = (Bytef*)outbuffer;
zs.avail_out = sizeof(outbuffer);
ret = deflate(&zs, Z_FINISH);
if (outstring.size() < zs.total_out) {
outstring.append(outbuffer, zs.total_out - outstring.size());
}
} while (ret == Z_OK);
deflateEnd(&zs);
if (ret != Z_STREAM_END) {
throw std::runtime_error("deflate failed");
}
return outstring;
}
std::string decompress_string(const std::string& str)
{
z_stream zs{};
zs.zalloc = Z_NULL;
zs.zfree = Z_NULL;
zs.opaque = Z_NULL;
if (inflateInit(&zs) != Z_OK) {
throw std::runtime_error("inflateInit failed");
}
zs.next_in = (Bytef*)str.data();
zs.avail_in = (uInt)str.size();
int ret;
char outbuffer[32768];
std::string outstring;
do {
zs.next_out = (Bytef*)outbuffer;
zs.avail_out = sizeof(outbuffer);
ret = inflate(&zs, Z_NO_FLUSH);
if (outstring.size() < zs.total_out) {
outstring.append(outbuffer, zs.total_out - outstring.size());
}
} while (ret == Z_OK);
inflateEnd(&zs);
if (ret != Z_STREAM_END) {
throw std::runtime_error("inflate failed");
}
return outstring;
}
int main()
{
std::string original = R"(Hello zlib!
这是一个超长测试字符串,重复很多很多很多很多很多很多很多很多很多很多很多很多很多很多很多很多很多很多很多很多很多很多次!
用来验证压缩率是否真的很高。)";
std::cout << "原始大小: " << original.size() << " 字节\n";
auto compressed = compress_string(original);
std::cout << "压缩后: " << compressed.size() << " 字节 ("
<< 100.0 * compressed.size() / original.size() << "%)\n";
auto decompressed = decompress_string(compressed);
std::cout << "解压后大小: " << decompressed.size() << " 字节\n";
std::cout << "解压是否一致: " << (original == decompressed ? "YES" : "NO") << "\n\n";
std::cout << "原文预览:\n" << original << "\n";
return 0;
}
Metadata
Metadata
Assignees
Labels
No labels