MantisBT - CMake
View Issue Details
0014923CMakeModulespublic2014-05-21 05:242015-01-05 08:39
skvadrik 
 
normalminoralways
closedfixed 
amd64Gentoo Linux3.14.1
CMake 2.8.12.2 
CMake 3.1CMake 3.1 
0014923: check_cxx_compiler_flag fails when variable name contains "++"
The following call:

check_cxx_compiler_flag(-Weffc++ CXX_FLAG_-Weffc++)

Leads to the following error:

RegularExpression::compile(): Nested *?+.
RegularExpression::compile(): Error in compile.
CMake Error at /usr/share/cmake/Modules/CheckCXXSourceCompiles.cmake:30 (if):
  if given arguments:

    "LJS_CXX_FLAG_-Weffc++" "MATCHES" "^LJS_CXX_FLAG_-Weffc++\$"

  Regular expression "^LJS_CXX_FLAG_-Weffc++$" cannot compile
check_cxx_compiler_flag(-Weffc++ CXX_FLAG_-Weffc++)
check_cxx_compiler_flag calls check_cxx_source_compiles. The latter tries to
interpret variable name as a regexp:

if("${VAR}" MATCHES "^${VAR}$")

which leads to an error for a variable name "CXX_FALG_-Weffc++" (and many other
variable names, which are generally accepted by cmake)
No tags attached.
Issue History
2014-05-21 05:24skvadrikNew Issue
2014-07-31 04:48Rolf Eike BeerNote Added: 0036512
2014-07-31 05:33skvadrikNote Added: 0036515
2014-07-31 05:51Rolf Eike BeerNote Added: 0036517
2014-07-31 08:39Brad KingNote Added: 0036520
2014-07-31 08:47skvadrikNote Added: 0036522
2014-07-31 08:57skvadrikNote Added: 0036526
2014-07-31 10:10Brad KingNote Added: 0036536
2014-07-31 10:16skvadrikNote Added: 0036537
2014-07-31 10:26Brad KingStatusnew => resolved
2014-07-31 10:26Brad KingResolutionopen => fixed
2014-07-31 10:26Brad KingFixed in Version => CMake 3.1
2014-07-31 10:26Brad KingTarget Version => CMake 3.1
2015-01-05 08:39Robert MaynardNote Added: 0037603
2015-01-05 08:39Robert MaynardStatusresolved => closed

Notes
(0036512)
Rolf Eike Beer   
2014-07-31 04:48   
Can't this just be "if (NOT VAR)"?
(0036515)
skvadrik   
2014-07-31 05:33   
Maybe it can, it's in the source code of cmake module CheckCXXSourceCompiles
(not in my source).

I just meant that the following call:
    check_cxx_compiler_flag(-Weffc++ CXX_FLAG_-Weffc++)
shouldn't cause errors, because CXX_FLAG_-Weffc++ is a valid identifier.

So the bug is in CheckCXXSourceCompiles, not in cmake (see bug's category).
(0036517)
Rolf Eike Beer   
2014-07-31 05:51   
Yes, absolutely. The question was more in the direction of Brad ;)
(0036520)
Brad King   
2014-07-31 08:39   
Re 0014923:0036512: That logic is an ancient hack from before we had if(DEFINED). Try this patch:

diff --git a/Modules/CheckCXXSourceCompiles.cmake b/Modules/CheckCXXSourceCompiles.cmake
index 6ce64a1..edd62a6 100644
--- a/Modules/CheckCXXSourceCompiles.cmake
+++ b/Modules/CheckCXXSourceCompiles.cmake
@@ -39,7 +39,7 @@
 
 
 macro(CHECK_CXX_SOURCE_COMPILES SOURCE VAR)
- if("${VAR}" MATCHES "^${VAR}$")
+ if(NOT DEFINED "${VAR}")
     set(_FAIL_REGEX)
     set(_key)
     foreach(arg ${ARGN})
(0036522)
skvadrik   
2014-07-31 08:47   
It works, thank you!
Is this patch in HEAD already?
(0036526)
skvadrik   
2014-07-31 08:57   
By the way, other modules have this error too:
   33:CheckFunctionExists.cmake 30:CheckCSourceRuns.cmake 45:CheckSymbolExists.cmake 30:CheckCXXSourceCompiles.cmake 32:CheckIncludeFile.cmake 30:CheckCXXSourceRuns.cmake 29:CheckIncludeFiles.cmake 30:CheckCSourceCompiles.cmake 32:CheckIncludeFileCXX.cmake 32:CheckVariableExists.cmake 32:CheckLibraryExists.cmake 282:ExternalData.cmake

I searched for regexp 'if\("\$\{.*\}" MATCHES "\^\$\{.*\}\$"\)' in /usr/share/cmake/Modules.
(0036536)
Brad King   
2014-07-31 10:10   
Re 0014923:0036526: Thanks. I've fixed it in all the modules:

 Check*: Allow result variables to contain regex special characters (0014923)
 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=4f2fcce4 [^]
(0036537)
skvadrik   
2014-07-31 10:16   
Thank you!
(0037603)
Robert Maynard   
2015-01-05 08:39   
Closing resolved issues that have not been updated in more than 4 months