View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0013796CMakeCMakepublic2012-12-14 08:552013-06-26 16:03
Reporterraspy 
Assigned ToAlex Neundorf 
PrioritynormalSeverityfeatureReproducibilityalways
StatusclosedResolutionfixed 
PlatformUnixOSLinuxOS VersionRHEL5
Product VersionCMake 2.8.10.2 
Target VersionCMake 2.8.12Fixed in VersionCMake 2.8.12 
Summary0013796: Toolchain files cannot see CMakeSystem variables like CMAKE_HOST_SYSTEM_NAME
DescriptionIn CMake 2.8.10 there was a change introduced: http://cmake.org/gitweb?p=cmake.git;a=commit;h=7195aca54f40778f41894c9e62649afe09e71d6c. [^] As a part of this change location of CMakeSystem.cmake generated file was changed (http://cmake.org/gitweb?p=cmake.git;a=blobdiff;f=Modules/CMakeDetermineSystem.cmake;h=cd33447560e12ac473d57ec5ad7784f7c5a1f861;hp=22c5016146bba896b8bbcb76458d420bd74c81b9;hb=7195aca54f40778f41894c9e62649afe09e71d6c;hpb=ec22a9b5217c2110db9af1791a61a7552144f028 [^])

When the project is configured, it runs CMakeDetermineSystem which creates CMakeSystem.cmake. We use CMAKE_TOOLCHAIN_FILE which is included by CMakeDetermineSystem and its path is also written in CMakeSystem.cmake. Then the compiler is tested; it is done by creating temporary CMake subproject to try to compile a sample file. Issue is: in that subproject CMAKE_TOOLCHAIN_FILE is not set, but it includes CMakeSystem.cmake. Our toolchain file includes CMakeDetermineSystem which in turn overwrites CMakeSystem.cmake WITHOUT toolchain file location. Therefore, when CMake is run next time it does not include toolchain file and compiler's include location is not known.

The issue was not previously observed because CMakeSystem.cmake created by temporary TryCompile subproject was created in temporary subproject's directory. Now it is the same location for main project and subprojects and is being overwritten.
Steps To ReproduceUse the following CMakeLists.txt:

SET(CMAKE_TOOLCHAIN_FILE toolchain.cmake)
PROJECT(test C CXX ASM)
ADD_LIBRARY(test foo.c)

toolchain.cmake:
INCLUDE_DIRECTORIES(include_dir)
IF(NOT CMAKE_HOST_SYSTEM_NAME)
    INCLUDE(CMakeDetermineSystem)
ENDIF(NOT CMAKE_HOST_SYSTEM_NAME)

1. Run CMake 2.8.10.2. Check CMakeFiles/2.8.10.2/CMakeSystem.cmake does not contain line including toolchain file.
2. Run make VERBOSE=1. Note that -Iinclude_dir is provided (because it was cached from CMakeDetermineSystem).
3. Run CMake 2.8.10.2 again. Note that compiler settings are read from cache and CMakeDetermineSystem is not called, but rather generated CMakeSystem.cmake is included. As it lacks toolchain file include, toolchain file is not included and INCLUDE_DIRECTORIES command is missing.
4. Run make VERBOSE=1 again. Note that -Iinclude_dir is now missing from compilation line.
Additional InformationThis particular change http://cmake.org/gitweb?p=cmake.git;a=blobdiff;f=Modules/CMakeDetermineSystem.cmake;h=cd33447560e12ac473d57ec5ad7784f7c5a1f861;hp=22c5016146bba896b8bbcb76458d420bd74c81b9;hb=7195aca54f40778f41894c9e62649afe09e71d6c;hpb=ec22a9b5217c2110db9af1791a61a7552144f028 [^] introduced regression.

CMake up to 2.8.9 works with such toolchain file correctly (because CMakeSystem.cmake is generated in CMakeFiles/ and CMakeFiles/CMakeTmp/CMakeFiles separately). After the change they both use the same file location and the file gets overwritten once compiler tests are run.

