<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Fri, Nov 2, 2018 at 3:25 AM Federico Kircheis <<a href="mailto:federico.kircheis@gmail.com">federico.kircheis@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">As described on <a href="https://github.com/Kitware/CMake/" rel="noreferrer" target="_blank">https://github.com/Kitware/CMake/</a> I'm writing here to <br>
check if the current behavior of cmake is really a bug.<br>
<br>
I'm having following issues with toolchains files.<br>
<br>
Here is my use case:<br>
I have a `toolchain.gcc.cmake` and a `toolchain.clang.cmake` toolchain <br>
files.<br>
Those files define variables for the gcc and clang compiler, and some <br>
settings (location of libraries, version numbers and so on) are common <br>
to both, and I would like to have a common `toolchain.cmake` toolchain <br>
file for that.<br>
<br>
If I write (uncomment on of the includes)<br>
<br>
-----<br>
# toolchain.gcc.cmake<br>
<br>
#include(common_settings.cmake)<br>
#include(./common_settings.cmake)<br>
#include(${CMAKE_CURRENT_SOURCE_DIR}/common_settings.cmake)<br>
#include(${CMAKE_SOURCE_DIR}/common_settings.cmake)<br>
#include(${CMAKE_HOME_DIRECTORY}/common_settings.cmake)<br>
<br>
set(CMAKE_C_COMPILER gcc)<br>
----<br>
<br>
and execute (an empty CMakeLists.txt in the current directory is sufficient)<br>
<br>
----<br>
rm -rf build; mkdir build && (cd build && cmake <br>
-DCMAKE_TOOLCHAIN_FILE=../toolchain.gcc.cmake ..);<br>
----<br>
<br>
then cmake complains:<br>
----<br>
   include could not find load file:<br>
<br>
<br>
/home/user/Workspace/toolchain/build/CMakeFiles/CMakeTmp/common_settings.cmake<br>
Call Stack (most recent call first):<br>
<br>
/home/user/Workspace/toolchain/build/CMakeFiles/3.12.3/CMakeSystem.cmake:6 <br>
(include)<br>
<br>
/home/user/Workspace/toolchain/build/CMakeFiles/CMakeTmp/CMakeLists.txt:2 <br>
(project)<br>
<br>
<br>
CMake Error at /usr/share/cmake-3.12/Modules/CMakeTestCCompiler.cmake:37 <br>
(try_compile):<br>
   Failed to configure test project build system.<br>
Call Stack (most recent call first):<br>
   CMakeLists.txt:3 (project)<br>
----<br>
<br>
As far as I've understood, cmake runs some internal test where, for <br>
example, `CMAKE_CURRENT_SOURCE_DIR` would not be the source directory of <br>
my code, and therefore <br>
`include(${CMAKE_CURRENT_SOURCE_DIR}/common_settings.cmake)` obviously <br>
fails.<br>
Same holds for other variables.<br>
<br>
<br>
The problem is that there is no way to set a path relative to the <br>
toolchain file, at least I was not able to find any.<br>
<br>
The only possible fix is setting an absolute path, but this is not <br>
really a solution since it makes the toolchain not portable.<br>
<br>
Is there anything else I could try?<br>
Is there already an open issue? I was not able to find any on <br>
<a href="https://gitlab.kitware.com/cmake/cmake/issues/" rel="noreferrer" target="_blank">https://gitlab.kitware.com/cmake/cmake/issues/</a>.<br></blockquote><div><br></div><div>You should be able to use CMAKE_CURRENT_LIST_DIR to specify a location relative to the toolchain file itself.</div><div> </div></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr">Craig Scott<br><div>Melbourne, Australia</div><div><a href="https://crascit.com" target="_blank">https://crascit.com</a><br></div><div><br></div><div>New book released: <a href="https://crascit.com/professional-cmake/" target="_blank">Professional CMake: A Practical Guide</a><br></div></div></div></div></div></div></div></div>