jamescookmd
25th November 2006 00:00 UTC
Detect NSIS compiler version, branch?
I need to write a NSIS script that supports both NSIS 2.04 and 2.21. Between these two version the lzma compressor changed to not default to "solid". The older version does not support the /solid flag.
Is there a way I can do something like:
!ifdef NSIS_204
SetCompressor lzma
!else
SetCompressor /solid lzma
!endif
Thanks,
James
bholliger
25th November 2006 02:17 UTC
Hi jamescookmd!
The constant NSIS_VERSION holds the version of the compiler. I think the best way is using a second file and include the output.
NSIS >= 2.07 SetCompressor /SOLID lzma
NSIS < 2.07 SetCompressor lzma
Try this:
nsiscompressionmaximiser.nsi (save in the same directory):
; include header files
!include LogicLib.nsh
!include WordFunc.nsh
!insertmacro VersionCompare
OutFile "nsiscompressionmaximiser.exe"
Function .onInit
StrCpy $R0 ${NSIS_VERSION} "" 1 ; usual output is "vX.YZ"
${VersionCompare} $R0 "2.07" $R1
; equal or higher, use solid compression
${If} $R1 == 0
${OrIf} $R1 == 1
StrCpy $R3 "SetCompressor /SOLID lzma"
${Else}
StrCpy $R3 "SetCompressor lzma"
${EndIf}
; Write output to file and include
FileOpen $R0 "$EXEDIR\maxcompression.nsh" w
FileWrite $R0 "$R3$\r$\n"
FileClose $R0
Quit
FunctionEnd
Section
SectionEnd
Put this in your script:
!system "${NSISDIR}\makensis.exe nsiscompressionmaximiser.nsi"
!system "nsiscompressionmaximiser.exe"
!include "maxcompression.nsh"
edit: Make sure the header files are in the installation of 2.04 as well.
Have fun!
Cheers
Bruno
bholliger
25th November 2006 02:41 UTC
Hi James!
What a great feeling to improve yourself.
Here is a shorter version:
; whatever NSIS version is used, use solid compression
; Works for NSIS > 2.01
!define COMPRESSOR_${NSIS_VERSION}
!ifdef COMPRESSOR_v2.01 | COMPRESSOR_v2.02 | COMPRESSOR_v2.03 | COMPRESSOR_v2.04 | COMPRESSOR_v2.05 | COMPRESSOR_v2.06
SetCompressor lzma
!else
SetCompressor /SOLID lzma
!endif
!undef COMPRESSOR_${NSIS_VERSION}
:
:
Have fun.
Cheers
Bruno
jamescookmd
25th November 2006 06:09 UTC
Thanks! I tried the latter example and it works well for me.
James