@@ -319,3 +319,100 @@ def test_set_overridable_option_with_cli_override(self):
319
319
)
320
320
self .run_cmake (cmake_args = ["-DEXECUTORCH_TEST_MESSAGE='from the cli'" ])
321
321
self .assert_cmake_cache ("EXECUTORCH_TEST_MESSAGE" , "from the cli" , "STRING" )
322
+
323
+ def test_check_required_options_on_if_on_off (self ):
324
+ """Test that when IF_ON is OFF, no checks are performed."""
325
+
326
+ _cmake_lists_txt = """
327
+ cmake_minimum_required(VERSION 3.24)
328
+ project(test_preset)
329
+ include(${PROJECT_SOURCE_DIR}/preset.cmake)
330
+
331
+ set(FEATURE_FLAG OFF)
332
+ set(REQUIRED_OPTION1 OFF)
333
+ set(REQUIRED_OPTION2 OFF)
334
+
335
+ check_required_options_on(
336
+ IF_ON
337
+ FEATURE_FLAG
338
+ REQUIRES
339
+ REQUIRED_OPTION1
340
+ REQUIRED_OPTION2
341
+ )
342
+ """
343
+ self .create_workspace ({"CMakeLists.txt" : _cmake_lists_txt })
344
+ self .run_cmake () # Should succeed
345
+
346
+ def test_check_required_options_on_all_required_on (self ):
347
+ """Test that when IF_ON is ON and all required options are ON, no error occurs."""
348
+
349
+ _cmake_lists_txt = """
350
+ cmake_minimum_required(VERSION 3.24)
351
+ project(test_preset)
352
+ include(${PROJECT_SOURCE_DIR}/preset.cmake)
353
+
354
+ set(FEATURE_FLAG ON)
355
+ set(REQUIRED_OPTION1 ON)
356
+ set(REQUIRED_OPTION2 ON)
357
+
358
+ check_required_options_on(
359
+ IF_ON
360
+ FEATURE_FLAG
361
+ REQUIRES
362
+ REQUIRED_OPTION1
363
+ REQUIRED_OPTION2
364
+ )
365
+ """
366
+ self .create_workspace ({"CMakeLists.txt" : _cmake_lists_txt })
367
+ self .run_cmake ()
368
+
369
+ def test_check_required_options_on_one_required_off (self ):
370
+ """Test that when IF_ON is ON but one required option is OFF, a fatal error occurs."""
371
+
372
+ _cmake_lists_txt = """
373
+ cmake_minimum_required(VERSION 3.24)
374
+ project(test_preset)
375
+ include(${PROJECT_SOURCE_DIR}/preset.cmake)
376
+
377
+ set(FEATURE_FLAG ON)
378
+ set(REQUIRED_OPTION1 ON)
379
+ set(REQUIRED_OPTION2 OFF)
380
+
381
+ check_required_options_on(
382
+ IF_ON
383
+ FEATURE_FLAG
384
+ REQUIRES
385
+ REQUIRED_OPTION1
386
+ REQUIRED_OPTION2
387
+ )
388
+ """
389
+ self .create_workspace ({"CMakeLists.txt" : _cmake_lists_txt })
390
+ self .run_cmake (
391
+ error_contains = "Use of 'FEATURE_FLAG' requires 'REQUIRED_OPTION2'"
392
+ )
393
+
394
+ def test_check_required_options_on_multiple_required_off (self ):
395
+ """Test that when IF_ON is ON but multiple required options are OFF, a fatal error occurs for the first one."""
396
+
397
+ _cmake_lists_txt = """
398
+ cmake_minimum_required(VERSION 3.24)
399
+ project(test_preset)
400
+ include(${PROJECT_SOURCE_DIR}/preset.cmake)
401
+
402
+ set(FEATURE_FLAG ON)
403
+ set(REQUIRED_OPTION1 OFF)
404
+ set(REQUIRED_OPTION2 OFF)
405
+
406
+ # This should cause a fatal error
407
+ check_required_options_on(
408
+ IF_ON
409
+ FEATURE_FLAG
410
+ REQUIRES
411
+ REQUIRED_OPTION1
412
+ REQUIRED_OPTION2
413
+ )
414
+ """
415
+ self .create_workspace ({"CMakeLists.txt" : _cmake_lists_txt })
416
+ self .run_cmake (
417
+ error_contains = "Use of 'FEATURE_FLAG' requires 'REQUIRED_OPTION1'"
418
+ )
0 commit comments