Skip to content

Commit 02d2a93

Browse files
committed
Add missing CompileResources.py script
1 parent 3c52385 commit 02d2a93

File tree

2 files changed

+217
-23
lines changed

2 files changed

+217
-23
lines changed

CMakeLists.txt

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,38 +35,34 @@ function (SubDirList dirlist curdir)
3535
set (${dirlist} ${result} PARENT_SCOPE)
3636
endfunction ()
3737

38-
function (GetModuleNameFromModuleFolderName module folder)
39-
set (result "")
40-
if (${folder} MATCHES "^.*Lib$")
41-
string (REGEX REPLACE "^(.*)Lib$" "\\1" result ${folder})
42-
elseif (WIN32 AND ${folder} MATCHES "^Communication.*$")
43-
string (REGEX REPLACE "^Communication(.*)$" "Communication.\\1" result ${folder})
44-
else ()
45-
set (result ${folder})
46-
endif ()
47-
set (${module} ${result} PARENT_SCOPE)
38+
function (AddGSModuleToIncludeDirectories target folder)
39+
message (STATUS "Add ${folder} GS Module to include directories")
40+
target_include_directories (${target} PUBLIC "${AC_API_DEVKIT_DIR}/Support/Modules/${folder}")
4841
endfunction ()
4942

50-
function (AddGSModule target folder)
51-
message (STATUS "AddGSModule ${folder}")
52-
target_include_directories (${target} PUBLIC "${AC_API_DEVKIT_DIR}/Support/Modules/${folder}")
53-
set (module "")
54-
GetModuleNameFromModuleFolderName (module ${folder})
43+
function (AddGSModulesToLinkLibraries target folder)
5544
if (WIN32)
56-
set (ModuleLibPath "${AC_API_DEVKIT_DIR}/Support/Modules/${folder}/Win/${module}Imp.lib")
45+
file (GLOB LinkLibraries
46+
${AC_API_DEVKIT_DIR}/Support/Modules/${folder}/Win/*.lib
47+
)
5748
else ()
58-
set (ModuleLibPath "${AC_API_DEVKIT_DIR}/Support/Frameworks/${module}.framework")
59-
endif ()
60-
if (EXISTS ${ModuleLibPath})
61-
target_link_libraries (${target} ${ModuleLibPath})
49+
file (GLOB LinkLibraries
50+
${AC_API_DEVKIT_DIR}/Support/Frameworks/*.framework
51+
)
6252
endif ()
53+
foreach (linkLibrary ${LinkLibraries})
54+
get_filename_component (libraryName "${linkLibrary}" NAME)
55+
message (STATUS "Add ${libraryName} GS Module to link libraries")
56+
target_link_libraries (${target} ${linkLibrary})
57+
endforeach ()
6358
endfunction ()
6459

6560
set_property (GLOBAL PROPERTY USE_FOLDERS ON)
6661

6762
get_filename_component (CMAKE_CURRENT_FOLDER_NAME "${CMAKE_CURRENT_LIST_DIR}" NAME)
6863
set (CMAKE_SUPPRESS_REGENERATION 1)
6964
set (CMAKE_CONFIGURATION_TYPES Debug;Release;RelWithDebInfo)
65+
set (CMAKE_OSX_DEPLOYMENT_TARGET ___MACOSX_DEPLOYMENT_TARGET___)
7066
set (AC_API_DEVKIT_DIR "${CMAKE_CURRENT_LIST_DIR}/../.." CACHE PATH "API DevKit directory.")
7167
set (AC_ADDON_NAME "${CMAKE_CURRENT_FOLDER_NAME}" CACHE STRING "Add-On name.")
7268
set (AC_ADDON_LANGUAGE "INT" CACHE STRING "Add-On language code.")
@@ -105,7 +101,6 @@ if (WIN32)
105101
file (GLOB AddOnResourceFiles
106102
${AddOnResourcesFolder}/R${AC_ADDON_LANGUAGE}/*.grc
107103
${AddOnResourcesFolder}/RFIX/*.grc
108-
${AddOnResourcesFolder}/RFIX/*.grc
109104
${AddOnResourcesFolder}/RFIX.win/*.rc2
110105
)
111106
else ()
@@ -133,7 +128,7 @@ if (WIN32)
133128
DEPENDS ${AddOnResourceFiles} ${AddOnImageFiles}
134129
COMMENT "Compiling resources..."
135130
COMMAND ${CMAKE_COMMAND} -E make_directory "${ResourceObjectsDir}"
136-
COMMAND python "${APIDevKitToolsFolderAbsolute}/CompileResources.py" "${AC_ADDON_LANGUAGE}" "${AC_API_DEVKIT_DIR}" "${AddOnSourcesFolderAbsolute}" "${AddOnResourcesFolderAbsolute}" "${ResourceObjectsDir}" "${ResourceObjectsDir}/${AC_ADDON_NAME}.res"
131+
COMMAND python "${AddOnResourcesFolderAbsolute}/CompileResources.py" "${AC_ADDON_LANGUAGE}" "${AC_API_DEVKIT_DIR}" "${AddOnSourcesFolderAbsolute}" "${AddOnResourcesFolderAbsolute}" "${ResourceObjectsDir}" "${ResourceObjectsDir}/${AC_ADDON_NAME}.res"
137132
COMMAND ${CMAKE_COMMAND} -E touch "${ResourceObjectsDir}/AddOnResources.stamp"
138133
)
139134
else ()
@@ -214,5 +209,12 @@ get_filename_component (APIDevKitModulesDir "${AC_API_DEVKIT_DIR}/Support/Module
214209
set (GSModules "")
215210
SubDirList (GSModules "${APIDevKitModulesDir}")
216211
foreach (gsModule ${GSModules})
217-
AddGSModule (AddOn ${gsModule})
212+
AddGSModuleToIncludeDirectories (AddOn ${gsModule})
218213
endforeach ()
214+
if (WIN32)
215+
foreach (gsModule ${GSModules})
216+
AddGSModulesToLinkLibraries (AddOn ${gsModule})
217+
endforeach ()
218+
else ()
219+
AddGSModulesToLinkLibraries (AddOn)
220+
endif ()

CompileResources.py

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
import os
2+
import sys
3+
import platform
4+
import subprocess
5+
import shutil
6+
import codecs
7+
8+
class ResourceCompiler (object):
9+
def __init__ (self, devKitPath, languageCode, sourcesPath, resourcesPath, resourceObjectsPath):
10+
self.devKitPath = devKitPath
11+
self.languageCode = languageCode
12+
self.sourcesPath = sourcesPath
13+
self.resourcesPath = resourcesPath
14+
self.resourceObjectsPath = resourceObjectsPath
15+
self.resConvPath = None
16+
17+
def IsValid (self):
18+
if self.resConvPath == None:
19+
return False
20+
if not os.path.exists (self.resConvPath):
21+
return False
22+
return True
23+
24+
def GetPrecompiledResourceFilePath (self, grcFilePath):
25+
grcFileName = os.path.split (grcFilePath)[1]
26+
return os.path.join (self.resourceObjectsPath, grcFileName + '.i')
27+
28+
def CompileLocalizedResources (self):
29+
locResourcesFolder = os.path.join (self.resourcesPath, 'R' + self.languageCode)
30+
grcFiles = self.CollectFilesFromFolderWithExtension (locResourcesFolder, '.grc')
31+
for grcFilePath in grcFiles:
32+
assert self.CompileResourceFile (grcFilePath), 'Failed to compile resource: ' + grcFilePath
33+
34+
def CompileFixResources (self):
35+
fixResourcesFolder = os.path.join (self.resourcesPath, 'RFIX')
36+
grcFiles = self.CollectFilesFromFolderWithExtension (fixResourcesFolder, '.grc')
37+
for grcFilePath in grcFiles:
38+
assert self.CompileResourceFile (grcFilePath), 'Failed to compile resource: ' + grcFilePath
39+
40+
def RunResConv (self, platformSign, codepage, inputFilePath, nativeResourceFileExtenion):
41+
imageResourcesFolder = os.path.join (self.resourcesPath, 'RFIX', 'Images')
42+
inputFileBaseName = os.path.splitext (os.path.split (inputFilePath)[1])[0]
43+
nativeResourceFilePath = os.path.join (self.resourceObjectsPath, inputFileBaseName + nativeResourceFileExtenion)
44+
result = subprocess.call ([
45+
self.resConvPath,
46+
'-m', 'r', # resource compile mode
47+
'-T', platformSign, # target platform
48+
'-q', 'utf8', codepage, # code page conversion
49+
'-w', '2', # HiDPI image size list
50+
'-p', imageResourcesFolder, # image search path
51+
'-i', inputFilePath, # input path
52+
'-o', nativeResourceFilePath # output path
53+
])
54+
if result != 0:
55+
return False
56+
return True
57+
58+
def CollectFilesFromFolderWithExtension (self, folderPath, extension):
59+
result = []
60+
for fileName in os.listdir (folderPath):
61+
fileExtension = os.path.splitext (fileName)[1]
62+
if fileExtension.lower () == extension.lower ():
63+
fullPath = os.path.join (folderPath, fileName)
64+
result.append (fullPath)
65+
return result
66+
67+
class WinResourceCompiler (ResourceCompiler):
68+
def __init__ (self, devKitPath, languageCode, sourcesPath, resourcesPath, resourceObjectsPath):
69+
super (WinResourceCompiler, self).__init__ (devKitPath, languageCode, sourcesPath, resourcesPath, resourceObjectsPath)
70+
self.resConvPath = os.path.join (devKitPath, 'Support', 'Tools', 'Win', 'ResConv.exe')
71+
72+
def PrecompileResourceFile (self, grcFilePath):
73+
precompiledGrcFilePath = self.GetPrecompiledResourceFilePath (grcFilePath)
74+
result = subprocess.call ([
75+
'cl',
76+
'/nologo',
77+
'/X',
78+
'/EP',
79+
'/P',
80+
'/I', os.path.join (self.devKitPath, 'Support', 'Inc'),
81+
'/I', os.path.join (self.devKitPath, 'Support', 'Modules', 'DGLib'),
82+
'/I', self.sourcesPath,
83+
'/DWINDOWS',
84+
'/execution-charset:utf-8',
85+
'/Fi{}'.format (precompiledGrcFilePath),
86+
grcFilePath,
87+
])
88+
assert result == 0, "Failed to precompile resource " + grcFilePath
89+
return precompiledGrcFilePath
90+
91+
def CompileResourceFile (self, grcFilePath):
92+
precompiledGrcFilePath = self.PrecompileResourceFile (grcFilePath)
93+
return self.RunResConv ('W', '1252', precompiledGrcFilePath, '.rc2')
94+
95+
def GetNativeResourceFile (self):
96+
defaultNativeResourceFile = os.path.join (self.resourcesPath, 'RFIX.win', 'AddOnMain.rc2')
97+
if os.path.exists (defaultNativeResourceFile):
98+
return defaultNativeResourceFile
99+
100+
existingNativeResourceFiles = self.CollectFilesFromFolderWithExtension (os.path.join (self.resourcesPath, 'RFIX.win'), '.rc2')
101+
assert existingNativeResourceFiles, 'Native resource file was not found at RFIX.win folder'
102+
103+
return existingNativeResourceFiles[0]
104+
105+
def CompileNativeResource (self, resultResourcePath):
106+
nativeResourceFile = self.GetNativeResourceFile ()
107+
result = subprocess.call ([
108+
'rc',
109+
'/i', os.path.join (self.devKitPath, 'Support', 'Inc'),
110+
'/i', os.path.join (self.devKitPath, 'Support', 'Modules', 'DGLib'),
111+
'/i', self.sourcesPath,
112+
'/i', self.resourceObjectsPath,
113+
'/fo', resultResourcePath,
114+
nativeResourceFile
115+
])
116+
assert result == 0, 'Failed to compile native resource ' + nativeResourceFile
117+
118+
class MacResourceCompiler (ResourceCompiler):
119+
def __init__ (self, devKitPath, languageCode, sourcesPath, resourcesPath, resourceObjectsPath):
120+
super (MacResourceCompiler, self).__init__ (devKitPath, languageCode, sourcesPath, resourcesPath, resourceObjectsPath)
121+
self.resConvPath = os.path.join (devKitPath, 'Support', 'Tools', 'OSX', 'ResConv')
122+
123+
def PrecompileResourceFile (self, grcFilePath):
124+
precompiledGrcFilePath = self.GetPrecompiledResourceFilePath (grcFilePath)
125+
result = subprocess.call ([
126+
'clang',
127+
'-x', 'c++',
128+
'-E',
129+
'-P',
130+
'-Dmacintosh',
131+
'-I', os.path.join (self.devKitPath, 'Support', 'Inc'),
132+
'-I', os.path.join (self.devKitPath, 'Support', 'Modules', 'DGLib'),
133+
'-I', self.sourcesPath,
134+
'-o', precompiledGrcFilePath,
135+
grcFilePath,
136+
])
137+
assert result == 0, "Failed to precompile resource " + grcFilePath
138+
return precompiledGrcFilePath
139+
140+
def CompileResourceFile (self, grcFilePath):
141+
precompiledGrcFilePath = self.PrecompileResourceFile (grcFilePath)
142+
return self.RunResConv ('M', 'utf16', precompiledGrcFilePath, '.ro')
143+
144+
def CompileNativeResource (self, resultResourcePath):
145+
resultLocalizedResourcePath = os.path.join (resultResourcePath, 'English.lproj')
146+
if not os.path.exists (resultLocalizedResourcePath):
147+
os.makedirs (resultLocalizedResourcePath)
148+
resultLocalizableStringsPath = os.path.join (resultLocalizedResourcePath, 'Localizable.strings')
149+
resultLocalizableStringsFile = codecs.open (resultLocalizableStringsPath, 'w', 'utf-16')
150+
for fileName in os.listdir (self.resourceObjectsPath):
151+
filePath = os.path.join (self.resourceObjectsPath, fileName)
152+
extension = os.path.splitext (fileName)[1].lower ()
153+
if extension == '.tif':
154+
shutil.copy (filePath, resultResourcePath)
155+
elif extension == '.rsrd':
156+
shutil.copy (filePath, resultLocalizedResourcePath)
157+
elif extension == '.strings':
158+
stringsFile = codecs.open (filePath, 'r', 'utf-16')
159+
resultLocalizableStringsFile.write (stringsFile.read ())
160+
stringsFile.close ()
161+
resultLocalizableStringsFile.close ()
162+
163+
def Main (argv):
164+
assert len (argv) == 7, 'Usage: CompileResources.py <languageCode> <devKitPath> <sourcesPath> <resourcesPath> <resourceObjectsPath> <resultResourcePath>'
165+
166+
currentDir = os.path.dirname (os.path.abspath (__file__))
167+
os.chdir (currentDir)
168+
169+
languageCode = argv[1]
170+
devKitPath = os.path.abspath (argv[2])
171+
sourcesPath = os.path.abspath (argv[3])
172+
resourcesPath = os.path.abspath (argv[4])
173+
resourceObjectsPath = os.path.abspath (argv[5])
174+
resultResourcePath = os.path.abspath (argv[6])
175+
176+
resourceCompiler = None
177+
system = platform.system ()
178+
if system == 'Windows':
179+
resourceCompiler = WinResourceCompiler (devKitPath, languageCode, sourcesPath, resourcesPath, resourceObjectsPath)
180+
elif system == 'Darwin':
181+
resourceCompiler = MacResourceCompiler (devKitPath, languageCode, sourcesPath, resourcesPath, resourceObjectsPath)
182+
183+
assert resourceCompiler, 'Platform is not supported'
184+
assert resourceCompiler.IsValid (), 'Invalid resource compiler'
185+
186+
resourceCompiler.CompileLocalizedResources ()
187+
resourceCompiler.CompileFixResources ()
188+
resourceCompiler.CompileNativeResource (resultResourcePath)
189+
190+
return 0
191+
192+
sys.exit (Main (sys.argv))

0 commit comments

Comments
 (0)