I would suggest to export CMAKE_TOOLCHAIN_FILE for test subprojects, so that at least CMakeDetermineSystem generates the same CMakeSystem.cmake file.
TagsNo tags attached.
Attached Files? file icon CMakeSystem.cmake.in [^] (537 bytes) 2013-04-10 15:15

 Relationships

  Notes
(0031891)
Brad King (manager)
2012-12-14 09:45

The full commit for the change referenced in the Additional Information is:

 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;hb=7195aca5 [^]
(0031892)
Brad King (manager)
2012-12-14 09:54

The CMakeDetermineSystem module is for internal use by CMake and not publicly documented. You should not be including it from the toolchain file. It's not clear what you're trying to achieve by doing so, but this is not the place to discuss it. Please ask for help on the mailing list instead:

 http://www.cmake.org/cgi-bin/mailman/listinfo/cmake [^]

Resolving as suspended for now.
(0031893)
raspy (reporter)
2012-12-14 10:56

CMakeDetermineSystem is required to set up correct paths for the compiler based on CMAKE_HOST_SYSTEM_NAME. This variable (documented) is not exported into test subprojects (since it goes through the IF condition to include CMakeDetermineSystem). So to be able to pass compiler checks toolchain file has to to select correct compiler based on the system type which is not exported from main CMake. That's why I include CMakeDetermineSystem.

Note also that it used to work. I used it since 2.8.3 and it now it fails on 2.8.10.2. The issue would not happen if test subproject would either a) include CMakeSystem.cmake generated by parent CMakeLists.txt or b) CMAKE_TOOLCHAIN_FILE was exported into test subproject's CMakeLists.txt. Currently it is a breaking change.
(0031895)
Brad King (manager)
2012-12-14 11:31

The commit that changed this behavior addressed very important problems that many users encountered even when using documented behavior. The fact that undocumented behavior accidentally worked in older versions is not a sufficient reason to support it.

If you were using undocumented behavior to work around a limitation of documented capabilities then that limitation should be addressed, but not necessarily by supporting the workaround. However, solution (a) in 0013796:0031893 is already the case. Consider:

$ cat ../CMakeLists.txt
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/toolchain.cmake)
cmake_minimum_required(VERSION 2.8)
project(Issue13796 C)
$ cat ../toolchain.cmake
message(WARNING "CMAKE_TOOLCHAIN_FILE=[${CMAKE_TOOLCHAIN_FILE}]")
$ cmake --version
cmake version 2.8.10.2
$ cmake ..
CMake Warning at toolchain.cmake:1 (message):
  CMAKE_TOOLCHAIN_FILE=[.../toolchain.cmake]
Call Stack (most recent call first):
  .../share/cmake-2.8/Modules/CMakeDetermineSystem.cmake:89 (include)
  CMakeLists.txt:3 (project)

CMake Warning at toolchain.cmake:1 (message):
  CMAKE_TOOLCHAIN_FILE=[.../toolchain.cmake]
Call Stack (most recent call first):
  b/CMakeFiles/2.8.10.2/CMakeSystem.cmake:1 (include)
  CMakeLists.txt:3 (project)

-- The C compiler identification is GNU 4.7.1
-- Check for working C compiler: /usr/bin/cc
CMake Warning at .../toolchain.cmake:1 (message):
  CMAKE_TOOLCHAIN_FILE=[]
Call Stack (most recent call first):
  .../b/CMakeFiles/2.8.10.2/CMakeSystem.cmake:1 (include)
  CMakeLists.txt:2 (PROJECT)

-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
CMake Warning at .../toolchain.cmake:1 (message):
  CMAKE_TOOLCHAIN_FILE=[]
Call Stack (most recent call first):
  .../b/CMakeFiles/2.8.10.2/CMakeSystem.cmake:1 (include)
  CMakeLists.txt:2 (PROJECT)

-- Detecting C compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: .../b


One can see that the CMakeSystem.cmake file from the parent *is* included inside the try_compile test project. It is also including the toolchain file.

I think your problem is that the toolchain file is included at the *top* of CMakeSystem.cmake so it does not see the values configured in that file.
(0031896)
raspy (reporter)
2012-12-14 11:39

