5

For the reasons irrelevant to mention I would like to be able to include multiple files into toolchain file. Let's say my toolchain contains following:

message(STATUS "file1 is ok")
include(./build/file2)

the file2 contains identification line:

message(STATUS "file2 is ok")

the CMakeLists.txt contains:

cmake_minimum_required (VERSION 2.8.8)
project (pro)
message(STATUS "cmakelists.txt is ok")

I call it using following command:

cmake -DCMAKE_TOOLCHAIN_FILE=../../build/file1 ../../

Now, I would expect the following output:

-- file1 is ok
-- file2 is ok
-- cmakelists.txt is ok

Yet I get this:

-- file1 is ok
-- file2 is ok
-- file1 is ok
-- file2 is ok
-- The C compiler identification is Clang 5.0.0
-- The CXX compiler identification is Clang 5.0.0
-- Check for working C compiler: /usr/bin/cc
CMake Error at /fullpath/build/file1:2 (include):
  include could not find load file:
    ./build/file2
Call Stack (most recent call first):
  /fullpath/build/Mac/CMakeFiles/2.8.12/CMakeSystem.cmake:6 (include)
  CMakeLists.txt:2 (PROJECT)
CMake Error: Internal CMake error, TryCompile configure of cmake failed
-- Check for working C compiler: /usr/bin/cc -- broken
CMake Error at /Applications/CMake 2.8-12.app/Contents/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake:61 (message):
  The C compiler "/usr/bin/cc" is not able to compile a simple test program.
  It fails with the following output:
  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:2 (project)
-- Configuring incomplete, errors occurred!

Not only does CMake print the information twice, it also claim it cannot find included files at third time after that.

Any ideas?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
etwas77
  • 514
  • 1
  • 6
  • 17
  • 1
    It's even worse than that. Try changing STATUS to VERBOSE. For me the toolchain.cmake runs 12 times, and my issue is that only the first 2 times -DVAR=VAL variables are set. The following 10 times they are not set. Yet even worse than that, if I actually try to set toolchain paths, I get an infinite loop. Can someone please explain what's happening? – PizzaBeer Jun 26 '20 at 21:38

1 Answers1

2

Not only cmake prints the information twice

It's normal: during configuration, several steps are performed. On every step the toolchain file used.

it also claims it cannot find included files at a third time after that. Any ideas?

Provide an absolute path.

thiagowfx
  • 4,832
  • 6
  • 37
  • 51
  • 1
    I did just that and found out, that third time the cmake is using "fullpath/build/target/CMakeFiles/CMakeTmp/" directory, instead of intended "fullpath". of course it cannot find files.. – etwas77 Nov 11 '13 at 08:07
  • ^^^ This is exactly what I'm experiencing since I do use absolute paths. Version 3.16 and 3.24 both. – natersoz Dec 30 '22 at 23:21
  • [CMAKE_CURRENT_LIST_DIR](https://cmake.org/cmake/help/latest/variable/CMAKE_CURRENT_LIST_DIR.html) may be of help – Alex Che Apr 21 '23 at 17:29