I'm new to CMake and I was trying to develop a shared library in Ubuntu. I've managed to create some basic CMakeLists.txt file that allows me to compile a very simple library with just one header and one source file.
In fact, my project tree was:
.
├── CMakesList.txt
├── First.h
|
└── src
└──First.cpp
And I was able to do the CMakeLists.txt file using this answer.
However, then I tried to add a little bit more complexity to the example, by adding a Second
class to the library.
Now, my public header, First.h
, also imports the include/Second.h
. The project tree is like this:
.
├── CMakesList.txt
├── First.h
|
└── include
| └──Second.h
|
└── src
└──First.cpp
└──Second.cpp
And I've made the necessary changes to the CMakesList file, which looks like this:
cmake_minimum_required(VERSION 3.1...3.15)
project(First VERSION 1.0
DESCRIPTION "It does very little"
LANGUAGES CXX)
include(GNUInstallDirs)
add_library(First SHARED
src/First.cpp
src/Second.cpp)
set_target_properties(First PROPERTIES
VERSION ${PROJECT_VERSION}
PUBLIC_HEADER First.h)
configure_file(FIRST.pc.in FIRST.pc @ONLY)
target_include_directories(First PRIVATE .)
install(TARGETS First
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(FILES ${CMAKE_BINARY_DIR}/First.pc
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig)
And this file is also run sucessfully. It builds the library with no errors.
However, now, when I'm linking the library and using it in another project, it does not compile, and gives me the following error:
/usr/local/include/First.h:36: error: include/Second.h: No such file or directory
#include "include/Second.h"
^~~~~~~~~~~~~~
So I guess my question is:
How can I also create a directory (in this case, at /usr/local/include/) that contains all the necessary headers requested by my public header (as well as other headers that can be requested by the headers requested by my public header, etc)? In this case, I would like to include the "Include" directory at the same directory where my public header is.
Sorry for the dumb question, I'm just exploring!
Thanks in advance!