27
27
import tempfile
28
28
import threading
29
29
import sys
30
+ import json
30
31
31
32
from absl import app , flags , logging
32
33
82
83
g_cpp_sdk_realpath = ""
83
84
84
85
FLAGS = flags .FLAGS
86
+
87
+ #
88
+ flags .DEFINE_string (
89
+ 'generator' , "Visual Studio 16 2019" ,
90
+ "The cmake generator passed with -G flag"
91
+ )
92
+ flags .DEFINE_string (
93
+ 'preset' , None ,
94
+ "The cmake --preset name arg from CMakeSettings.json or CMakeUserSettings.json"
95
+ )
85
96
flags .DEFINE_string (
86
97
'platform' , None ,
87
98
'Which platform to build SDK on. Required one entry from ({})' .format (
@@ -142,6 +153,51 @@ def get_build_path(platform, clean_build=False):
142
153
return platform_path
143
154
144
155
156
+ def get_presets_file_path (source_path : str ):
157
+ """Get the cmake args to pass as --preset name from a CMakePresets.json
158
+ from that root project folder
159
+
160
+ Args:
161
+ source_path: root source folder to find CMakePresets.json or CMakeUserPresets.json files.
162
+
163
+ Returns:
164
+ camke args with the --preset name that contains variables and others cmake configurations
165
+ """
166
+
167
+ if FLAGS .preset :
168
+ return f"--preset { FLAGS .preset } "
169
+
170
+ preset_files = [
171
+ source_path + "CMakePresets.json" ,
172
+ source_path + "CMakeUserPresets.json"
173
+ ]
174
+
175
+ for pfile in preset_files :
176
+
177
+ if not os .path .exists (pfile ):
178
+ continue
179
+
180
+ try :
181
+ presets_file = open (pfile )
182
+
183
+ if presets_file :
184
+ presets_data = json .load (presets_file )
185
+
186
+ # List comprehension filter
187
+ matches = [x for x in presets_data ['configurePresets' ] if x ['name' ].startswith ("firebase-unity-sdk" )]
188
+ if matches and matches [0 ]:
189
+ preset = matches [0 ]
190
+
191
+ return f"--preset { preset ['name' ]} "
192
+
193
+ except OSError as error :
194
+ print (
195
+ f"Error on load file: '{ pfile } '" ,
196
+ "Reason => " ,
197
+ f'[{ type (error ).__name__ } ]: { error .strerror } '
198
+ )
199
+
200
+
145
201
def get_cpp_folder_args (source_path ):
146
202
"""Get the cmake args to pass in local Firebase C++ SDK folder.
147
203
If not found, will download from Firebase C++ git repo.
@@ -430,7 +486,7 @@ def get_windows_args():
430
486
cmake args for windows platform.
431
487
"""
432
488
result_args = []
433
- result_args .append (' -G Visual Studio 16 2019' )
489
+ result_args .append (" -G %s" % FLAGS . generator ) # Default: -G Visual Studio 16 2019
434
490
result_args .append ('-A x64' ) # TODO flexibily for x32
435
491
result_args .append ("-DFIREBASE_PYTHON_HOST_EXECUTABLE:FILEPATH=%s" % sys .executable )
436
492
# Use a newer version of the Windows SDK, as the default one has build issues with grpc
@@ -734,6 +790,9 @@ def main(argv):
734
790
platform , "," .join (SUPPORT_PLATFORMS )))
735
791
736
792
source_path = os .getcwd ()
793
+ relative_path = "." + os .path .sep
794
+
795
+ cmake_presets_file_args = get_presets_file_path (relative_path )
737
796
cmake_cpp_folder_args = get_cpp_folder_args (source_path )
738
797
build_path = get_build_path (platform , FLAGS .clean_build )
739
798
if is_android_build () and g_cpp_sdk_realpath :
@@ -746,6 +805,9 @@ def main(argv):
746
805
"cmake" ,
747
806
source_path
748
807
]
808
+
809
+ if cmake_presets_file_args :
810
+ cmake_setup_args .append (cmake_presets_file_args )
749
811
750
812
if FLAGS .verbose :
751
813
cmake_setup_args .append ('-DCMAKE_VERBOSE_MAKEFILE=1' )
0 commit comments