C++ cmake - CMakeLists.txt 不在根文件夹中(但包含在源代码中)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21409935/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 23:38:34  来源:igfitidea点击:

cmake - CMakeLists.txt is not in root folder (but is included in source)

c++cmakelibpng

提问by dvdkouril

I'm trying to compile a libpng library. The thing is that I need a specific version of this library - 1.2.37 - because the project I'm using it in is written with this version. I've found the source code of this version here(GnuWin32 project).

我正在尝试编译一个 libpng 库。问题是我需要这个库的特定版本 - 1.2.37 - 因为我正在使用它的项目是用这个版本编写的。我发现这个版本的源代码在这里(的GnuWin32项目)。

But the folder structure looks something like this:

但是文件夹结构看起来像这样:

libpng-1.2.37-src/
   contrib/
   projects/
   scripts/
      CMakeLists.txt
   png.h
   pngread.c
   pngwrite.c
   ...

See, the CMakeLists.txt is one level deeper than the source files.

看,CMakeLists.txt 比源文件更深一层。

I've tried:

我试过了:

  1. source directory libpng-1.2.37-src/-> resulted in error: The source directory does not appear to contain CMakeLists.txt
  2. source directory libpng-1.2.37-src/scripts-> resulted in multiple errors: File libpng-1.2.37-src/scripts/scripts/libpng.pc.in does not exist.
  3. copy CMakeLists.txt from /scriptsto /libpng-1.2.37-srcand set source directory to /libpng-1.2.37-src-> resulted in error: The source "/libpng-1.2.37-src/CMakeLists.txt" does not match the source "/libpng-1.2.37-src/scripts/CMakeLists.txt" used to generate cache.
  1. 源目录libpng-1.2.37-src/-> 导致错误:源目录似乎不包含 CMakeLists.txt
  2. 源目录libpng-1.2.37-src/scripts-> 导致多个错误:文件 libpng-1.2.37-src/scripts/scripts/libpng.pc.in 不存在。
  3. 将 CMakeLists.txt 从/scripts复制到/libpng-1.2.37-src并将源目录设置为/libpng-1.2.37-src-> 导致错误:源“/libpng-1.2.37-src/CMakeLists.txt " 与用于生成缓存的源 "/libpng-1.2.37-src/scripts/CMakeLists.txt" 不匹配。

What should I do to make it work? I don't know why the CMakeLists.txt file would be included if it can't be used.

我该怎么做才能让它发挥作用?我不知道为什么不能使用 CMakeLists.txt 文件。

采纳答案by Silex

The INSTALLfile explicitely says:

INSTALL文件明确指出:

If you want to use "cmake" (see www.cmake.org), copy CMakeLists.txt
from the "scripts" directory to this directory and type

   cmake . [-DPNG_MMX=YES] -DCMAKE_INSTALL_PREFIX=/path
   make
   make install

And as a side note, before this it says that the classic way to install it is:

作为旁注,在此之前它说安装它的经典方法是:

On Unix/Linux and similar systems, you can simply type

    ./configure [--prefix=/path]
    make check
    make install

It sounds like you did right with 3), however you forgot to cleanup the build dir before trying again.

听起来您对 3) 的处理是正确的,但是您在重试之前忘记清理构建目录。

回答by Vaclav P.

If it's library which you use in your project you can build it automatically via technique called 'superbuild' (use ExternalProject_Add). By specifying SOURCE_SUBDIR as is described hereto subdirectory with CMakeLists.txt you can do something like this

如果它是您在项目中使用的库,则可以通过称为“superbuild”的技术(使用 ExternalProject_Add)自动构建它。通过将此处描述的 SOURCE_SUBDIR 指定为CMakeLists.txt 的子目录,您可以执行以下操作

  ExternalProject_Add(libpng
  GIT_REPOSITORY    url-to-your-repository.git
  GIT_TAG           v1.2.37
  SOURCE_SUBDIR     "scripts"