Skip to content

Commit f002a94

Browse files
committed
Added option to also write the non windows licenses to the license artifacts folder.
1 parent 8edcb6c commit f002a94

File tree

9 files changed

+139
-41
lines changed

9 files changed

+139
-41
lines changed

src/CommandLineInfo.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ void CommandLineInfo::ParseParam(const wchar_t* pszParam, BOOL bFlag, BOOL bLast
4242
_options->includeIncompatibleLicense=TRUE;
4343
else if (_wcsicmp(pszParam, L"includeOptional") == 0)
4444
_options->includeOptional=TRUE;
45+
else if (_wcsicmp(pszParam, L"includeNonWindows") == 0)
46+
_options->includeNonWindows=TRUE;
4547
else if (_wcsicmp(pszParam, L"installedSupport") == 0)
4648
_options->installedSupport=TRUE;
4749
else if (_wcsicmp(pszParam, L"noDpc") == 0)

src/Configure.vcxproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
<ItemGroup>
127127
<ClCompile Include="Config.cpp" />
128128
<ClCompile Include="Configs.cpp" />
129+
<ClCompile Include="Licence.cpp" />
129130
<ClCompile Include="Main.cpp" />
130131
<ClCompile Include="Options.cpp" />
131132
<ClCompile Include="InstallerConfig.cpp" />
@@ -173,6 +174,7 @@
173174
<ItemGroup>
174175
<ClInclude Include="Config.h" />
175176
<ClInclude Include="Configs.h" />
177+
<ClInclude Include="License.h" />
176178
<ClInclude Include="Options.h" />
177179
<ClInclude Include="InstallerConfig.h" />
178180
<ClInclude Include="MagickBaseConfig.h" />
@@ -202,4 +204,4 @@
202204
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
203205
<ImportGroup Label="ExtensionTargets">
204206
</ImportGroup>
205-
</Project>
207+
</Project>

src/Configure.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
<ClCompile Include="Notice.cpp" />
2929
<ClCompile Include="InstallerConfig.cpp" />
3030
<ClCompile Include="WaitDialog.cpp" />
31+
<ClCompile Include="Main.cpp" />
32+
<ClCompile Include="Licence.cpp" />
3133
</ItemGroup>
3234
<ItemGroup>
3335
<ClInclude Include="CommandLineInfo.h" />
@@ -59,6 +61,7 @@
5961
<ClInclude Include="Notice.h" />
6062
<ClInclude Include="InstallerConfig.h" />
6163
<ClInclude Include="WaitDialog.h" />
64+
<ClInclude Include="License.h" />
6265
</ItemGroup>
6366
<ItemGroup>
6467
<ResourceCompile Include="Configure.rc" />

src/ConfigureApp.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "ConfigureWizard.h"
2424
#include "CommandLineInfo.h"
2525
#include "InstallerConfig.h"
26+
#include "License.h"
2627
#include "MagickBaseConfig.h"
2728
#include "Notice.h"
2829
#include "Options.h"
@@ -109,7 +110,7 @@ void ConfigureApp::copyFiles(const wstring &sourceDirectory,const wstring &targe
109110

110111
BOOL ConfigureApp::createFiles(Options &options,WaitDialog &waitDialog) const
111112
{
112-
waitDialog.setSteps(15);
113+
waitDialog.setSteps(16);
113114

114115
waitDialog.nextStep(L"Cleaning up directories...");
115116
cleanupDirectories(options,waitDialog);
@@ -134,6 +135,12 @@ BOOL ConfigureApp::createFiles(Options &options,WaitDialog &waitDialog) const
134135
waitDialog.nextStep(L"Writing solution files...");
135136
Solution::write(options,projects);
136137

138+
if (options.includeNonWindows)
139+
{
140+
waitDialog.nextStep(L"Writing non windows licenses...");
141+
License::writeNonWindowsLicenses(options);
142+
}
143+
137144
if (versionInfo)
138145
writeImageMagickFiles(options,*versionInfo,waitDialog);
139146

src/Licence.cpp

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3+
% %
4+
% Copyright @ 1999 ImageMagick Studio LLC, a non-profit organization %
5+
% dedicated to making software imaging solutions freely available. %
6+
% %
7+
% You may not use this file except in compliance with the License. You may %
8+
% obtain a copy of the License at %
9+
% %
10+
% http://www.imagemagick.org/script/license.php %
11+
% %
12+
% Unless required by applicable law or agreed to in writing, software %
13+
% distributed under the License is distributed on an "AS IS" BASIS, %
14+
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
15+
% See the License for the specific language governing permissions and %
16+
% limitations under the License. %
17+
% %
18+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19+
*/
20+
21+
#include "License.h"
22+
23+
void License::write(const Options &options,const Config &config,const wstring name)
24+
{
25+
const auto targetDirectory=options.rootDirectory + L"Artifacts\\license\\";
26+
filesystem::create_directories(targetDirectory);
27+
28+
wofstream licenseFile(targetDirectory + name + L".txt");
29+
for (const auto& license : config.licenses())
30+
{
31+
const auto sourceFileName=options.rootDirectory + config.directory() + license;
32+
wifstream sourceLicenseFile(sourceFileName);
33+
if (!sourceLicenseFile)
34+
throwException(L"Failed to open license file: " + sourceFileName);
35+
36+
auto versionFileName=options.rootDirectory + config.directory() + L".ImageMagick\\ImageMagick.version.h";
37+
auto projectName=name;
38+
if (!filesystem::exists(versionFileName))
39+
{
40+
const auto configDirectory=sourceFileName.substr(0,sourceFileName.find_last_of(L"\\"));
41+
versionFileName=configDirectory + L"\\.ImageMagick\\ImageMagick.version.h";
42+
projectName=configDirectory.substr(configDirectory.find_last_of(L"\\") + 1);
43+
}
44+
45+
wifstream versionFile(versionFileName);
46+
if (versionFile)
47+
{
48+
wstring
49+
line;
50+
51+
getline(versionFile,line);
52+
getline(versionFile,line);
53+
if (!startsWith(line,L"#define DELEGATE_VERSION_STRING "))
54+
throwException(L"Invalid version file: " + versionFileName);
55+
line=line.substr(33,line.length() - 34);
56+
licenseFile << L"[ " << projectName << L" " << line << L" ]" << endl << endl;
57+
}
58+
else
59+
{
60+
licenseFile << L"[ " << projectName << L" ]" << endl << endl;
61+
}
62+
licenseFile << sourceLicenseFile.rdbuf() << endl;
63+
}
64+
}
65+
66+
void License::writeNonWindowsLicenses(const Options &options)
67+
{
68+
auto directory=L"Dependencies\\NonWindowsDependencies\\";
69+
if (!filesystem::exists(options.rootDirectory + directory))
70+
directory=L"NonWindowsDependencies\\";
71+
72+
if (!filesystem::exists(options.rootDirectory + directory))
73+
return;
74+
75+
for (const auto& entry : filesystem::directory_iterator(options.rootDirectory + directory))
76+
{
77+
if (!entry.is_directory())
78+
continue;
79+
80+
auto name=entry.path().filename().wstring();
81+
auto projectDirectory=directory + name + L"\\";
82+
auto configFile=options.rootDirectory + projectDirectory + L".ImageMagick\\Config.txt";
83+
auto config=Config::load(name,projectDirectory,configFile);
84+
85+
License::write(options,config,name);
86+
}
87+
}

src/License.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3+
% %
4+
% Copyright @ 1999 ImageMagick Studio LLC, a non-profit organization %
5+
% dedicated to making software imaging solutions freely available. %
6+
% %
7+
% You may not use this file except in compliance with the License. You may %
8+
% obtain a copy of the License at %
9+
% %
10+
% http://www.imagemagick.org/script/license.php %
11+
% %
12+
% Unless required by applicable law or agreed to in writing, software %
13+
% distributed under the License is distributed on an "AS IS" BASIS, %
14+
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
15+
% See the License for the specific language governing permissions and %
16+
% limitations under the License. %
17+
% %
18+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19+
*/
20+
#pragma once
21+
#include "stdafx.h"
22+
23+
#include "Config.h"
24+
#include "Options.h"
25+
26+
class License
27+
{
28+
public:
29+
static void write(const Options &options,const Config &config,const wstring name);
30+
31+
static void writeNonWindowsLicenses(const Options &options);
32+
};

src/Options.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Options::Options(const wstring &rootDirectory)
1919
includeIncompatibleLicense=FALSE;
2020
includeOptional=FALSE;
2121
#endif
22+
includeNonWindows=FALSE;
2223
installedSupport=FALSE;
2324
isImageMagick7=TRUE;
2425
isStaticBuild=FALSE;

src/Options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class Options
2929
BOOL enableDpc;
3030
BOOL excludeDeprecated;
3131
BOOL includeIncompatibleLicense;
32+
BOOL includeNonWindows;
3233
BOOL includeOptional;
3334
BOOL installedSupport;
3435
BOOL isStaticBuild;

src/Project.cpp

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1919
*/
2020
#include "Project.h"
21+
#include "License.h"
2122

2223
Project::Project(const Config &config,const Options &options)
2324
: _config(config),
@@ -594,45 +595,7 @@ void Project::writeLicense() const
594595
if (_config.licenses().empty())
595596
return;
596597

597-
const auto targetDirectory=_options.rootDirectory + L"Artifacts\\license\\";
598-
filesystem::create_directories(targetDirectory);
599-
600-
wofstream licenseFile(targetDirectory + name() + L".txt");
601-
for (const auto& license : _config.licenses())
602-
{
603-
const auto sourceFileName=_options.rootDirectory + _config.directory() + license;
604-
wifstream sourceLicenseFile(sourceFileName);
605-
if (!sourceLicenseFile)
606-
throwException(L"Failed to open license file: " + sourceFileName);
607-
608-
auto versionFileName=_options.rootDirectory + _config.directory() + L".ImageMagick\\ImageMagick.version.h";
609-
auto projectName=name();
610-
if (!filesystem::exists(versionFileName))
611-
{
612-
const auto configDirectory=sourceFileName.substr(0,sourceFileName.find_last_of(L"\\"));
613-
versionFileName=configDirectory + L"\\.ImageMagick\\ImageMagick.version.h";
614-
projectName=configDirectory.substr(configDirectory.find_last_of(L"\\") + 1);
615-
}
616-
617-
wifstream versionFile(versionFileName);
618-
if (versionFile)
619-
{
620-
wstring
621-
line;
622-
623-
getline(versionFile,line);
624-
getline(versionFile,line);
625-
if (!startsWith(line,L"#define DELEGATE_VERSION_STRING "))
626-
throwException(L"Invalid version file: " + versionFileName);
627-
line=line.substr(33,line.length() - 34);
628-
licenseFile << L"[ " << projectName << L" " << line << L" ]" << endl << endl;
629-
}
630-
else
631-
{
632-
licenseFile << L"[ " << projectName << L" ]" << endl << endl;
633-
}
634-
licenseFile << sourceLicenseFile.rdbuf() << endl;
635-
}
598+
License::write(_options,_config,name());
636599
}
637600

638601
void Project::writeLinkProperties(wofstream& file) const

0 commit comments

Comments
 (0)