MantisBT - CMake
View Issue Details
0015943CMakeCMakepublic2016-01-29 12:242016-06-10 14:31
senz 
Kitware Robot 
highmajoralways
closedmoved 
MACOSX10.11.3
CMake 3.4.3 
 
0015943: CMAKE_CXX_STANDARD not working on non-apple clang++
cmake does not set standard related flags on non-apple clang++ ignoring CMAKE_CXX_STANDARD var or/and CXX_STANDARD propery.
# brew install llvm --with-clang --with-libcxx --with-rtti
# export PATH=/usr/local/opt/llvm/bin:$PATH
# export CXX=/usr/local/opt/llvm/bin/clang++
# export CC=/usr/local/opt/llvm/bin/clang

cmake project with
set (CMAKE_CXX_STANDARD 14)
set (CMAKE_CXX_STANDARD_REQUIRED ON)

# make VERBOSE=1
no -std=c++14 flag
No tags attached.
related to 0015897closed Brad King Clang CXX feature detection disabled on WIN32 platforms 
related to 0015544closed Kitware Robot Policy to require cmake_minimum_required() before project() 
Issue History
2016-01-29 12:24senzNew Issue
2016-01-29 13:26Brad KingNote Added: 0040364
2016-01-29 13:27Brad KingRelationship addedrelated to 0015897
2016-01-29 13:28senzNote Added: 0040365
2016-01-29 13:34senzNote Edited: 0040365bug_revision_view_page.php?bugnote_id=40365#r2021
2016-01-29 13:36Brad KingNote Added: 0040366
2016-01-29 14:03senzNote Added: 0040371
2016-01-29 14:06senzNote Added: 0040372
2016-01-29 14:11Brad KingNote Added: 0040374
2016-01-29 14:16senzNote Added: 0040375
2016-01-30 01:49Stephen KellyNote Added: 0040380
2016-02-01 08:46Brad KingRelationship addedrelated to 0015544
2016-06-10 14:29Kitware RobotNote Added: 0042928
2016-06-10 14:29Kitware RobotStatusnew => resolved
2016-06-10 14:29Kitware RobotResolutionopen => moved
2016-06-10 14:29Kitware RobotAssigned To => Kitware Robot
2016-06-10 14:31Kitware RobotStatusresolved => closed

Notes
(0040364)
Brad King   
2016-01-29 13:26   
This may be due to the code here:

 https://cmake.org/gitweb?p=cmake.git;a=blob;f=Modules/Compiler/Clang-CXX.cmake;hb=v3.4.3#l8 [^]
 cmake_policy(GET CMP0025 appleClangPolicy)
 if(WIN32 OR (APPLE AND NOT appleClangPolicy STREQUAL NEW))
   return()
 endif()

Check that the top-level CMakeLists.txt file starts with

 cmake_minimum_required(VERSION 3.0) # or higher

before the project() command.
(0040365)
senz   
2016-01-29 13:28   
(edited on: 2016-01-29 13:34)
First line is cmake_minimum_required(VERSION 3.4) - no effect

(0040366)
Brad King   
2016-01-29 13:36   
$ export PATH=/usr/local/opt/llvm/bin:$PATH
$ export CXX=/usr/local/opt/llvm/bin/clang++
$ export CC=/usr/local/opt/llvm/bin/clang
$ cmake --version
cmake version 3.4.1
$ cat ../CMakeLists.txt
cmake_minimum_required(VERSION 3.3)
project(Issue15943)
set(CMAKE_CXX_STANDARD 14)
add_executable(foo foo.cxx)
$ cmake ..
-- The C compiler identification is Clang 3.6.2
-- The CXX compiler identification is Clang 3.6.2
-- Check for working C compiler: /usr/local/opt/llvm/bin/clang
-- Check for working C compiler: /usr/local/opt/llvm/bin/clang -- works
...
-- Check for working CXX compiler: /usr/local/opt/llvm/bin/clang++
-- Check for working CXX compiler: /usr/local/opt/llvm/bin/clang++ -- works
...
$ make VERBOSE=1 | grep std=
/usr/local/opt/llvm/bin/clang++ ... -std=gnu++14 ...
(0040371)
senz   
2016-01-29 14:03   
Found the difference.
In faulty file project() command was never called, but it was set with set( PROJECT foo )
If calling project() flags are fine on both clangs. That is a very strange behavior
(0040372)
senz   
2016-01-29 14:06   
cmake_minimum_required(VERSION 3.4)
#project(Issue15943)
set (PROJECT Issue15943)
set(CMAKE_CXX_STANDARD 14)
set (CMAKE_CXX_STANDARD_REQUIRED ON)

add_executable(foo foo.cxx)
(0040374)
Brad King   
2016-01-29 14:11   
The project() command is required and is inserted on line 0 if not present:

 https://cmake.org/cmake/help/v3.4/command/project.html [^]
 "The top-level CMakeLists.txt file for a project must contain a literal,
  direct call to the project() command; loading one through the include()
  command is not sufficient. If no such call exists CMake will implicitly
  add one to the top that enables the default languages (C and CXX)."

The implied call was originally meant to make hello-world projects shorter (e.g. just add_executable). Since it is inserted on line 0 that is before the cmake_minimum_required(VERSION) call sets CMP0025 to NEW so the code mentioned in 0015943:0040364 triggers. The reason is that without CMP0025 we don't know whether the Clang version number corresponds to upstream or Apple's fork.
(0040375)
senz   
2016-01-29 14:16   
Tricky, thanks. Mb emit warning about implicit insert? At least in verbose mode
(0040380)
Stephen Kelly   
2016-01-30 01:49   
If cmake_minimum_required() is required before project(), then users can't have this bug. http://public.kitware.com/Bug/view.php?id=15544 [^]
(0042928)
Kitware Robot   
2016-06-10 14:29   
Resolving issue as `moved`.

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.