Commit Graph

121 Commits

Author SHA1 Message Date
Stephen Kelly d6a03b475e cmIfCommand: Issue CMP0054 warning with appropriate context. (#15802)
Commit v3.4.0-rc1~494^2~4 (cmMakefile: Add API for elseif to create
backtrace., 2015-05-29) removed the use of cmMakefileCall to push/pop
execution context in favor of a new way to create backtraces.

However, a call to cmMakefile::GetExecutionContext is still invoked to
issue a contextual CMP0054 warning through cmConditionEvaluator.  As
the elseif is not part of the call stack, this resulted in trying to
access an empty vector.

Avoid the attempt at getting execution context when evaluating elseif by
constructing a context and backtrace on behalf of the cmConditionEvaluator
in all cases.
2015-10-20 23:40:12 +02:00
Stephen Kelly 59e21ffa13 Port static calls from cmLocalGenerator to cmOutputConverter. 2015-06-06 09:15:58 +02:00
Stephen Kelly b68f2ea8ae cmMakefile: Add API for elseif to create backtrace. 2015-06-03 01:03:58 +02:00
Stephen Kelly 9486769866 Don't use a cmLocalGenerator instance to call static methods. 2015-05-14 20:30:09 +02:00
Rolf Eike Beer 51f8de8102 if(): avoid one needless string compare for all if() statements
If it's known that it is an "if" it can't be an "elseif".
2015-02-22 13:48:30 +01:00
Stephen Kelly fd7b371293 Replace foo.size() pattern with !foo.empty(). 2015-01-18 14:25:24 +01:00
Stephen Kelly 930bd47816 Replace 'foo.size() == 0' pattern with foo.empty(). 2015-01-18 14:25:24 +01:00
Gregor Jasny 0de867dde2 continue: Add a new CMake language command for loop continuation (#14013)
Inspired-by: Doug Barbieri
Signed-off-by: Gregor Jasny <gjasny@googlemail.com>
2014-12-01 09:50:49 -05:00
Nils Gladitz 188a1f236e If: Introduce policy CMP0054 - don't dereference quoted variables in if() 2014-09-11 21:23:17 +02:00
Nils Gladitz b900c1ccaa If: Extract cmConditionEvaluator from if() implementation 2014-09-11 21:17:09 +02:00
Ben Boeckel f718b30a95 ClearMatches: Only clear matches which were actually set
ClearMatches was clearing many variables which were never set in the
first place. Instead, store how many matches were made last time and
only clear those. It is moved to the cmMakefile class since it is a
common utility used by multiple commands.
2014-04-29 16:00:05 -04:00
Stephen Kelly 21c573f682 Remove some c_str() calls.
Use the clang RemoveCStrCalls tool to automatically migrate the
code. This was only run on linux, so does not have any positive or
negative effect on other platforms.
2014-03-11 15:03:50 +01:00
Ben Boeckel 3742bb0d32 stringapi: Use strings for variable names
Variable names are always generated by CMake and should never be NULL.
2014-03-08 13:05:28 -05:00
Rolf Eike Beer c768e398f9 cmMakefile: make some methods take const std::string& instead of const char*
Most callers already have a std::string, on which they called c_str() to pass it
into these methods, which internally converted it back to std::string. Pass a
std::string directly to these methods now, avoiding all these conversions.
Those methods that only pass in a const char* will get the conversion to
std::string now only once.
2014-01-16 09:28:29 -05:00
Stephen Kelly 48bb48e114 De-duplicate version comparison code.
Extend the VersionCompare in cmSystemTools to handle 8 components,
and port the if command to use that.
2013-06-12 14:09:36 +02:00
Brad King dfa0ebd646 if: Compare up to 8 components in VERSION tests
Extend the number of components tested by

  if(... VERSION_LESS ...)
  if(... VERSION_EQUAL ...)
  if(... VERSION_GREATER ...)

from 4 to 8.  The latter is a more extreme maximum.
2012-09-11 15:59:16 -04:00
Brian Helba b3b095a933 Print any evaluated 'elseif'/'else' commands in trace mode (#13220)
In trace mode ('--trace'), any 'elseif' or 'else' commands that are
evaluated as part of a conditional block will be printed.  Previously,
only the opening 'if' command of a conditional block was printed.
2012-05-16 09:07:55 -04:00
Rolf Eike Beer 54fd9e38bb fix uninitialized var in if(NOT foo bar STREQUAL "foo bar")
Also adds test to verify this.
2012-01-22 12:15:57 +01:00
Brad King e0d0d5db0f Remove unreachable code in cmIfCommand
The commit "Fix if() command and CMP0012 OLD/NEW behavior" introduced an
unreachable 'break' after 'return' in a switch statement.  We remove it.
2009-10-28 08:45:46 -04:00
Brad King cb185d93d2 Fix if() command and CMP0012 OLD/NEW behavior
The commit "modified the if command to address bug 9123 some" changed
the if() command behavior with respect to named boolean constants.  It
introduced policy CMP0012 to provide compatibility.  However, it also
changed behavior with respect to numbers (like '2') but did not cover
the change with the policy.  Also, the behavior it created for numbers
is confusing ('2' is false).

This commit teaches if() to recognize numbers again, and treats them
like the C language does in terms of boolean conversion.  We also fix
the CMP0012 check to trigger in all cases where the result of boolean
coersion differs from that produced by CMake 2.6.4.
2009-10-27 09:07:39 -04:00
Brad King 9f43fa602d Report expanded arguments in if() command errors
The if() command reports its arguments at the beginning of some error
messages.  Originally it reported the un-expanded form of the arguments
because in ancient CMake versions no context information was available.
Now it is more useful to see the real arguments, which may be mentioned
in the main error message.  Since full context information is now
available, users can refer back to the source if they need to see the
unexpanded form of the arguments.

For example, the code

  set(regex "++")
  if("x" MATCHES "${regex}")
  endif()

now produces the message

  if given arguments:

    "x" "MATCHES" "++"

  Regular expression "++" cannot compile

instead of

  if given arguments

    "x" MATCHES "${regex}"

  Regular expression "++" cannot compile
2009-10-27 09:01:33 -04:00
Brad King 7a9f75c1a8 Add IS_SYMLINK test to if command 2009-10-21 13:11:16 -04:00
Brad King 3d3efbd3f5 Clarify documentation and message for CMP0012
This commit re-words the warning message produced for CMP0012 to avoid
the word 'you' since often the person reading the message is not the
author of the code.  We also add an example of the bad OLD behavior to
the policy documentation.
2009-10-02 14:36:47 -04:00
Brad King 96afb12087 Convert CMake to OSI-approved BSD License
This converts the CMake license to a pure 3-clause OSI-approved BSD
License.  We drop the previous license clause requiring modified
versions to be plainly marked.  We also update the CMake copyright to
cover the full development time range.
2009-09-28 11:43:28 -04:00
Brad King 3c856405e4 ENH: Improve format of if() command messages
Errors and warnings from the if() command always display the argument
list given to the command followed by an explanation of the problem.
This moves the argument list into a pre-formatted block and follows it
with a paragraph-form explanation.  The result looks cleaner.
2009-06-17 14:18:08 -04:00
Ken Martin f50cf4f60d ENH: warning fix 2009-06-12 11:10:26 -04:00
Ken Martin a73071ca17 ENH: modified the if command to address bug 9123 some 2009-06-12 10:07:05 -04:00
Brad King 1dcc5b4558 ENH: Better handling of mismatched blocks
If a logical block terminates with mismatching arguments we previously
failed to remove the function blocker but replayed the commands anyway,
which led to cases in which we failed to report the mismatch (return
shortly after the ending command).  The recent refactoring of function
blocker deletion changed this behavior to produce an error on the ending
line by not blocking the command.  Furthermore, the function blocker
would stay in place and complain at the end of every equal-level block
of the same type.

This teaches CMake to treat the begin/end commands (if/endif, etc.) as
correct and just warns when the arguments mismatch.  The change allows
cases in which CMake 2.6.2 silently ignored a mismatch to run as before
but with a warning.
2009-01-21 09:49:00 -05:00
Brad King bca1026250 ENH: Better error message for unclosed blocks
This centralizes construction of the error message for an unclosed
logical block (if, foreach, etc.).  We record the line at which each
block is opened so it can be reported in the error message.
2009-01-21 09:48:20 -05:00
Brad King 2c81e5fb5c ENH: Refactor function blocker deletion
When a function blocker decides to remove itself we previously removed
it at every return point from the C++ scope in which its removal is
needed.  This teaches function blockers to transfer ownership of
themselves from cmMakefile to an automatic variable for deletion on
return.  Since this removes blockers before they replay their commands,
we no longer need to avoid running blockers on their own commands.
2009-01-20 14:36:18 -05:00
Brad King a541cac325 ENH: Improve response to bad if or elseif
Previously bad arguments to an if() or elseif() would cause some
subsequent statements in the corresponding block to execute.  This
teaches CMake to stop processing commands with a fatal error.  It also
provides context to bad elseif() error messages.
2009-01-20 14:35:22 -05:00
Bill Hoffman ecf312ccc8 STYLE: fix line length stuff for KWStyle 2008-10-01 09:04:27 -04:00
Brad King 4fa96dbf95 ENH: Add version comparison to if() command
Provide VERSION_LESS, VERSION_EQUAL, and VERSION_GREATER operators in
the if() command.  This simplifies component-wise comparison of version
numbers in the form "major[.minor[.patch[.tweak]]]".
2008-09-10 11:58:40 -04:00
Brad King fff812db95 ENH: Add if(TARGET) command
It is useful to be able to test if a target has been created.  Often
targets are created only inside conditions.  Rather than storing the
result of the condition manually for testing by other parts of the
project, it is much easier for the other parts to just test for the
target's existence.  This will also be useful when find-modules start
reporting results with IMPORTED targets and projects want to test if a
certain target is available.
2008-08-20 11:45:16 -04:00
Ken Martin 52d8b1b5d9 BUG: fix memory leak and cleanup error string code 2008-06-28 11:16:36 -04:00
Ken Martin 19e891532a ENH: support parenthesis as arguments and in conditionals feature request #6191 2008-06-26 13:01:35 -04:00
Brad King a6a673979d ENH: Add "if(POLICY policy-id)" option for IF command.
- This will help projects support multiple CMake versions.
  - In order to set a policy when using a newer CMake but still
    working with an older CMake one may write
      if(POLICY CMP1234)
        cmake_policy(SET CMP1234 NEW)
      endif(POLICY CMP1234)
  - Note that since CMake 2.4 does not have if(POLICY) supporting
    it will also require using "if(COMMAND cmake_policy)"
2008-03-20 18:25:59 -04:00
Bill Hoffman f48a5cedc9 ENH: fix warnings 2008-02-29 21:33:33 -05:00
Bill Hoffman f386c2aae0 ENH: make CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS the default and remove the property. If any value is specified in an endif, endforeach, endwhile, etc then make sure it matches the start string. If no values are given then it is no longer an error. 2008-02-29 12:18:11 -05:00
Ken Martin 0e69d38004 ENH: add return and break support to cmake, also change basic command invocation signature to be able to return extra informaiton via the cmExecutionStatus class 2008-01-23 10:28:26 -05:00
Alexander Neundorf 69e9848fb4 BUG: this seems to fix the regexp result-storage problem, now it seems the actual result is tored instead of "1" , as it happened for StringFileTest on Windows
Alex
2007-08-29 14:35:06 -04:00
Alexander Neundorf e80acd971c ENH: also store the group matches from IF( MATCHES) in CMAKE_MATCH_(0..9)
Alex
2007-08-29 11:58:38 -04:00
Alexander Neundorf c9f1af3913 ENH: add IF(IS_ABSOLUTE path), so no regex matching is required in the cmake scripts
Alex
2007-06-06 08:49:18 -04:00
Brad King 9a5b4eba97 BUG: All variable accesses should produce watch callbacks, including IF(DEFINED <var>) ones. Instead we define a new access type for IF(DEFINED) so that the error does not show up for backward compatibility variables. 2007-05-17 17:40:59 -04:00
Brad King b8928b0c8e BUG: Do not complain about missing watched variables when they are accessd with IF(DEFINED VAR). 2007-05-17 15:12:13 -04:00
Ken Martin 372ce05a07 ENH: fix a warning and a nice fix to the IF command 2006-12-12 10:07:20 -05:00
Ken Martin 27379d7b08 ENH: make properties a bit more formal with documentation and chaining 2006-12-07 09:45:32 -05:00
Ken Martin d92f22023c ENH: remove old hack now that project level compatibility files are supported 2006-11-16 15:31:34 -05:00
Brad King b7e04e69ae BUG: It cannot be an error if the values do not convert. The docs say that if the values do not convert the test is false. 2006-10-25 10:57:26 -04:00
Brad King d563ab6677 BUG: For LESS, GREATER, and EQUAL check that the arguments can actually be converted to numbers. Also force the conversion results to be stored in memory to make sure they both use the same precision. This addresses bug#3966. 2006-10-25 10:31:26 -04:00