[CMake] Question about FOREACH

Dekeyser, Kris Kris.Dekeyser at lms.be
Wed May 25 03:09:16 EDT 2005


Hi,

Your FOREACH can work, but you first have to replace the \n chars with ; chars. To illustrate, here's an extract from a macro we use in our build system:

    #--- If config file found, process it
    SET(Configfile "${${ProjectName}_SOURCE_DIR}/adm/config.txt")
    SET(ConfigFileContents)
    
    IF(EXISTS ${Configfile})
      FILE(READ ${Configfile} ConfigFileContents)
    ENDIF(EXISTS ${Configfile})
    
    #--- parse config file
    IF(ConfigFileContents)
    
      #--- Remove newlines
      STRING(REGEX REPLACE "\n" ";" ConfigLines ${ConfigFileContents})
      
      #--- process line by line
      FOREACH(ConfigLine ${ConfigLines})

      [...]

      ENDFOREACH(ConfigLine)
      
    ENDIF(ConfigFileContents)

HTH,
Kris

> -----Original Message-----
> From: alaterale at elitemail.org [mailto:alaterale at elitemail.org]
> Sent: Tuesday, May 24, 2005 19:23
> To: cmake at cmake.org
> Subject: [CMake] Question about FOREACH
> 
> 
> Hi,
> I have a quick question about the FOREACH command.  I'm 
> basically trying
> to execute the "env" program and be able to parse specific environment
> variables into cmake variables.  So here's what I'm doing so far:
> 
> EXEC_PROGRAM("env > env.txt")
> FILE(READ "env.txt" ENVIRONMENT_VARIABLES)
> 
> Now, I need to be able to use FOREACH to iterate through the file
> contents based on some delimiter (preferably "/n" since 
> that's what the
> file is delimited on by default)
> 
> I have this so far but it doesn't work:
> FOREACH(VAR ENVIRONMENT_VARIABLES)
> 	MESSAGE(STATUS ${VAR})
> ENDFOREACH(VAR ENVIRONMENT_VARIABLES)
> 
> I guess all this would be unnecessary if there were a way to just
> retrieve real environment variables from the system, but I have not
> figured that out yet :P  So I guess if anyone knows how to get and set
> environment variables from cmake, that would help too.  Thanks!
> ~~J Strange
> _______________________________________________
> CMake mailing list
> CMake at cmake.org
> http://www.cmake.org/mailman/listinfo/cmake
> 
+-+-+- Email Confidentiality Footer +-+-+- 
Privileged/Confidential Information may be contained in this message. If you are not the addressee indicated in this message (or responsible for delivery of the message to such person), you may not print, retain, copy nor disseminate this message or any part of it to anyone and you should notify the sender by reply email and destroy this message. Neglecting this clause could be a breach of confidence. Please advise immediately if you or your employer does not consent to Internet email for messages of this kind. Opinions, conclusions and other information in this message that are not related to the official business of my firm shall be understood as neither given nor endorsed by it.


More information about the CMake mailing list