include a file from the toolchain file

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

include a file from the toolchain file

Federico Kircheis
As described on https://github.com/Kitware/CMake/ I'm writing here to
check if the current behavior of cmake is really a bug.

I'm having following issues with toolchains files.

Here is my use case:
I have a `toolchain.gcc.cmake` and a `toolchain.clang.cmake` toolchain
files.
Those files define variables for the gcc and clang compiler, and some
settings (location of libraries, version numbers and so on) are common
to both, and I would like to have a common `toolchain.cmake` toolchain
file for that.

If I write (uncomment on of the includes)

-----
# toolchain.gcc.cmake

#include(common_settings.cmake)
#include(./common_settings.cmake)
#include(${CMAKE_CURRENT_SOURCE_DIR}/common_settings.cmake)
#include(${CMAKE_SOURCE_DIR}/common_settings.cmake)
#include(${CMAKE_HOME_DIRECTORY}/common_settings.cmake)

set(CMAKE_C_COMPILER gcc)
----

and execute (an empty CMakeLists.txt in the current directory is sufficient)

----
rm -rf build; mkdir build && (cd build && cmake
-DCMAKE_TOOLCHAIN_FILE=../toolchain.gcc.cmake ..);
----

then cmake complains:
----
   include could not find load file:

 
/home/user/Workspace/toolchain/build/CMakeFiles/CMakeTmp/common_settings.cmake
Call Stack (most recent call first):
 
/home/user/Workspace/toolchain/build/CMakeFiles/3.12.3/CMakeSystem.cmake:6
(include)
 
/home/user/Workspace/toolchain/build/CMakeFiles/CMakeTmp/CMakeLists.txt:2
(project)


CMake Error at /usr/share/cmake-3.12/Modules/CMakeTestCCompiler.cmake:37
(try_compile):
   Failed to configure test project build system.
Call Stack (most recent call first):
   CMakeLists.txt:3 (project)
----

As far as I've understood, cmake runs some internal test where, for
example, `CMAKE_CURRENT_SOURCE_DIR` would not be the source directory of
my code, and therefore
`include(${CMAKE_CURRENT_SOURCE_DIR}/common_settings.cmake)` obviously
fails.
Same holds for other variables.


The problem is that there is no way to set a path relative to the
toolchain file, at least I was not able to find any.

The only possible fix is setting an absolute path, but this is not
really a solution since it makes the toolchain not portable.

Is there anything else I could try?
Is there already an open issue? I was not able to find any on
https://gitlab.kitware.com/cmake/cmake/issues/.

Thank you in advance

Federico
--

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: include a file from the toolchain file

Craig Scott-3


On Fri, Nov 2, 2018 at 3:25 AM Federico Kircheis <[hidden email]> wrote:
As described on https://github.com/Kitware/CMake/ I'm writing here to
check if the current behavior of cmake is really a bug.

I'm having following issues with toolchains files.

Here is my use case:
I have a `toolchain.gcc.cmake` and a `toolchain.clang.cmake` toolchain
files.
Those files define variables for the gcc and clang compiler, and some
settings (location of libraries, version numbers and so on) are common
to both, and I would like to have a common `toolchain.cmake` toolchain
file for that.

If I write (uncomment on of the includes)

-----
# toolchain.gcc.cmake

#include(common_settings.cmake)
#include(./common_settings.cmake)
#include(${CMAKE_CURRENT_SOURCE_DIR}/common_settings.cmake)
#include(${CMAKE_SOURCE_DIR}/common_settings.cmake)
#include(${CMAKE_HOME_DIRECTORY}/common_settings.cmake)

set(CMAKE_C_COMPILER gcc)
----

and execute (an empty CMakeLists.txt in the current directory is sufficient)

----
rm -rf build; mkdir build && (cd build && cmake
-DCMAKE_TOOLCHAIN_FILE=../toolchain.gcc.cmake ..);
----

then cmake complains:
----
   include could not find load file:


/home/user/Workspace/toolchain/build/CMakeFiles/CMakeTmp/common_settings.cmake
Call Stack (most recent call first):

/home/user/Workspace/toolchain/build/CMakeFiles/3.12.3/CMakeSystem.cmake:6
(include)

/home/user/Workspace/toolchain/build/CMakeFiles/CMakeTmp/CMakeLists.txt:2
(project)


CMake Error at /usr/share/cmake-3.12/Modules/CMakeTestCCompiler.cmake:37
(try_compile):
   Failed to configure test project build system.
Call Stack (most recent call first):
   CMakeLists.txt:3 (project)
----

As far as I've understood, cmake runs some internal test where, for
example, `CMAKE_CURRENT_SOURCE_DIR` would not be the source directory of
my code, and therefore
`include(${CMAKE_CURRENT_SOURCE_DIR}/common_settings.cmake)` obviously
fails.
Same holds for other variables.


The problem is that there is no way to set a path relative to the
toolchain file, at least I was not able to find any.

The only possible fix is setting an absolute path, but this is not
really a solution since it makes the toolchain not portable.

Is there anything else I could try?
Is there already an open issue? I was not able to find any on
https://gitlab.kitware.com/cmake/cmake/issues/.

You should be able to use CMAKE_CURRENT_LIST_DIR to specify a location relative to the toolchain file itself.
 
--
Craig Scott
Melbourne, Australia


--

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: include a file from the toolchain file

Federico Kircheis


>You should be able to use CMAKE_CURRENT_LIST_DIR to specify a location
>relative to the toolchain file itself.


Thank you, it worked without an hiccup
--

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