[CMake] Troubles with include_directories

Workbench@gmx.at workbench at gmx.at
Sun Mar 10 17:01:30 EDT 2019


I talked a long time on irc.freenode.org #cmake channel and got told
everything you told me and more, i'm now aware of much more knowledge
than before thanks to that channel. Thanks for your late answer anyway.


best regards!

On 10.03.19 16:09, Eric Noulard wrote:
>
>
> Le sam. 9 mars 2019 à 08:44, Workbench at gmx.at
> <mailto:Workbench at gmx.at> <workbench at gmx.at <mailto:workbench at gmx.at>>
> a écrit :
>
>     Hi everyone,
>
>     i've a project setup that looks like this:
>
>
>     abc.h
>
>     def.h
>
>     and all my other .cpp and .h files are in the folder intern. Now my
>     CMakeLists.txt looks like this:
>
>     cmake_minimum_required(VERSION 3.7)
>     project(BS_Application)
>     set(SRC
>          BS_AppTypes.hpp
>          BS_IEvent.hpp
>          BS_ISystem.hpp
>          BS_IWindow.hpp
>          BS_ITimerTask.hpp
>          BS_IEventConsumer.hpp
>          BS_Application.cpp
>          BS_Button.cpp
>          BS_ContextSDL.cpp
>          BS_ISystem.cpp
>          BS_System.cpp
>          BS_SystemSDL.cpp
>          BS_WindowSDL.cpp
>          BS_ContextSDL.cpp
>          BS_DisplayManagerSDL.cpp
>          BS_Button.cpp
>          BS_EventManager.cpp
>          BS_EventPrinter.cpp
>          BS_ModifierKeys.cpp
>          BS_DisplayManager.cpp
>     )
>     set(INC
>          intern
>     )
>     include_directories(${INC})
>     add_library(BS_Application STATIC ${SRC})
>
>     Where all files above BS_Application.cpp are in the folder intern
>     but he
>     is not able to find BS_Application.cpp but i added it to the
>     include_direcotires, what am i doing wrong here ?
>
>
> First of all usage of include_directories is a discouraged old-style
> variable oriented CMake.
> You should prefer target oriented rule.
> Namelly target_include_directories().
> You can have a look
> at: https://steveire.wordpress.com/2017/11/05/embracing-modern-cmake/
> and/or
> refered presentation from Daniel Pfeifer or Mathieu Ropert there in.
> It'll get you a broad view of the "Modern CMake way to go".
>
> Now both commands (target_include_directories or include_directories)
> influence where *header* file are found.
> So that if you say
>
> include_directories(${INC})
> add_library(BS_Application STATIC BS_Application.cpp)
>
> CMake won't go looking for "BS_Application.cpp" inside ${INC}.
> You should refer to your source files with the proper path:
> i.e.
> add_library(BS_Application STATIC ${INC}/BS_Application.cpp)
>
> You may consider having a look at how to use target_source as well.
> Craig Scott published a nice blog entry about that:
> https://crascit.com/2016/01/31/enhanced-source-file-handling-with-target_sources/
>
> Regards,
> Eric
>
>
>     best regards!
>
>     -- 
>
>     Powered by www.kitware.com <http://www.kitware.com>
>
>     Please keep messages on-topic and check the CMake FAQ at:
>     http://www.cmake.org/Wiki/CMake_FAQ
>
>     Kitware offers various services to support the CMake community.
>     For more information on each offering, please visit:
>
>     CMake Support: http://cmake.org/cmake/help/support.html
>     CMake Consulting: http://cmake.org/cmake/help/consulting.html
>     CMake Training Courses: http://cmake.org/cmake/help/training.html
>
>     Visit other Kitware open-source projects at
>     http://www.kitware.com/opensource/opensource.html
>
>     Follow this link to subscribe/unsubscribe:
>     https://cmake.org/mailman/listinfo/cmake
>
>
>
> -- 
> Eric
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20190310/3ace0a5b/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pEpkey.asc
Type: application/pgp-keys
Size: 2452 bytes
Desc: not available
URL: <https://cmake.org/pipermail/cmake/attachments/20190310/3ace0a5b/attachment.key>


More information about the CMake mailing list