[CMake] Re: Weird if nesting problem

James Bigler bigler at cs.utah.edu
Wed Dec 6 12:19:21 EST 2006


  > Message: 1
> Date: Tue, 05 Dec 2006 20:28:36 -0800 (PST)
> From: "Alan W. Irwin" <irwin at beluga.phys.uvic.ca>
> Subject: Re: [CMake] Weird if nesting problem
> To: cmake <cmake at cmake.org>
> Message-ID: <Pine.LNX.4.60.0612052013060.31976 at puvpxnqrr.zlyna.ubzr>
> Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed
> 
> On 2006-12-05 20:05-0800 Brandon J. Van Every wrote:
> 
>> Alan W. Irwin wrote:
>>> On 2006-12-05 14:44-0700 James Bigler wrote:
>>>
>>>> CMake barfs on the first IF(EXISTS ${PARSER_EXECUTABLE}), probably 
>>>> because it is trying to evaluate if this expression is part of the ENDIF 
>>>> or something. It does this with 2.2.3, 2.4.3, 2.4.5 on Linux.
>>> Try IF(EXISTS ${PARSER_EXECUTABLE}) ==> IF(EXISTS PARSER_EXECUTABLE)
>> If that actually works, then the documentation is bugged.  PARSER_EXECUTABLE 
>> is a variable name, not a file or directory name.
> 
> Ugh.  I wrote too quickly. You are absolutely right, Brandon.  Thanks for
> that correction.
> 
> James, just ignore what I said.  We need more information before we can
> figure out why that IF statement is failing.
> 
> Time to do some deeper investigation such as printing out
> ${PARSER_EXECUTABLE}. That variable name sounds like it should contain an
> executable file, but does it?  The documentation of IF(EXISTS... warns
> "Behavior is well-defined only for full paths".  So I doubt if your logic
> will work properly if you are getting a *-NOTFOUND response to your
> FIND_PROGRAM command that determines PARSER_EXECUTABLE.  Perhaps you should
> surround everything with IF(PARSER_EXECUTABLE).... ENDIF(PARSER_EXECUTABLE)
> to make sure it is not a *-NOTFOUND result?
> 

If you look at the original code.  The PARSER_EXECUTABLE variable isn't 
defined until inside the first ELSE branch.

# You need at least version 2.4 for this to work.
IF("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" LESS 2.6)
   MESSAGE("You need at least version 2.4 for generating stuff.  Go get 
it from http://www.cmake.org/HTML/Download.html")
   SET(PARSERS_FOUND 0)

ELSE("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" LESS 2.6)

   FIND_PROGRAM(PARSER_EXECUTABLE
     NAMES my_parser
     PATHS ${PARSER_DIR} )

   IF(EXISTS ${PARSER_EXECUTABLE})
     SET(PARSERS_FOUND 1)
   ELSE(EXISTS ${PARSER_EXECUTABLE})
     SET(PARSERS_FOUND 0)
   ENDIF(EXISTS ${PARSER_EXECUTABLE})

ENDIF("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" LESS 2.6)

-----------------------------------------------------------

PARSER_EXECUTABLE doesn't exist until I'm in the ELSE block.  IF(EXISTS 
${PARSER_EXECUTABLE}) should *NEVER* get evaluated, but it does.

James


More information about the CMake mailing list