You are correct. If the toolchain file was included last in CMakeSystem.cmake, there would be no need to call CMakeDetermineSystem as system variables would already be there. I agree that the change was important and I do not ask for reverting it, it just caused breakage at my deployment and I am wondering now how to resolve it. Would it be possible to include toolchain file at the bottom of the CMakeSystem.cmake?
(0031897)
Brad King (manager)
2012-12-14 11:43

Alex, was there a reason to include the toolchain file at the top of CMakeSystem instead of the bottom?
(0032101)
raspy (reporter)
2013-01-14 05:29

Hi,

Any update on this?
(0032102)
Brad King (manager)
2013-01-14 15:40

I think this is more involved than discussed earlier because CMakeDetermineSystem includes the toolchain file so that it can support toolchain files that *set* information about the host. Any fix to this will have to support both use cases.
(0032125)
raspy (reporter)
2013-01-21 08:40

I think that including toolchain file at the bottom solves it as well:

1) when CMakeDetermineSystem includes toolchain file and it sets information about the host, these information will be written to CMakeSystem.cmake (so it's contents is compliant with toolchain file)
2) if toolchain file sets information about the host, it will set it as well if included at the bottom of CMakeSystem.cmake (these should still be compliant with what was written into CMakeSystem.cmake by CMakeDetermineSystem).
(0032642)
raspy (reporter)
2013-03-15 12:20

Hi,

Three months now since reporting, what's the status? :-)
(0032799)
Alex Neundorf (developer)
2013-04-10 15:16

Does the attached CMakeSystem.cmake.in make it work for you (if you replace the one coming with CMake with it) ?
(0033074)
Brad King (manager)
2013-05-16 14:04

The patch from 0013796:0032799 has been applied:

 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=efb19b6d [^]
(0033391)
Alex Neundorf (developer)
2013-06-26 16:03

It will be in 2.8.12, so I'm closing it.

 Issue History
Date Modified Username Field Change
2012-12-14 08:55 raspy New Issue
2012-12-14 09:45 Brad King Note Added: 0031891
2012-12-14 09:54 Brad King Note Added: 0031892
2012-12-14 09:54 Brad King Status new => resolved
2012-12-14 09:54 Brad King Resolution open => suspended
2012-12-14 10:56 raspy Note Added: 0031893
2012-12-14 10:56 raspy Status resolved => feedback
2012-12-14 10:56 raspy Resolution suspended => reopened
2012-12-14 11:31 Brad King Note Added: 0031895
2012-12-14 11:39 raspy Note Added: 0031896
2012-12-14 11:39 raspy Status feedback => new
2012-12-14 11:43 Brad King Note Added: 0031897
2012-12-14 11:43 Brad King Assigned To => Alex Neundorf
2012-12-14 11:43 Brad King Severity major => feature
2012-12-14 11:43 Brad King Status new => assigned
2012-12-14 11:43 Brad King Resolution reopened => open
2012-12-14 11:43 Brad King Summary Regression: Toolchain file including CMakeDetermineSystem no longer works => Toolchain files cannot see CMakeSystem variables like CMAKE_HOST_SYSTEM_NAME
2013-01-14 05:29 raspy Note Added: 0032101
2013-01-14 15:40 Brad King Note Added: 0032102
2013-01-21 08:40 raspy Note Added: 0032125
2013-03-15 12:20 raspy Note Added: 0032642
2013-04-10 15:15 Alex Neundorf File Added: CMakeSystem.cmake.in
2013-04-10 15:16 Alex Neundorf Note Added: 0032799
2013-05-16 14:04 Brad King Note Added: 0033074
2013-05-16 14:04 Brad King Status assigned => resolved
2013-05-16 14:04 Brad King Resolution open => fixed
2013-05-16 14:04 Brad King Fixed in Version => CMake 2.8.12
2013-05-16 14:04 Brad King Target Version => CMake 2.8.12
2013-06-26 16:03 Alex Neundorf Note Added: 0033391
2013-06-26 16:03 Alex Neundorf Status resolved => closed


Copyright © 2000 - 2018 MantisBT Team