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– thomas_f2018-07-17 11:53:34 +00:00Commented Jul 17, 2018 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_fmmdii– mmdii2018-07-17 12:20:05 +00:00Commented Jul 17, 2018 at 12:20
-
1Please, edit your question post with: 1. Layout of your project(what have your written in your comment). 2. The code which you have tried. 3. Exact error message.Tsyvarev– Tsyvarev2018-07-17 12:27:31 +00:00Commented Jul 17, 2018 at 12:27
-
1How in the world is it possible to answer your question!ConsistentProgrammer– ConsistentProgrammer2018-07-17 12:29:47 +00:00Commented Jul 17, 2018 at 12:29
-
sorry about bad question look 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 ? @ConsistentProgrammermmdii– mmdii2018-07-17 12:34:46 +00:00Commented Jul 17, 2018 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 Comment
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.