i have some .cpp files and their headers as includes in separate folders how i should write CMakeLists.txt for them . i can't write their address so compiler gets error like this -> no such file
-
1Can you be a bit more specific? Create a **minimal** example that represents your problem (folder/file structure etc). – thomas_f Jul 17 '18 at 11:53
-
look i have 3 folders one of them is src that have .cpp files like main.cpp and other .cpp files in it. one of folders named include that have .h files and last folder is nessesery libraries .now i should link them together in CMakeLists.txt in other folder and make them @thomas_f – mmdii Jul 17 '18 at 12:20
-
1Please, [edit] your question post with: 1. Layout of your project(what have your written in [your comment](https://stackoverflow.com/questions/51380520/how-to-write-cmake-for-multiple-cpp-files-and-headers-in-different-folders#comment89734109_51380520)). 2. The **code** which you have tried. 3. **Exact error message**. – Tsyvarev Jul 17 '18 at 12:27
-
1How in the world is it possible to answer your question! – ConsistentProgrammer Jul 17 '18 at 12:29
-
sorry about bad question look https://github.com/mrlspl/bare-library this is project that use autoconf and automake to make files and generate a specific lib . here i should use Cmake instead of this makefile system (autoconf and automake) how should i do this ? @ConsistentProgrammer – mmdii Jul 17 '18 at 12:34
2 Answers
Here is a simple example for CMake for a multiple files project. You will need to adapt it your own case:
|-- CMakeLists.txt <<---- cMAKEfile
|-- include
| \-- header.h
\-- src
|-- header.cpp
\-- main.cpp
Your CMakeLists.txt should look as follows:
project(test)
include_directories(include)
file(GLOB SOURCES "src/*.cpp")
add_executable(test ${SOURCES})
Then you can execute cmake
and make
commands.

- 1,294
- 10
- 14
Based on ConsistentProgrammer's answer: you can create two variables that will hold the file lists.
The header list will hold the files in the include directory and it's content will be like this: "./include/foo.h", "./include/bar.h"...
The source list will be similar but will hold the files inside the source directories.
I'm assuming that the directories are inside the directory that contains the CMakeLists.txt.
Also, you must inform to cmake the include directory using the command include_directories(dir).
I have a small example at github: Simple separated includes and cpps.

- 217
- 3
- 13