如何为第三方库正确编写 CmakeLists.txt?

时间:2021-02-04 06:20:19

标签: c++ cmake lemon

我正在使用 CLion 编写一个 Cmake 项目。这里是目录的树状图(忽略文件),其中lemon-1.3-1是第三方库。

├── cmake-build-debug
│   ├── CMakeFiles
│   │   ├── 3.15.3
│   │   │   ├── CompilerIdC
│   │   │   │   └── tmp
│   │   │   └── CompilerIdCXX
│   │   │       └── tmp
│   │   ├── CheckTypeSize
│   │   ├── CMakeTmp
│   │   ├── graph_partition_essay.dir
│   │   └── Progress
│   └── lemon-1.3.1
│       ├── cmake
│       ├── CMakeFiles
│       │   ├── check.dir
│       │   └── dist.dir
│       └── lemon
│           └── CMakeFiles
│               └── lemon.dir
│                   └── bits
└── lemon-1.3.1
    ├── cmake
    │   └── nsis
    ├── contrib
    ├── demo
    ├── doc
    │   ├── html
    │   │   └── search
    │   └── images
    ├── lemon
    │   ├── bits
    │   └── concepts
    ├── scripts
    ├── test
    └── tools

我还写了以下 CMakeLists.txt。使用这个文件,代码自动补全可以正常工作。

cmake_minimum_required(VERSION 3.15)
project(graph_partition_essay)

set (LEMON_INCLUDE_PATH ${CMAKE_SOURCE_DIR}/lemon-1.3.1)
add_subdirectory(lemon-1.3.1)
add_executable(graph_partition_essay main.cpp)

main.cpp

#include <iostream>
#include "lemon-1.3.1/lemon/list_graph.h"

using namespace lemon;
int main() {
    ListDigraph g;
    std::cout << "Hello, World!" << std::endl;
    return 0;
}

但是当我运行 main 函数时,我收到以下错误消息。

In file included from F:\xxx\graph_partition_essay\main.cpp:2:
F:\xxx\graph_partition_essay\lemon-1.3.1/lemon/list_graph.h:26:10: fatal error: lemon/core.h: No such file or directory
   26 | #include <lemon/core.h>
      |          ^~~~~~~~~~~~~~
compilation terminated.

我该如何解决这个问题?

0 个答案:

没有答案
相关问题