MantisBT - CMake
View Issue Details
0006251CMakeCMakepublic2008-01-16 16:142013-03-04 08:38
Andreas Pakulat 
Brad King 
normalfeaturealways
closedfixed 
 
CMake 2.8.10CMake 2.8.10 
0006251: Provide compiler version information
It would be cool if there was a CMAKE_CXX_COMPILER_VERSION variable available in cmake. Something like that is already available for MSVC, as there are separate MSVC80, MSVC71 and so on. Unfortunately there's nothing like that for other compilers, like gcc.

Often its useful to be able to check which version of a compiler is used, for example to enable some compiler flag - or in the case of boost libraries to be able to actually find the right libs.
No tags attached.
has duplicate 0011682closed Brad King [enhancement] Add GNU versions for CMakeLists.txt processing, just like MSVC_VERSION 
has duplicate 0011937closed Brad King Need determination of Intel C++ compiler version 
has duplicate 0012408closed Brad King CMake should have a variable for the compiler version 
Issue History
2008-01-16 16:14Andreas PakulatNew Issue
2008-01-17 15:17Bill HoffmanNote Added: 0010172
2008-01-17 15:17Bill HoffmanStatusnew => assigned
2008-01-17 15:17Bill HoffmanAssigned To => Brad King
2008-01-17 15:48Brad KingNote Added: 0010173
2008-01-17 16:42Andreas PakulatNote Added: 0010174
2011-01-11 08:41Brad KingRelationship addedhas duplicate 0011682
2011-01-11 10:33MaddesNote Added: 0024586
2011-01-11 10:39MaddesNote Added: 0024587
2011-01-11 10:42MaddesNote Edited: 0024586bug_revision_view_page.php?bugnote_id=24586#r92
2011-01-11 10:43MaddesNote Edited: 0024586bug_revision_view_page.php?bugnote_id=24586#r93
2011-01-11 10:43MaddesNote Edited: 0024586bug_revision_view_page.php?bugnote_id=24586#r94
2011-01-11 10:44MaddesNote Edited: 0024587bug_revision_view_page.php?bugnote_id=24587#r96
2011-01-11 10:45MaddesNote Edited: 0024587bug_revision_view_page.php?bugnote_id=24587#r97
2011-01-11 10:47MaddesNote Edited: 0024587bug_revision_view_page.php?bugnote_id=24587#r98
2011-01-11 10:48MaddesNote Edited: 0024587bug_revision_view_page.php?bugnote_id=24587#r99
2011-01-11 10:48MaddesNote Edited: 0024587bug_revision_view_page.php?bugnote_id=24587#r100
2011-01-11 10:54MaddesNote Edited: 0024586bug_revision_view_page.php?bugnote_id=24586#r101
2011-01-11 10:55MaddesNote Edited: 0024587bug_revision_view_page.php?bugnote_id=24587#r102
2011-01-11 10:59MaddesNote Edited: 0024587bug_revision_view_page.php?bugnote_id=24587#r103
2011-01-11 11:01MaddesNote Edited: 0024587bug_revision_view_page.php?bugnote_id=24587#r104
2011-01-11 11:02MaddesNote Edited: 0024587bug_revision_view_page.php?bugnote_id=24587#r105
2011-02-08 17:59MaddesNote Added: 0025347
2011-02-08 17:59MaddesNote Edited: 0025347bug_revision_view_page.php?bugnote_id=25347#r194
2011-02-08 18:00MaddesNote Edited: 0024587bug_revision_view_page.php?bugnote_id=24587#r195
2012-04-19 12:12David ColeNote Added: 0029256
2012-04-19 13:53Brad KingNote Added: 0029259
2012-04-19 13:53Brad KingAssigned ToBrad King =>
2012-04-19 13:53Brad KingStatusassigned => backlog
2012-04-19 13:55Brad KingRelationship addedhas duplicate 0011937
2012-04-19 13:57Brad KingRelationship addedhas duplicate 0012408
2012-09-03 17:01Rolf Eike BeerNote Added: 0030902
2012-09-03 17:24David ColeNote Added: 0030904
2012-09-03 17:24David ColeStatusbacklog => resolved
2012-09-03 17:24David ColeFixed in Version => CMake 2.8.10
2012-09-03 17:24David ColeResolutionopen => fixed
2012-09-03 17:24David ColeAssigned To => Brad King
2012-09-03 17:24David ColeTarget Version => CMake 2.8.10
2013-03-04 08:38Robert MaynardNote Added: 0032448
2013-03-04 08:38Robert MaynardStatusresolved => closed

