---
# System prepended metadata

title: My c project

---

# My c project
this is my project structure before compile

~/proj/CMakeLists.txt
~/proj/src/CMakeLists.txt
~/proj/src/main.cpp
~/proj/build/



## input
proj/CMakeList.txt
```cmake=
cmake_minimum_required(VERSION 3.10)
project(test)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

include_directories(/usr/local/include)

add_subdirectory(src)
```
proj/src/CMakeList.txt
```cmake=
find_package(OpenGL REQUIRED)
find_package(GLUT REQUIRED)
add_executable(test main.cpp)
set(GL_LIBRARIES OpenGL::GL GLUT::GLUT)
target_link_libraries(test ${GL_LIBRARIES})

```



## Output

build/compile_command.json
```json
[
{
  "directory": "/home/hanslu95/proj/src",
  "command": "/usr/bin/c++  -isystem /usr/local/include  -o CMakeFiles/test.dir/main.cpp.o -c /home/hanslu95/proj/src/main.cpp",
  "file": "/home/hanslu95/proj/src/main.cpp",
  "output": "src/CMakeFiles/test.dir/main.cpp.o"
}
]
```
compile_command.json
```json
[
{
  "directory": "/home/hanslu95/proj/src",
  "command": "/usr/bin/c++  -isystem /usr/local/include  -o CMakeFiles/test.dir/main.cpp.o -c /home/hanslu95/proj/src/main.cpp",
[
{
  "directory": "/home/hanslu95/proj/build/src",
  "command": "/usr/bin/c++  -isystem /usr/local/include  -o CMakeFiles/test.dir/main.cpp.o -c /home/hanslu95/proj/src/main.cpp",
  "file": "/home/hanslu95/proj/src/main.cpp",
  "output": "src/CMakeFiles/test.dir/main.cpp.o"
}
]
```


## Final Result
![image](https://hackmd.io/_uploads/B1Ks2j95p.png)
