gretty
22nd August 2013 04:26 UTC
Include Page only if Macros are Defined
Hello
In NSIS is there a Pre-Processor directive called 'defined'? I am attempting to include a specific page in my installer only if a macro/s are defined.
!define INSTALL_V8 1
!define INSTALL_V10 1
#if we are installing to more than 1 version of 12d Model: Show 'Version Selector' Page
!if defined(INSTALL_V8) && defined(INSTALL_V9) || defined(INSTALL_V8) && defined(INSTALL_V10) || defined(INSTALL_V9) && defined(INSTALL_V10)
Page Custom CustomPageInitialise CustomPageFinalise
!endif
The above code gives a compile error saying:
!if expects 1-4 parameters, got 11
Do you know how I could check if multiple macros are defined?
Anders
22nd August 2013 06:05 UTC
NSIS is not C compatible, use !ifdef foo | bar
gretty
22nd August 2013 06:12 UTC
Thanks for the reply :)
demiller9
22nd August 2013 13:36 UTC
A macro to count the defines would simplify the test
!define INSTALL_V8
!define INSTALL_V9
...
!define count 0
# call the macro for every possible def value
${CountDefs} count INSTALL_V8
${CountDefs} count INSTALL_V9
${CountDefs} count INSTALL_V10
!if ${count} > 1
Page Custom ...
!endif
Here's the macro to do that
!macro CountDefs Counter DefName
!ifdef ${DefName}
!define tmpval ${${Counter}}
!undef ${Counter}
!define /math ${Counter} ${tmpval} + 1
!undef tmpval
!endif
!macroend
!define CountDefs "!insertmacro CountDefs"
gretty
23rd August 2013 00:51 UTC
Thanks for the code example :D Much appreciated.
Some people when you ask if its possible to do something in programming its always littered with, cant or not possible. Whereas some people like yourself see the outcome that is desired and come up with a way to achieve it within the parameters of the language. I vehemently believe there is no such a thing as not possible in programming. I often wonder how the former people are able to get employed. I like to think I am firmly in the latter category.
Thanks again.