Troubles with include_directories

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Troubles with include_directories

Steven Truppe
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 ?


best regards!

--

Powered by 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
Reply | Threaded
Open this post in threaded view
|

Re: Troubles with include_directories

Steven Truppe
I mean belov, all files bellow BS_IEventConsumer.hpp (beginning with
BS_Application) are in the intern folder in the same path as the other
files above BS_Application.


best regards!

On 09.03.19 08:38, [hidden email] wrote:

> 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 ?
>
>
> best regards!
>
--

Powered by 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
Reply | Threaded
Open this post in threaded view
|

Re: Troubles with include_directories

Eric Noulard
In reply to this post by Steven Truppe


Le sam. 9 mars 2019 à 08:44, [hidden email] <[hidden email]> 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().
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:

Regards,
Eric


best regards!

--

Powered by 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

--

Powered by 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
Reply | Threaded
Open this post in threaded view
|

Re: Troubles with include_directories

Steven Truppe

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, [hidden email] <[hidden email]> 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().
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:

Regards,
Eric


best regards!

--

Powered by 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

--

Powered by 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

pEpkey.asc (2K) Download Attachment