[CMake] header files/build orgainization with cmake

Marcel Loose loose at astron.nl
Tue Jun 17 08:04:45 EDT 2014


Hi Majo,

We have a similar situation. I assume you want to use lib1 in proj2 at
build time, without doing a separate install. The way I solved this
involves symbolic links, which AFAIK only work on Unix-like systems.

We have an include directory inside the build directory that is
populated with symbolic links to the diverse directories containing
header files at cmake configure time. So, in your case there should be a
symbolic link ${CMAKE_BINARY_DIR}/include/lib1 that points to
${CMAKE_SOURCE_DIR}/lib1/include. Then, somewhere at the top of your
main CMakeLists.txt file you should add ${CMAKE_BINARY_DIR}/include to
the include path using include_directories().

Now proj2 should be able to locate lib1/lib1.h through the symbolic
link, because ${CMAKE_BINARY_DIR}/include is in the -I<path>.

Hope this helps.

Regards,
Marcel Loose.

On 17/06/14 13:46, majo huber wrote:
> 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/a0fb78fd/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: loose.vcf
Type: text/x-vcard
Size: 292 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/cmake/attachments/20140617/a0fb78fd/attachment.vcf>


More information about the CMake mailing list