1

Here is an example of project structure :

CMakeLists.txt
  A/
    includes/a.h
    src/a.cpp
    CMakeLists.txt
  B/
    includes/b.h
    src/b.cpp
    CMakeLists.txt

And here is a sumup of my CMake config

cmake_minimum_required(VERSION 3.16)

project("WeedEngine")

# add_subdirectory(A)
add_library(A src/a.cpp)

target_include_directories(A PUBLIC includes)

# add_subdirectory(B)
add_library(B src/b.cpp)

target_link_libraries(B PRIVATE A)

I would like to link in my b.cpp the headers from my lib A like this

// b.cpp
#include "A/a.h"

But i can't manage to give an alias to my headers properly. Should I use something like this :

target_include_directories(A
    PUBLIC
    $<TARGET_NAME:${CMAKE_CURRENT_SOURCE_DIR}/includes>
)

Best regards,

Hugo Serrat
  • 149
  • 2
  • 12
  • You can use the `CMAKE_SOURCE_DIR` variable to use the **top-level** source directory in your `target_include_directories()` call. Thus, you could include them with `#include "A/include/a.h"`. See my response [here](https://stackoverflow.com/a/58193842/3987854). – Kevin Jan 23 '20 at 14:56
  • 2
    If you can change your project structure, you can just add a folder called "A" under "includes" in the `A` project and this will give you the alias you're looking for. For the most part this is how I structure my projects and it's worked quite well. – Developer Paul Jan 23 '20 at 15:49

0 Answers0