My project has two utility library in it. I am looking for the best way to write CMake configurations for the libraries.
/my_project
--> CMakeLists.txt
--> main.cpp
--> /utils
--> CMakeLists.txt
--> common.h
--> /base_c
--> CMakeLists.txt
--> base_c.c
--> base_c.h
--> /base_cpp
--> CMakeLists.txt
--> base_cpp.cpp
--> base_cpp.hpp
My current CMake files:
/my_project/CMakeLists.txt
cmake_minimum_requared(VERSION 3.8)
project(my_project)
add_subdirectory(utils)
add_executable(main main.c)
target_link_libraries(main utils base_c base_cpp)
/my_project/utils/CMakeLists.txt
add_subdirectory(base_c)
add_subdirectory(base_cpp)
add_library(utils)
target_sources(utils PUBLIC common.h)
/my_project/utils/base_c/CMakeLists.txt
add_library(base_c base_c.c)
target_sources(base_c PUBLIC base_c.h)
/my_project/utils/base_cpp/CMakeLists.txt
add_library(base_cpp base_cpp.cpp)
target_sources(base_cpp PUBLIC base_cpp.hpp)
find_library(BASEC base_c ../base_c)
target_link_libraries(base_cpp BASEC)
The problem is that base_cpp does not find includes from base_c. How should I fix the configuration?
I managed to make it work with target_include_directories(base_cpp PRIVATE ../base_c), but that's ugly and shouldn't be necessary, according to INTERFACE_INCLUDE_DIRECTORIES documentation.