Own CMAKE library

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:

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

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

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

cmake_minimum_required(VERSION 3.21)
project(Game)

set(CMAKE_CXX_STANDARD 23)

add_executable(Game
        main.cpp)

target_link_libraries(Game Engine)

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

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)