# Own CMAKE library

**URL:** https://discourse.cmake.org/t/own-cmake-library/5179
**Category:** Code
**Tags:** os:linux, gen:makefiles
**Created:** [March 6, 2022, 4:31pm UTC](https://discourse.cmake.org/t/own-cmake-library/5179 "2022-03-06T16:31:47Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Spyrex](https://discourse.cmake.org/user_avatar/discourse.cmake.org/spyrex/32/2247_2.png) [@Spyrex](https://discourse.cmake.org/u/Spyrex)
#### Post date: [March 6, 2022, 4:31pm UTC](https://discourse.cmake.org/t/own-cmake-library/5179/1 "2022-03-06T16:31:47Z")

</div>

Hey, I am relatively new to cpp.  
I programmed some classes I want to be able to build to a separate library I can use from another cpp project.

This my directory structure:

```auto
Root
- Game/
   - CMakeLists.txt
   - main.cpp
- Engine/
   - CMakeLists.txt
   - src/
      - Engine.h
      - ....
- CMakeLists.txt
```

Now I want to be able to run a function from Engine.h in main.cpp but I get the error “Velium.h: No such file or directory”

These are my CMakeLists:

Root CMakeLists.txt

```auto
cmake_minimum_required(VERSION 3.21)
project(Root)

set(CMAKE_CXX_STANDARD 23)

set(VELIUM_INCLUDE_DIR
        ${CMAKE_CURRENT_SOURCE_DIR}/Engine)

add_subdirectory(Engine)

include_directories(${Engine_INCLUDE_DIR})

add_subdirectory(Game)

ADD_DEPENDENCIES(Game Engine)
```

Engine CMakeLists.txt

```auto
cmake_minimum_required(VERSION 3.21)
project(Engine)

set(CMAKE_CXX_STANDARD 23)

add_library(Engine STATIC
        src/Engine.h)

target_include_directories(Engine PUBLIC lib/imgui/)

target_link_libraries(Engine -lGL -lsfml-network -lsfml-graphics -lsfml-window -lsfml-system -lsfml-audio -lX11)

```

Game CMakeLists.txt

```auto
cmake_minimum_required(VERSION 3.21)
project(Game)

set(CMAKE_CXX_STANDARD 23)

add_executable(Game
        main.cpp)

target_link_libraries(Game Engine)

```

---

<div class="post-metadata">

### Author: ![buildSystemPerson](https://discourse.cmake.org/user_avatar/discourse.cmake.org/buildsystemperson/32/2851_2.png) [@buildSystemPerson](https://discourse.cmake.org/u/buildSystemPerson)
#### Post date: [March 7, 2022, 8:14pm UTC](https://discourse.cmake.org/t/own-cmake-library/5179/2 "2022-03-07T20:14:41Z")

</div>

You aren’t propagating the include directory for your engine code. Do this:

```auto
target_include_directories(Engine PUBLIC 
    lib/imgui/
    # You need to provide the include directory to your clients
    src/
)

```

If Engine.h is the interface to your library I recommend putting it in a inc/ folder instead of the src folder.

The general convention is that inc/ represents the interface to your library

Also FWIW most projects only need 1 `cmake_minimum_required` call. And generally only need 1 `project` call. Those 2 calls are only necessary for your `root` CMakeLists.txt (which is called the top level CMakeLists)
