Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write Cmake for multiple .cpp files and headers in different folders ?

Tags:

c++

cmake

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

like image 929
mmdii Avatar asked Dec 17 '22 22:12

mmdii


1 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.

like image 149
ConsistentProgrammer Avatar answered Dec 28 '22 21:12

ConsistentProgrammer