[CMake] header files/build orgainization with cmake

majo huber majo.huber at gmail.com
Tue Jun 17 07:46:52 EDT 2014


Hi @all,

I have a question regarding the organization of the header files of
libraries.
I have a meta project with following structure:

metaproj1/
|-- CMakeLists.txt
|-- lib1/
    |-- include/
    |   |
    |   `-- lib1.h
|   |-- CMakeLists.txt
|   `-- lib1.c
`-- proj2/
    |-- CMakeLists.txt
    `-- main.c

The meta project contains several other projects not mentioned here.
I would like to be able to do following things.
- the lib1 project should be usable in any other meta project without any
changes to the library. E.g. in metaproject metaproj2
- install library header file to include/lib1/ in the system (e.g.
/usr/local/include/lib1/lib1.h)
- include in any other source like that: #include <lib1/lib1.h> (see
following examples)
  - include the header from the system location it is installed in (e.g.
/usr/local/include/lib1/lib1.h) ( with #include <lib1/lib1.h>)
  - include the header from project proj2 with #include <lib1/lib1.h> (for
builds from inside the meta project without installing the library)

One approach I thought of is the following:
- copy all installed header files to a temp. build directory named lib1
- set variable LIB1_INCLUDE_DIR to point to that directory
- use the variable with include_directories(${LIB1_INCLUDE_DIR}) in proj2

I know that there is a mechanism called find_package(), but if I am correct
this does not allow to have a different directory inside the library for
the headers (include) and as installation path (lib1/), right?

Now I wanted to know if there is any better solution to my problem?


Thanks in Advance,
majo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20140617/45c9829b/attachment.html>


More information about the CMake mailing list