Using CMake include does not seem to work intuatively

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

Using CMake include does not seem to work intuatively

Saad Khattak
Hi,

Let's say I have the following directory structure:
~/Repos/MyRepo/CMakeLists.txt
~/CMakeFiles/Foo.cmake
~/CMakeFiles/Bar.cmake

In the CMakeLists.txt I have the following command:

include(~/CMakeFiles/Foo.cmake)

And in Foo.cmake I have the following command:

include(Bar.cmake)

Turns out that he `include(Bar.cmake)` from `Foo.cmake` fails. This is counter to what I would expect (e.g. how #include works in C).

Is this a bug or is this behavior expected? If it's expected, what is the workaround? We have a lot of common cmake files which in turn include files relative to each other and not the calling CMakeLists.txt.

Thank you,
Saad

--

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:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Using CMake include does not seem to work intuatively

Petr Kmoch
Hi Saad.

I can't comment on whether the behaviour is correct or expectable, but to get it working the way you want, you can specify the path fully:

include(${CMAKE_CURRENT_LIST_DIR}/Bar.cmake)

Petr


On 13 December 2017 at 01:34, Saad Khattak <[hidden email]> wrote:
Hi,

Let's say I have the following directory structure:
~/Repos/MyRepo/CMakeLists.txt
~/CMakeFiles/Foo.cmake
~/CMakeFiles/Bar.cmake

In the CMakeLists.txt I have the following command:

include(~/CMakeFiles/Foo.cmake)

And in Foo.cmake I have the following command:

include(Bar.cmake)

Turns out that he `include(Bar.cmake)` from `Foo.cmake` fails. This is counter to what I would expect (e.g. how #include works in C).

Is this a bug or is this behavior expected? If it's expected, what is the workaround? We have a lot of common cmake files which in turn include files relative to each other and not the calling CMakeLists.txt.

Thank you,
Saad

--

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:
http://public.kitware.com/mailman/listinfo/cmake


--

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:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Using CMake include does not seem to work intuatively

Michael Jackson

The way "include" was explained to me years ago was that it operates in much the same way as literally "pasting" all the code from the included file directly into the place where the include() command is used. With this in mind the "include(Bar.cmake)" from the Foo.cmake file and the associated error make sense. If you were to copy-paste the code from Foo.cmake into your CMakeLIsts.txt file then it would be looking for a Bar.cmake file in the same directory as "CMakeLists.txt".

 

--

Michael Jackson | Owner, President

      BlueQuartz Software

[e] [hidden email]

[w] www.bluequartz.net

 

From: CMake <[hidden email]> on behalf of Petr Kmoch <[hidden email]>
Date: Wednesday, December 13, 2017 at 3:03 AM
To: Saad Khattak <[hidden email]>
Cc: CMake Mail List <[hidden email]>
Subject: Re: [CMake] Using CMake include does not seem to work intuatively

 

Hi Saad.

I can't comment on whether the behaviour is correct or expectable, but to get it working the way you want, you can specify the path fully:

include(${CMAKE_CURRENT_LIST_DIR}/Bar.cmake)

Petr

 

 

On 13 December 2017 at 01:34, Saad Khattak <[hidden email]> wrote:

Hi,

 

Let's say I have the following directory structure:

~/Repos/MyRepo/CMakeLists.txt

~/CMakeFiles/Foo.cmake

~/CMakeFiles/Bar.cmake

 

In the CMakeLists.txt I have the following command:

 

include(~/CMakeFiles/Foo.cmake)

 

And in Foo.cmake I have the following command:

 

include(Bar.cmake)

 

Turns out that he `include(Bar.cmake)` from `Foo.cmake` fails. This is counter to what I would expect (e.g. how #include works in C).

 

Is this a bug or is this behavior expected? If it's expected, what is the workaround? We have a lot of common cmake files which in turn include files relative to each other and not the calling CMakeLists.txt.

 

Thank you,

Saad


--

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:
http://public.kitware.com/mailman/listinfo/cmake

 

-- 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: http://public.kitware.com/mailman/listinfo/cmake


--

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:
http://public.kitware.com/mailman/listinfo/cmake