Notes
(0010172)
Bill Hoffman   
2008-01-17 15:17   
Does the new compiler id stuff do this?
(0010173)
Brad King   
2008-01-17 15:48   
CMake HEAD in CVS has a CMAKE_<lang>_COMPILER_ID variable that gets set to the vendor name for known compilers. It does not contain the version. However the logic used to compute the ID can be extended to extract version information too.
(0010174)
Andreas Pakulat   
2008-01-17 16:42   
Boost uses <compiler><major><minor> mostly, i.e. msvc80, msvc71, gcc34, gcc42. But sometimes also has mgw, il (for mingw and intel compiler). So if CMAKE_<LANG>_COMPILER_ID can provide exactly that string it would be really helpful.
(0024586)
Maddes   
2011-01-11 10:33   
(edited on: 2011-01-11 10:54)
I think the approach mentioned in 0011682 of having multiple version variables has advantages over the approach here of having one generic string variable.

Having multiple specific variables allow for complex checks, also they are filled with version numbers only.
Using more generic variable names like CMAKE_<lang>_COMPILER_[MAJOR|MINOR|PATCHLEVEL] would make them re-useable for other compilers too.

A single string variable with text and numbers as mentioned here, maybe with different formats, can be very hard to parse.

(0024587)
Maddes   
2011-01-11 10:39   
(edited on: 2011-02-08 18:00)
The boost format is inaccurate and not great for conditions (<, <=, >, >=).
The MSVC compiler version has nothing to do with the Visual Studio release name. MSVC compiler come also with Windows SDK and other Microsoft products.
So for correct decisions the compiler version (e.g. 1310, 1400, etc.) has to be taken in account.

Also you can easily map the MSVC_VERSION to a boost compiler version yourself. See their visualc.hpp header file near the end (URL: http://www.boost.org/doc/libs/1_41_0/boost/config/compiler/visualc.hpp [^] )
Put the CMake mapping code in a separate text file and include it whenever necessary (see CMake's include at http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:include [^]).

(0025347)
Maddes   
2011-02-08 17:59   
Found an easy workaround for GNU C/CXX:

execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion
    OUTPUT_VARIABLE C_VERSION
    OUTPUT_STRIP_TRAILING_WHITESPACE)
message(STATUS "C version is >${C_VERSION}<" )

execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion
    OUTPUT_VARIABLE CXX_VERSION
    OUTPUT_STRIP_TRAILING_WHITESPACE)
message(STATUS "CXX version is >${CXX_VERSION}<" )

Now you can use VERSION_LESS/EQUAL/GREATER with C_VERSION and CXX_VERSION.

Maybe this can be implemented in CMake directly.

(0029256)
David Cole   
2012-04-19 12:12   
Is this issue "fixed" now that the feature is mostly there in 2.8.8... or are you keeping it open to remember to finish off the few IDE generators that are still missing this information?
(0029259)
Brad King   
2012-04-19 13:53   
CMake 2.8.8 defines variables like CMAKE_C_COMPILER_VERSION but they are documented for internal use only. They are needed to choose version-dependent compiler flags for a few toolchains. However, they are not provided for all toolchains by all generators.

Currently the version information is computed at the same time as the compiler identification. Some generators (VS, Xcode) do not perform the identification step because they generate project files specifying the build and let the native build tool map attributes to the real compiler command lines. For these generators the version information is not computed.

Additional work is needed to compute the compiler version everywhere. It should probably be done during the compiler ABI detection step (when not done during the id step) since it is similar to the id check but runs everywhere.
(0030902)
Rolf Eike Beer   
2012-09-03 17:01   
A lot of that stuff has happened for 2.8.9 and beyond that. Can we export the results as CMake variables now?
(0030904)
David Cole   
2012-09-03 17:24   
CMAKE_CXX_COMPILER_VERSION and CMAKE_C_COMPILER_VERSION are now available everywhere.

CMAKE_Fortran_COMPILER_VERSION is available where it is possible to determine it without knowing it in advance...
(0032448)
Robert Maynard   
2013-03-04 08:38   
Closing resolved issues that have not been updated in more than 4 months.