amalgamate
amalgamate

Reputation: 2310

Can I select an #include path using a script and command line args in an Inno Setup installer?

So the problem arises where I have a number of installations where most everything is the same except of course the files in the install. I have a suite of include files that are different.

So I thought, "Hey, lets simply add a command line argument to specify what file to include." I can get information from the command line argument in the Pascal code.

The problem comes when I try to use the information in the #include. The preprocessor seems to know nothing about the Pascal scripting. That makes sense, except that I want it to know. for example, I can't do this:

[Files]
#include "{code:GetMyArgument}"

or this:

[Files]
#include {param:foo|bar}

So the question is really: How can I set a #include to include a path file that I set in the command line arguments? or some other dynamic method... I can think of one. I just don't like my way: I don't like the idea of moving files around or changing file contents on the fly for this, my/this/these solutions smell, I think. Is there a better way?

I am on version 5.5.6(u) of Inno Setup.

Upvotes: 2

Views: 457

Answers (1)

Martin Prikryl
Martin Prikryl

Reputation: 202534

Just use a preprocessor variable:

#include IncludePath

And specify its value on compiler's command-line:

ISCC.exe Example1.iss /DIncludePath=Other.iss

Meaning of the /D switch:

/D<name>[=<value>] Emulate #define public <name> <value>

If you are using an Inno Setup IDE that does not support setting compiler's command-line arguments (like Inno Script Studio), you can base the included script's filename on some installer's option, like AppId, AppName, OutputBaseFilename, etc.

For example for a name based on the AppName, use:

#include SetupSetting("AppName") + ".iss"

Note that this works only if the #include directive, with the call to SetupSetting preprocessor function, is after the respective [Setup] section directive.


Yet another option is to reverse the include.

A main .iss is project-specific and it includes a shared .iss:

Project-specific .iss:

; Project-specific settings
[Setup]
AppId=id
AppName=name

[Files]  
; Project specific files

; Include shared script
#include "shared.iss"

Note that it's perfectly OK, if the sections repeat. So the shared.iss can include again both [Setup] and [Files] sections with other directives and files.

Upvotes: 1

Related Questions