Archive: Conditional Compilation


Conditional Compilation
For some times i'm searching for a method to control the compile process, that for example compiling with an old version aborts the compile or changes a (few) line(s) because of limitations in the old versions.

I found the following in the RFE on Sourcefoge:


!define "ver_${NSIS_VERSION}"
!ifdef "ver_v2.05"
File /r /x .svn "${QUELLE_TC}\*.*"
!else
File /r "${QUELLE_TC}\*.*"
!endif


Unfortunatley this only works for a specific version. Is there a solution for any future versions? The sample above differs between pre 2.05 and 2.05 or higher. Perhaps something like the code below would be possible.



!ifdef "$NSIS_VERSION" >= "v2.05"
File /r /x .svn "${QUELLE_TC}\*.*"
!else
File /r "${QUELLE_TC}\*.*"
!endif


I don't want to change the code with every new nsis release.

Regards flizebogen

Do you know when NSIS_VERSION was introduced into NSIS?
I couldn't find it at all in the change log. If it was added recently, then you could do a straight !ifdef NSIS_VERSION, because older versions might not have it defined.

-Stu


Ok, so it seems NSIS_VERSION was added in v2.0, so this will work.

!define "CheckVer_${NSIS_VERSION}"
!ifdef "CheckVer_" | "CheckVer_v2.0" | "CheckVer_v2.01" | "CheckVer_v2.02" | "CheckVer_v2.03" | "CheckVer_v2.04"
File /r "${QUELLE_TC}\*.*"
!else
File /r /x .svn "${QUELLE_TC}\*.*"
!endif


-Stu

What a workaround. Not very pretty as the list increases with every new version for new commands. In my opinion the "!ifdef" command should have the posibility for value checks.


doing a >= on of ifdef doesn't really work with the whole idea of a ifdef i think since it's just there to see if the value is defined and not to do a conditional test. maybe you could create some sort of normal function and then do some string based checks on that which would set a variable/register value that you could then compare against. it's not great solution but it's an alternative work around.

-daz


The problem is that it has to be processed at compile-time and the list of compile-time commands isn't this big.

Maybe we need a complete new command life !if ? How about it?


Another workaround, but should do the trick nicely (unless you're compiling on < Win2k...)

!ifdef NSIS_VERSION
!system `(if /i "${NSIS_VERSION}" geq "v2.05" echo !define FILE_X_SUPPORTED) >"$%TEMP%\temp.nsh"`
!include $%TEMP%\temp.nsh
!system `del "$%TEMP%\temp.nsh"`
!endif

OutFile iftest.exe
Section
!ifdef FILE_X_SUPPORTED
MessageBox MB_OK "Yes"
!else
MessageBox MB_OK "No"
!endif
SectionEnd

Originally posted by eccles
[B]Another workaround, but should do the trick nicely (unless you're compiling on < Win2k...)
That solved my problem, too. Thanks.
I compile my script via batch file that asks the user which versionnumber to use.

As I find it better to check for a missing versionnumber in the script (instead of several batch files) I now use this:


!system `(if "${VERSION}" equ "" echo !define NO_VERSION) >"$%TEMP%\temp.nsh"`
!include $%TEMP%\temp.nsh
!system `del "$%TEMP%\temp.nsh"`

!ifdef NO_VERSION
!error "No version defined!"
!endif



I would appreciate it if there was a !if function that could check for empty strings. I guess this would be helpful for several other people.

Do you mean empty constants?

!define "Empty_${Define}"

!ifdef Empty_
!error "Define -> Empty"
!else
!echo "Define -> OK"
!end if


-Stu

Originally posted by Larsen
I would appreciate it if there was a !if function that could check for empty strings. I guess this would be helpful for several other people.
2.15 will have !if. You can check it out with the nightly build.

@Stu: Thanks for the workaround.

@kichik: That´s good news.