c_spk
c_spk

Reputation: 179

CMake: build subproject depending on other's subproject header

I have a project containing two subdirectories (simplified):

project(superproj)    
add_subdirectory(foo-api)
add_subdirectory(bar-api)

bar-api uses foo-api headers and expects them to be installed in $PREFIX/include/foo (its files contain #include <foo/header.h>)

But when I compile this superproject, I don't want foo-api actually installed in my system. How do I build bar-api in this case? Is it possible to do so without messing with bar-api's CMakeFile? I want to keep these two projects as much independent as possible, so one could just clone and build them separately.

Upvotes: 2

Views: 1205

Answers (1)

Sergey
Sergey

Reputation: 8238

Use include_directories:

project(superproj) 
include_directories(foo-api/path/to/includes)   
add_subdirectory(foo-api)
add_subdirectory(bar-api)

It's action is propagated to all subdirectories in current directory. And yes, consider target_include_directories for modern versions of CMake, as Florian mentioned in comments.

Upvotes: 1

Related Questions