Skip to content

Commit

Permalink
Added installer scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
JJPPeters committed Dec 10, 2022
1 parent fad1b41 commit 7c57a68
Show file tree
Hide file tree
Showing 9 changed files with 929 additions and 0 deletions.
1 change: 1 addition & 0 deletions scripts/create_installer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
temp/*
14 changes: 14 additions & 0 deletions scripts/create_installer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Create Installer

## About
These scripts are intended to make the actual Strain++ installer. I do not pretend that this is a good way to do it, it is just what I cobbled together.

The core of the scripts is using InnoSetup, with the rest just copying around files.

## Usage

The main (and only) script is `make_installer.py`. This handles everything.

To adapt to different computers, there are several file paths at the top of the script that should be set. Different versions of various libraries may also require modifying the dependency lists - it is all very manual.

There is some finesse for using the automatic GitHub version number, as the release must be created before the build.
52 changes: 52 additions & 0 deletions scripts/create_installer/inno_installer_script.iss
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

[Setup]
; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{E451AF69-2A8F-459B-86A3-DCFC4EDBD660}
AppName=Strain++
AppVersion=;version_string;
ArchitecturesAllowed=x64
DisableWelcomePage=no
AppPublisher=PetersSoft
DefaultDirName={pf64}\Strain++
DefaultGroupName=Strain++
AllowNoIcons=yes
OutputDir=Installer_exe\
OutputBaseFilename=Install_Strain++
SetupIconFile=installer_files\Strainppico.ico
Compression=lzma
SolidCompression=yes
WizardSmallImageFile="installer_files\image_small.bmp"
WizardImageFile="installer_files\image.bmp"
LicenseFile="installer_files\license.txt"

[Registry]
Root: HKCU; Subkey: "SOFTWARE\PetersSoft"; Flags: uninsdeletekeyifempty
Root: HKCU; Subkey: "SOFTWARE\PetersSoft\Strain++"; Flags: uninsdeletekey

[Messages]
SetupAppTitle = Setup {#SetupSetting("AppName")}
SetupWindowTitle = Setup - {#SetupSetting("AppName")} {#SetupSetting("AppVersion")}

[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"

[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked

[InstallDelete]
Type: filesandordirs; Name: "{app}\*"

[Files]
Source: "dist_files\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
; NOTE: Don't use "Flags: ignoreversion" on any shared system files

[Icons]
Name: "{group}\Strain++"; Filename: "{app}\strainpp.exe"
Name: "{commondesktop}\Strain++"; Filename: "{app}\strainpp.exe"; Tasks: desktopicon

[Run]
Filename: "{app}\strainpp.exe"; Description: "{cm:LaunchProgram,Strain++}"; Flags: nowait postinstall skipifsilent
Binary file not shown.
Binary file not shown.
Binary file not shown.
674 changes: 674 additions & 0 deletions scripts/create_installer/installer_files/license.txt

Large diffs are not rendered by default.

185 changes: 185 additions & 0 deletions scripts/create_installer/make_installer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
import shutil, os, re, subprocess

mingw_path = r'D:\Programming\packages\msys64\mingw64'

build_path = r'D:\Work\strainpp-dev\Strainpp-git\cmake-build-release'

inno_exe = r'C:\Program Files (x86)\Inno Setup 6\ISCC.exe'

this_path = os.path.dirname(os.path.abspath(__file__))

# WARNING: this folder will get deleted, so don't set it to anything important
temp_path = os.path.join(this_path, 'temp')

def copy_dist_files():

dist_path = os.path.join(temp_path, 'dist_files') # this is the path of this file

os.makedirs(dist_path, exist_ok=True)

bin_path = os.path.join(mingw_path, "bin")
bin_deps = ['zlib1',
'Qt5Widgets',
'Qt5Svg',
'Qt5PrintSupport',
'Qt5Gui',
'Qt5Core',
'libwinpthread-1',
'libturbojpeg',
'libtiffxx-5',
'libtiff-5',
'libstdc++-6',
'libpng16-16',
'libpcre16-0',
'libpcre2-16-0',
'liblzma-5',
'libjpeg-8',
'libintl-8',
'libicuuc67',
'libicuin67',
'libicudt67',
'libiconv-2',
'libharfbuzz-0',
'libgomp-1',
'libgobject-2.0-0',
'libglib-2.0-0',
'libgcc_s_seh-1',
'libfreetype-6',
'libfftw3-3',
'libffi-7',
'libbz2-1',
'libgraphite2',
'libpcre-1',
'libdouble-conversion',
'libzstd',
'libbrotlidec',
'libbrotlicommon']

formats_path = os.path.join(mingw_path, r"share\qt5\plugins\imageformats")
formats_deps = ['qtiff']

styles_path = os.path.join(mingw_path, r"share\qt5\plugins\styles")
styles_deps = ['qwindowsvistastyle']

platform_path = os.path.join(mingw_path, r"share\qt5\plugins\platforms")
platform_deps = ['qminimal',
'qwindows']

other_deps = [r'D:\Programming\libraries\qcustomplot\2.0.1\lib\qcustomplot2.dll',
os.path.join(build_path, r'strainpp.exe')]

for dep in bin_deps:
try:
shutil.copy(os.path.join(bin_path, dep+'.dll'), dist_path)
except IOError as e:
print('Error: ' + os.path.join(bin_path, dep+'.dll') + ', ' + e.strerror)

for dep in formats_deps:
pth = os.path.join(dist_path, 'imageformats')
os.makedirs(pth, exist_ok=True)

try:
shutil.copy(os.path.join(formats_path, dep+'.dll'), pth)
except IOError as e:
print('Error: ' + dep + '.dll, ' + e.strerror)

for dep in styles_deps:
pth = os.path.join(dist_path, 'styles')
os.makedirs(pth, exist_ok=True)

try:
shutil.copy(os.path.join(styles_path, dep+'.dll'), pth)
except IOError as e:
print('Error: ' + dep + '.dll, ' + e.strerror)

for dep in platform_deps:
pth = os.path.join(dist_path, 'platforms')
os.makedirs(pth, exist_ok=True)

try:
shutil.copy(os.path.join(platform_path, dep+'.dll'), pth)
except IOError as e:
print('Error: ' + dep + '.dll, ' + e.strerror)

for dep in other_deps:
try:
shutil.copy(dep, dist_path)
except IOError as e:
print('Error: ' + dep + e.strerror)


def get_versions():
version_file = os.path.join(build_path, r'src\version.cpp')

version = ""
branch = ""
revision = ""

with open(version_file, 'r') as file:
for line in file:
mtch = re.findall(r'["]([\w\s]+)["]', line)

if not mtch:
continue

if "GIT_REV" in line:
revision = mtch[0]
elif "GIT_TAG" in line:
version = mtch[0]
elif "GIT_BRANCH" in line:
branch = mtch[0]

return version, branch, revision


def make_version_string():
version, branch, revision = get_versions()

if version:
return version
else:
return branch + "." + revision


def make_installer_script():
in_script_name = "inno_installer_script.iss"
in_script_path = os.path.join(this_path, in_script_name)

out_script_name = "strainpp.iss"
out_script_path = os.path.join(temp_path, out_script_name)

version_string = make_version_string()

with open(in_script_path, 'r') as in_file:
file_text = in_file.read()

file_text = file_text.replace(";version_string;", version_string)

with open(out_script_path, 'w') as out_file:
out_file.write(file_text)

return out_script_path

def make_installer():
if os.path.exists(temp_path):
shutil.rmtree(temp_path)

# copy dependencies
copy_dist_files()

# copy installer files to temp folder
src_path = os.path.join(this_path, "installer_files")
dst_path = os.path.join(temp_path, "installer_files")

shutil.copytree(src_path, dst_path)

# make script with correct version
script_path = make_installer_script()

# run the script
process = subprocess.run([inno_exe, script_path],
stdout=subprocess.PIPE,
universal_newlines=True)

if __name__ == "__main__":
make_installer()
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ ADD_CUSTOM_COMMAND(
${CMAKE_CURRENT_BINARY_DIR}/_version.cpp
COMMAND ${CMAKE_COMMAND} -P
${CMAKE_CURRENT_SOURCE_DIR}/version.cmake)

# this is important as it will be used by the installer scripts
configure_file(version.cpp version.cpp COPYONLY)
#

FIND_PACKAGE( OpenMP REQUIRED )
Expand Down

0 comments on commit 7c57a68

Please sign in to comment.