I am working on a library with the tree looking something like(file names have been changed a little bit for simplicity):
.
├── CMakeLists.txt
├── include
│ └── proj_name
│ ├── core
│ │ ├── file00.h
│ │ ├── file01.h
│ │ ├── ...
│ │ ├── ...
│ │ └── filen.h
│ └── core.h
└── src
├── file00.c
├── file01.c
├── ...
├── ...
└── filem.c
Now, I need to created a shared library, so I have written the CMakeLists as:
cmake_minimum_required(VERSION 3.5)
project(module VERSION 1.0.0)
include(GNUInstallDirs)
add_library(module SHARED
src/file00.c
src/file01.c
src/...
src/...
src/filem.c
)
set_target_properties(module PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION 1
PUBLIC_HEADER include/proj_name/core.h)
target_include_directories(proj_name PRIVATE include)
target_include_directories(proj_name PRIVATE src)
install(TARGETS proj_name
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/proj_name)
The issue starts from here onwards. This CMakeLists is generating the shared objects in the /usr/local(as expected) shown below:
.
├── include
│ └── proj_name
│ └── core.h
└── lib
├── ...
├── libcore.so -> libcore.so.1
├── libcore.so.1 -> libcore.so.1.0.0
└── libcore.so.1.0.0
But inside the include subdirectory only core.h is copied, to use my library I have to manually copy the ./include/proj_name/core
directory into /usr/local
.
Q1. Is there a way in which I can do that with the help of CMakeLists only?
Q2. In future I am planning to extend my library and the whole tree(at top) is just a single module. If I want to install the library as:
/usr/local/include/proj_name/proj_name.h
/usr/local/include/proj_name/module1.h
/usr/local/include/proj_name/module2.h
...
How should I write the CMakeLists?
[EDIT]: I forgot to mention the tree structure for my future library:
.
├── include
│ └── proj_name
│ └── proj_name.h
├── module1
│ ├── CMakeLists.txt
│ ├── include
│ │ └── proj_name
│ │ ├── module1
│ │ │ ├── file00.h
│ │ │ └── file01.h
│ │ └── module1.h
│ └── src
│ ├── file00.c
│ └── file01.c
├── module2
│ ├── CMakeLists.txt
│ ├── include
│ │ └── proj_name
│ │ ├── module2
│ │ │ ├── file00.h
│ │ │ └── file01.h
│ │ └── module2.h
│ └── src
│ ├── file00.c
│ └── file01.c
└── module3
├── CMakeLists.txt
├── include
│ └── proj_name
│ ├── module3
│ │ ├── file00.h
│ │ └── file01.h
│ └── module3.h
└── src
├── file00.c
└── file01.c