Skip to content
⌘ NSIS Forum Archive

Can we do compound tests for conditional compilation?

3 posts

Mike C#

Can we do compound tests for conditional compilation?

Our software can be installed with different installation types, for different user types. We achieve this by building a different installer for each installation type. We specify the installation type as a compile-time symbol, defined using the /D command-line option to the NSIS compiler, e.g.

makensis /DINSTALL_CONFIG="TYPE1" installer.nsi
Within the code, we use !if statements to resolve the conditionally compiled parts, e.g.

!if ${INSTALL_CONFIG} == "TYPE1"
MessageBox MB_OK "This is a Type 1 installation"
!elseif ${INSTALL_CONFIG} == "TYPE2"
MessageBox MB_OK "This is a Type 2 installation"
; And so on, for other types
!endif
This worked fine when we had only a small number of types, but - as is the way of things - the number has grown. We'd really like to be able to check for various different values of the compile-time constant, i.e. if ${INSTALL_CONFIG} is "TYPE1", or ${INSTALL_CONFIG} is "TYPE2", or ${INSTALL_CONFIG} is "TYPE3" then do this, else do that.

The documentation for !else mentions || and && operators, but provides no examples. I've been unable to find a way to use the || operator to do this in a way that compiles, and the error message suggests that I can only use them with values, rather than expressions.

Is it possible to this, or am I going to have to kludge it?
Anders#
!ifdef supports | and & but !if does not, it is not a full C preprocessor.

If the type string does not contain spaces you can do this:

!define INSTALL_CONFIG_${INSTALL_CONFIG}
!ifdef INSTALL_CONFIG_TYPE1 | INSTALL_CONFIG_TYPE2
The other option is to do some of this at run-time with the LogicLib, then you can use ${Switch} or ${Select}.
Mike C#
Originally Posted by Anders View Post
!ifdef supports | and & but !if does not, it is not a full C preprocessor.

If the type string does not contain spaces you can do this:



The other option is to do some of this at run-time with the LogicLib, then you can use ${Switch} or ${Select}.
Interesting - thanks very much!