Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9139423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:23:08+00:00 2026-06-17T09:23:08+00:00

The project has roughly the following structure: include/ lib_name/ public_foo.h public_bar.h src/ CMakeLists.txt foo.c

  • 0

The project has roughly the following structure:

include/
  lib_name/
    public_foo.h
    public_bar.h
src/
  CMakeLists.txt
  foo.c
  foo.h
  bar.c
  bar.h
CMakeLists.txt

The top-level CMakeLists.txt file defines a shared library target

add_library(lib_name SHARED "src/foo.c" "src/bar.c")

At the same time, there’s a custom command

add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/src/foo-impl.c" ...)

that generated foo-impl.c in the build directory that is included by `foo.c’ like this:

#include <some_header.h>
#include <other.h>

#include "foo-impl.c"

In order to be able to include foo-impl.cI do the following in src/CMakeLists.txt

include_directories("${CMAKE_CURRENT_BINARY_DIR}")

Looks like it should work, right?

Well, it doesn’t work – the src directory is not added to compiler flags for foo.c. It seems like include directories affect only targets defined in the same directory (or subdirectories).

I know I can just do

include_directories("${CMAKE_CURRENT_BINARY_DIR}/src")

from the root CMakeLists.txt (in fact, this is how I’m doing it at the moment) but that’s not acceptable: every subdirectory will see the parent’s files and this can eventually lead to file name collisions.

How do people overcome this in large projects? or maybe I’m doing something wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:23:09+00:00Added an answer on June 17, 2026 at 9:23 am

    Like most cmake commands, include_directories only affects targets in that directory and subdirectories. And IIRC only targets defined after the command. That’s intentional. It’s how you define different flags for different modules.

    And when I say like most cmake commands, I really mean most. Most importantly including add_definitions and set except with CACHE argument.

    Also remember, that include_directories apples to targets, not files.

    Either define the library in the subdirectory (makes most sense to me), put everything in the top-level CMakeLists.txt or set the flags on the target only using set_target_properties(lib_name PROPERTIES COMPILE_FLAGS "-I${CMAKE_BINARY_DIR}/src") (must be done after the target is defined).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a project created in Eclipse that has roughly this structure: src conf
My project has the following requirements: Header fixed to the top of the page
My project has the following scenario: [Preview View Controller] --(Modal)--> Navigation Controller --(Top)--> [Photo
My project has a file foo that I've been using and checking in with
My current iPad project-in-progress has the need for a sequence of events; It roughly
I have a project that is a tab-bar controller. Each tab usually has a
My project has some unit tests. They all depend on some external service, over
My project has weirdly started failing with no error messages. Ive tried cleaning the
Our project has a trunk. I worked on Branch A, adding several features, and
My project has multiple themes with different colors. I need to skin certain textboxes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.