[CMake] Using CMake include does not seem to work intuatively

Michael Jackson mike.jackson at bluequartz.net
Wed Dec 13 08:27:16 EST 2017


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] mike.jackson at bluequartz.net

[w] www.bluequartz.net

 

From: CMake <cmake-bounces at cmake.org> on behalf of Petr Kmoch <petr.kmoch at gmail.com>
Date: Wednesday, December 13, 2017 at 3:03 AM
To: Saad Khattak <saadrustam at gmail.com>
Cc: CMake Mail List <cmake at cmake.org>
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 <saadrustam at gmail.com> 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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20171213/2a511776/attachment-0001.html>


More information about the CMake mailing list