I have a CMake project with the following directory structure:
- CMakeLists.txt
- A/CMakeLists.txt
- B/CMakeLists.txt
A and B both describe shared libraries, and B depends upon A.
Calling cmake
on the entire project gives no problems. Neither does building A, but building B tells me it misses symbols from A. This makes sense, and so I solved that by adding target_link_libraries(B A)
to B/CMakeLists.txt.
However, when I call cmake
now, I get errors about B/CMakeLists.txt not being able to find source files from A. Apparently, to solve this, I should add target_include_directories(A PUBLIC .)
to A/CMakeLists.txt, but that does not work. What am I missing here?
For completion's sake, here's the dumbed-down CMake files:
cmake_minimum_required (VERSION 3.5.1)
project(main C CXX)
add_subdirectory(A)
add_subdirectory(B)
A/CMakeLists.txt
cmake_minimum_required (VERSION 3.5.1)
add_library(A SHARED "")
target_include_directories(A PUBLIC .)
target_sources(A PUBLIC ...)
B/CMakeLists.txt
cmake_minimum_required (VERSION 3.5.1)
add_library(B SHARED "")
target_link_libraries(B A)
target_sources(B PUBLIC ...)
The error I get is the following
CMake Error at B/CMakeLists.txt:3 (add_library): Cannot find source file:
Access.hpp
Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp .hxx .in .txx
I'm following this tutorial, explaining about target_link_libraries
and target_include_directories
.
add_library()
you specify source files (*c, *.cpp) to build library from. What isAccess.hpp
header is doing there? – VelkanBinPackingSpace.cpp
). – Stijn FrishertB/CMakeLists.txt
file? – Velkan