cmake - using header files in higher directories

This is a discussion on cmake - using header files in higher directories within the C Programming forums, part of the General Programming Boards category; Hi, Say I have a directory structure: lib/dbg/debug.h lib/other/other.h lib/other/other.c tools/program.c And other.c has: #include "lib/dbg/debug.h" How do I setup ...

  1. #1
    Spam is Good
    Join Date
    Jan 2009
    Location
    In a cave on Mars
    Posts
    37

    cmake - using header files in higher directories

    Hi,

    Say I have a directory structure:
    lib/dbg/debug.h
    lib/other/other.h
    lib/other/other.c
    tools/program.c

    And other.c has: #include "lib/dbg/debug.h"

    How do I setup the CMakeFiles.txt files in each directory, so the executable "program" (from program.c) is created.

    Currently I get the error:

    lib/other/other.h:33: fatal error: lib/dbg/debug.h: No such file or directory

    Thanks in advance.
    "What comes around, goes around"

  2. #2
    Just a pushpin. bernt's Avatar
    Join Date
    May 2009
    Posts
    426
    Just a shot in the dark, but you might have to specify that file relative to other.h, as in
    Code:
    (other.h)
    
    #include "../dbg/debug.h"
    ...
    so as to appease the preprocessor.
    Consider this post signed

  3. #3
    Spam is Good
    Join Date
    Jan 2009
    Location
    In a cave on Mars
    Posts
    37
    Ok, that works, but doesn't solve my next problem:

    I'm wanting to use cmake to create a static library of my project.
    The project (libspam) has the directory structure:
    CMakeLists.txt
    common/CMakeLists.txt
    common/test.h
    common/test.c
    other/CMakeLists.txt
    other/test2.c
    other/test2.h

    Where the root path CMakeLists.txt is:
    Code:
    project(LIBSPAM)
    
    add_subdirectory(common)
    add_subdirectory(other)
    
    # create static lib
    add_library(spam STATIC common/test.c other/test2.c)
    target_link_libraries(spam usb-1.0)
    
    install (TARGETS spam DESTINATION lib)
    install(FILES common/test.c other/test2.c DESTINATION include)
    And common/CMakeLists.txt is:
    Code:
    cmake_minimum_required(VERSION 2.8)
    add_library(common test)
    And other/CMakeLists.txt is:
    Code:
    cmake_minimum_required(VERSION 2.8)
    add_library(other test2)
    While this works, the header file include paths are:

    #include "../common/test.h"
    #include "../other/test2.h"

    So if I installed these header files, it may overwrite some similar named files, and the above include paths are wrong for other programs that use these header files. How can I set the include paths to:

    #include "libspam/common/test.h"
    #include "libspam/other/test2.h"

    And get cmake to install these headers in /usr/local/lib/libspam/
    Last edited by coletek; 11-02-2010 at 07:30 PM.
    "What comes around, goes around"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Trying to make the best use of header files
    By alanb in forum C++ Programming
    Replies: 4
    Last Post: 08-31-2009, 04:45 PM
  2. what am I missing? (Program won't compile)
    By steals10304 in forum C Programming
    Replies: 3
    Last Post: 08-25-2009, 03:01 PM
  3. Header files and multiple definitions
    By sjweinberg in forum C++ Programming
    Replies: 16
    Last Post: 07-17-2009, 05:59 PM
  4. Confusion on header and source files
    By dnguyen1022 in forum C++ Programming
    Replies: 4
    Last Post: 01-17-2009, 02:42 AM
  5. Conflicting Header Files
    By X PaYnE X in forum Windows Programming
    Replies: 17
    Last Post: 01-08-2004, 10:28 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21