how to correctly write CmakeLists.txt for third-party library?

287 views Asked by At

I am using CLion to write a Cmake project. here is the tree view of the directory(files are ignored),where lemon-1.3-1 is the third party library.

├── 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

Also I write the following CMakeLists.txt. Using this file, the auto code completion can function normally.

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)

and the 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;
}

But when I run the main function, I got the following error message.

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.

How can I fix this problem?

0

There are 0 answers