[cmake-developers] while(1) containing non-fatal errors is an infinite loop

Alan W. Irwin irwin at beluga.phys.uvic.ca
Fri Dec 6 13:47:58 EST 2013


On 2013-12-06 09:46-0500 Brad King wrote:

> On 12/05/2013 03:39 PM, Alan W. Irwin wrote:
>> But if you replace
>>
>> message(FATAL_ERROR "Should stop loop?") ==>
>> add_subdirectory(non_existent_directory)
>
> Okay, so the code in question is:
>
> while(1)
>   add_subdirectory(non_existent_directory)
>   message(STATUS "Did I make it by FATAL_ERROR?")
> endwhile(1)
>
>> in the above CMake logic you get an infinite loop despite the FATAL
>> error from the add_subdirectory command.
>
> A missing subdirectory is not a FATAL error.

Thanks for that clarification.  And I knew from the first that a
SEND_ERROR would not stop an infinite loop, but I was confused because error messages
for SEND_ERROR and FATAL_ERROR are of identical form, e.g.,

CMake Error at CMakeLists.txt:5 (message):

versus

CMake Error at CMakeLists.txt:5 (add_subdirectory):

in my two examples with the second one leading to an infinite loop. 
Please fix that ambiguity between FATAL_ERROR and SEND_ERROR somewhere in
the associated error messages, e.g.,

CMake FATAL_ERROR  at CMakeLists.txt:5 (message): 
CMake SEND_ERROR at CMakeLists.txt:5 (add_subdirectory):

To finish this up, my original complicated example (where I thought
message(FATAL_ERROR ....) was not stopping inside a subdirectory that
was added from an outer loop is now gone.  However, I tried to
reproduce that this morning with the following simple example:

project(test_loop_fatal_errors NONE)
cmake_minimum_required(VERSION 2.8.12.1 FATAL_ERROR)

foreach(i RANGE 10)
   file(MAKE_DIRECTORY ${CMAKE_SOURCE_DIR}/test${i})
     file(WRITE ${CMAKE_SOURCE_DIR}/test${i}/CMakeLists.txt "message(FATAL_ERROR \"Error${i}\")")
   add_subdirectory(test${i})
endforeach(i RANGE 10)

The result was

irwin at raven> cmake ..
CMake Error at test0/CMakeLists.txt:1 (message):
   Error0


-- Configuring incomplete, errors occurred!

So clearly the processing is being stopped by that FATAL_ERROR
generated from inside a subdirectory just as desired, and I was likely
just not remembering correctly exactly what happened with my more
complicated example or was confused by the ambiguous "CMake Error"
string that occurred.

In sum, please disambiguate the two kinds of error messages using my
suggestion above or something similar. That way, you will be able to
salvage a positive result from what turned out to be a mistaken report
on my part that was fueled by that ambiguity.

Alan
__________________________
Alan W. Irwin

Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).

Programming affiliations with the FreeEOS equation-of-state
implementation for stellar interiors (freeeos.sf.net); the Time
Ephemerides project (timeephem.sf.net); PLplot scientific plotting
software package (plplot.sf.net); the libLASi project
(unifont.org/lasi); the Loads of Linux Links project (loll.sf.net);
and the Linux Brochure Project (lbproject.sf.net).
__________________________

Linux-powered Science
__________________________



More information about the cmake-developers mailing list