I have a very simply application that tries to build a main.cpp that includes a header file. The CMake file looks like this:
cmake_minimum_required(VERSION 3.21.0)
project(test_app
VERSION 0.1.0
LANGUAGES CXX C
)
set(CXX_STANDARD_REQUIRED 17)
add_executable(test_app)
target_sources(test_app PRIVATE
main.cpp
${CMAKE_CURRENT_SOURCE_DIR}/include/myinc.h
)
The project structure is:
.
├── CMakeLists.txt
├── include
│ └── myinc.h
└── main.cpp
main.cpp includes myinc.h, but cannot find it:
main.cpp:2:10: fatal error: myinc.h: No such file or directory
Looking at the compile_commands.json file I see:
"command": "/usr/bin/g++ -g -o CMakeFiles/scrathpad.dir/main.cpp.o -c /home/supal/cppsandbox/main.cpp"
According to https://github.com/Bagira80/More-Modern-CMake/blob/master/OhNoMoreModernCMake.pdf (slide 10), it is recommended to do it this way.
What am I doing wrong?
P.S., my CMake version is 3.22.