File tree Expand file tree Collapse file tree 2 files changed +30
-4
lines changed Expand file tree Collapse file tree 2 files changed +30
-4
lines changed Original file line number Diff line number Diff line change @@ -89,11 +89,9 @@ endmacro()
89
89
# Set an overridable option.
90
90
macro (set_overridable_option NAME VALUE )
91
91
# If the user has explitily set the option, do not override it.
92
- if (DEFINED ${NAME} )
93
- return ( )
92
+ if (NOT DEFINED ${NAME} )
93
+ set ( ${NAME} ${VALUE} CACHE STRING "" )
94
94
endif ()
95
-
96
- set (${NAME} ${VALUE} CACHE STRING "" )
97
95
endmacro ()
98
96
99
97
# Detemine the build preset and load it.
Original file line number Diff line number Diff line change @@ -271,6 +271,34 @@ def test_set_overridable_option_after(self):
271
271
self .run_cmake ()
272
272
self .assert_cmake_cache ("EXECUTORCH_TEST_MESSAGE" , "move fast" , "STRING" )
273
273
274
+ def test_set_overridable_option_loaded_from_file (self ):
275
+ _cmake_lists_txt = """
276
+ cmake_minimum_required(VERSION 3.24)
277
+ project(test_preset)
278
+ include(${PROJECT_SOURCE_DIR}/preset.cmake)
279
+ include(${PROJECT_SOURCE_DIR}/build/my_preset.cmake)
280
+ include(${PROJECT_SOURCE_DIR}/build/default.cmake)
281
+ """
282
+ _my_preset_txt = """
283
+ set_overridable_option(EXECUTORCH_FOO "hello world")
284
+ """
285
+ _default_preset_txt = """
286
+ define_overridable_option(EXECUTORCH_TEST_MESSAGE "test message" STRING "move fast")
287
+ define_overridable_option(EXECUTORCH_FOO "another test message" STRING "break things")
288
+ """
289
+ self .create_workspace (
290
+ {
291
+ "CMakeLists.txt" : _cmake_lists_txt ,
292
+ "build" : {
293
+ "my_preset.cmake" : _my_preset_txt ,
294
+ "default.cmake" : _default_preset_txt ,
295
+ },
296
+ }
297
+ )
298
+ self .run_cmake (cmake_args = ["-DEXECUTORCH_TEST_MESSAGE='from the cli'" ])
299
+ self .assert_cmake_cache ("EXECUTORCH_TEST_MESSAGE" , "from the cli" , "STRING" )
300
+ self .assert_cmake_cache ("EXECUTORCH_FOO" , "hello world" , "STRING" )
301
+
274
302
def test_set_overridable_option_with_cli_override (self ):
275
303
_cmake_lists_txt = """
276
304
cmake_minimum_required(VERSION 3.24)
You can’t perform that action at this time.
0 commit comments