[cmake-developers] include directories per source file

Lectem lectem at gmail.com
Sat Dec 2 07:54:45 EST 2017


(edited the subject)
> Did you check these?
> https://cmake.org/cmake/help/v3.10/command/target_include_directories.html
> https://cmake.org/cmake/help/v3.10/command/target_sources.html
Yes I’m very well aware of those commands, but they do not achieve what I described, as it populates target properties, not source file properties.
Also target_sources can only be used to conditionally link targets or propagate source files needed for target that links the library (such as .natvis files), which is not what I want here.

Bests,
Lectem

De : Jano Svitok
Envoyé le :samedi 2 décembre 2017 13:38
À : Lectem
Cc : cmake-developers at cmake.org
Objet :Re: [cmake-developers] (no subject)

On Sat, Dec 2, 2017 at 10:45 AM, Lectem <lectem at gmail.com> wrote:
Hi,
 
I’m hurting an issue trying to hide dependencies from files that do not need those.
For example, I have a library that helps me decode some file, but I don’t want this library headers to be available for every .cpp in my library but one.
 
For example what one may do is the following :
 
#---------------------
add_library(mylib foo.cpp bar.cpp)
target_link_libraries(mylib PRIVATE libonlyusefulforfoo)
#---------------------
 
It works fine, but now bar.cpp can also include headers from libonlyusefulforfoo.
So what I tried was to use object libraries, but it has many disadvantages :
• I now have to duplicate dependencies for the object library and mylib if they have include directories requirements or compile flags in common
• An object library is a target… and I don’t want to add one target per file that has special include directories
• An object library shows in IDEs, while I’d like the .cpp files to stay in the same project. In visual the obj will be in my library but this is not practical.
I thought about source files properties, but unfortunately they do not support include directories, so here is my question :
 
TL ;DR
Would it be possible/difficult to have a PRIVATE_INCLUDE_DIRECTORIES property added for source files ? 
We already have COMPILE_FLAGS so why not include directories ?
 
I know we can set include directories per directory, but I don’t think that putting single .cpp files in seperate headers is good.
 
Thanks,
Lectem

Did you check these?

https://cmake.org/cmake/help/v3.10/command/target_include_directories.html
https://cmake.org/cmake/help/v3.10/command/target_sources.html
Jano

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20171202/f6a79358/attachment-0001.html>


More information about the cmake-developers mailing list