MantisBT - CMake
View Issue Details
0015897CMakeCMakepublic2016-01-01 10:102016-06-10 14:21
Paul "TBBle" Hampson 
Brad King 
normalminoralways
closedfixed 
Mingw64/msys2Windows10
CMake 3.4.1 
CMake 3.5CMake 3.5 
0015897: Clang CXX feature detection disabled on WIN32 platforms
When using clang from mingw64 under msys, the supplied repro case fails with:

CMake Error at CMakeLists.txt:12 (target_compile_features):
  target_compile_features no known features for CXX compiler

  "Clang"

  version 3.7.0.

This is because when Clang C++ feature detection support was added in https://cmake.org/gitweb?p=cmake.git;a=commit;h=cda233194f9caab8867b2451f3d859080a233d45 [^] (specifically Modules/Compiler/Clang-CXX.cmake, although Modules/Compiler/Clang-C.cmake has the same conditions) the following was done:
* The condition to bail out detecting a -std= flag for clang was expanded to also cover WIN32 (This breaks the CXX_STANDARD property) - line 9
* If not UNIX, no compiler features are recorded (This breaks target_compile_features) - line 52

It's not clear why these conditions were used, perhaps there's some interaction with clang-cl (Clang emulating MSVC)?

If that was the case, then the first condition should be changed to test that, as done earlier in the file, rather than blocking all WIN32-based clang compilers.
Given CMakeLists.txt:
cmake_minimum_required(VERSION 3.4.1 FATAL_ERROR)

project(test1 CXX)

# Globally C++11
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

file(WRITE test1.cpp "int main(int argc, char** argv) {auto x=argc; return x;}")

add_executable(test1 test1.cpp)
target_compile_features(test1 PRIVATE cxx_auto_type)

Running the following in the MINGW64 environment of msys2 works:
CXX=g++ cmake .. -G"MSYS Makefiles" && cmake --build .
but the following fails to generate:
CXX=clang++ cmake .. -G"MSYS Makefiles" && cmake --build .

If the target_compile_features directive is removed, then both generate, but the latter will fail to build, noting that 'auto' is a C++11 feature.

Test based on https://cmake.org/pipermail/cmake/2015-January/059593.html [^]
I tested that removing the WIN32 and UNIX parts of the conditionals I mentioned got MSYS working, but I don't happen to have clang-cl installed to verify that it wasn't broken by doing this.
No tags attached.
related to 0015443closed Brad King Unable to use target_compile_features with MinGW-w64 
related to 0015943closed Kitware Robot CMAKE_CXX_STANDARD not working on non-apple clang++ 
Issue History
2016-01-01 10:10Paul "TBBle" HampsonNew Issue
2016-01-07 15:05Brad KingRelationship addedrelated to 0015443
2016-01-07 15:08Brad KingNote Added: 0040147
2016-01-10 23:35Paul "TBBle" HampsonNote Added: 0040174
2016-01-11 10:19Brad KingNote Added: 0040182
2016-01-11 10:20Brad KingAssigned To => Brad King
2016-01-11 10:20Brad KingStatusnew => resolved
2016-01-11 10:20Brad KingResolutionopen => fixed
2016-01-11 10:20Brad KingFixed in Version => CMake 3.5
2016-01-11 10:20Brad KingTarget Version => CMake 3.5
2016-01-29 13:27Brad KingRelationship addedrelated to 0015943
2016-06-10 14:21Kitware RobotNote Added: 0041272
2016-06-10 14:21Kitware RobotStatusresolved => closed

Notes
(0040147)
Brad King   
2016-01-07 15:08   
IIRC the only reason the condition was added is that the original author was not able to test on MinGW Clang (or GNU) at the time, and we have no nightly testing for MinGW Clang.

This case for Clang appears to be the same case for GNU that was reported in 0015443 and fixed by:

 Record compile features for GNU on Windows
 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=f94727a9 [^]

Does a patch of that form work here too?
(0040174)
Paul "TBBle" Hampson   
2016-01-10 23:35   
That's the same as part of what I did local to fix it, removing UNIX from line 52. However, it's not complete as the WIN32 check on line 9 causes the file to early-out before it hits that point.

Note that I tested my fix on msys2 mingw64's clang but not Cygwin or any other platform's clang. Specifically, I didn't test with clang-cl. I believe my fix is correct though.

If my fix isn't clear in my description, I can see about producing a diff, but it's:
 Remove "WIN32 OR" from line 9
 Remove "UNIX AND" from line 52
(0040182)
Brad King   
2016-01-11 10:19   
Thanks. This should fix it for MinGW Clang:

 Record compile features for MinGW Clang on Windows
 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=3baca636 [^]

Hopefully someone with clang-cl will be able to help out with that version.
(0041272)
Kitware Robot   
2016-06-10 14:21   
This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.