cmakelists.txt不在根文件夹中(但包含在源中)

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

本文关键字:包含 txt 根文件夹 cmakelists      更新时间:2023-10-16

我正在尝试编译一个libpng库。问题是我需要此库的特定版本-1.2.37-,因为我正在使用的项目是用此版本编写的。我在这里找到了此版本的源代码(gnuwin32项目)。

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

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

参见,cmakelists.txt比源文件更深一个级别。

我尝试过:

  1. 源目录 libpng-1.2.37-src/ ->导致错误:源目录似乎不包含cmakelists.txt
  2. 源目录 libpng-1.2.37-src/scripts ->导致多个错误:文件libpng-1.2.37-src/scripts/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/scripts/cmakelists.cmakelists.txt"。

我该怎么做才能使它起作用?我不知道为什么不能使用cmakelists.txt文件。

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

和附带说明,在此之前,它说安装它的经典方法是:

On Unix/Linux and similar systems, you can simply type
    ./configure [--prefix=/path]
    make check
    make install

听起来您对3),但是您忘了在尝试再次尝试之前清理构建。

如果它是您在项目中使用的库,则可以通过称为'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"