View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0004249CMakeCMakepublic2006-12-30 00:062015-07-08 08:57
ReporterTodd Rovito 
Assigned ToBill Hoffman 
StatusclosedResolutionnot fixable 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0004249: Generate a warning when a undefined Cmake variable is used
DescriptionIf a CMakeLists.txt file contains the following:

    set(VARIABLE_NAME SomeFile.h SomeFile.cxx)

    add_executable(ProgramName SomeFileMain.cxx ${VARIABLE_NAME_UNDEFINED})

Endif (UNIX)

# end of CMakeLists.txt file

Cmake will not complain about VARIABLE_NAME_UNDEFINED being undefined it still tries to build the project. If possible I would like cmake to print a warning that it is using an undefined variable.
TagsNo tags attached.
Attached Filesdiff file icon undefined_variable_warnings.diff [^] (21,243 bytes) 2008-03-01 14:34 [Show Content]
txt file icon CMakeLists.txt [^] (429 bytes) 2008-03-01 14:35 [Show Content]

- Relationships Relation Graph ] Dependency Graph ]

-  Notes
Alex Neundorf (developer)
2007-01-02 12:24

That's similar to how all other scripting languages I know work.
Philip Lowman (developer)
2008-03-01 14:32

Here's a patch for implementing this (although it needs testing in Windows and on other platforms to squash any remaining internal CMake-generated warnings).

I modified cmCommandArgumentParserHelper.cxx so that when variables are expanded a warning is issued if the variable does not exist. This behavior can be overridden in two ways:

  1. The user may set CMAKE_ALLOW_UNKNOWN_VARIABLE_READ_ACCESS which will suppress all warnings (this variable would presumably be set by CMAKE_BACKWARDS_COMPATABILITY)

  2. The user may dereference variables with a special key (right now it's ALLOWUNDEF) to indicate that they are ok with the idea that the variable may be undefined and that no warning need be emitted.
     SET(foo $ALLOWUNDEF{bar})

There are several core CMake core modules that are designed to use variables that are often left undefined. An example is CMakeCommonLanguageInclude.cmake which optionally uses a lot of "_INIT" type variables to populate the cache. Instead of wrapping all of these cache assignments with annoying conditionals the $ALLOWUNDEF keyword was added here.

Assuming that this is a feature that is still desired, some work would remain:

1. Trying out initial CMake configuration on a variety of platforms, hunting down warnings and either fixing the code not to dereference undefined variables or adding the ALLOWUNDEF keyword.

2. Having a look at the standard CMake modules and either add checks for the existence of external variables before dereferencing them or add the ALLOWUNDEF keyword.


4. Add documentation on $ALLOWUNDEF{} somewhere
Stephen Kelly (developer)
2015-02-26 14:08

This isn't going to happen. Might as well close it.
Robert Maynard (manager)
2015-07-08 08:57

Closing resolved issues that have not been updated in more than 4 months.

- Issue History
Date Modified Username Field Change
2008-03-01 14:32 Philip Lowman Note Added: 0010678
2008-03-01 14:34 Philip Lowman File Added: undefined_variable_warnings.diff
2008-03-01 14:35 Philip Lowman File Added: CMakeLists.txt
2015-02-26 14:08 Stephen Kelly Note Added: 0038083
2015-02-26 14:08 Stephen Kelly Status assigned => resolved
2015-02-26 14:08 Stephen Kelly Resolution open => not fixable
2015-07-08 08:57 Robert Maynard Note Added: 0039072
2015-07-08 08:57 Robert Maynard Status resolved => closed

Copyright © 2000 - 2017 MantisBT Team
Powered by Mantis Bugtracker