@@ -493,6 +493,10 @@ endfunction()
493493# Internal utility functions that find Arduino components and configurations.
494494# ======================================================================================================================
495495
496+ set (__ARDUINO_CLI_CONFIG_DESCRIPTION "Arduino CLI configuration" )
497+ set (__ARDUINO_CLI_CONFIG_FILENAME "config.json" )
498+ set (__ARDUINO_CLI_CONFIG_COMMAND config dump --format=json)
499+
496500set (__ARDUINO_PROPERTIES_EXPANDED_DESCRIPTION "expanded build properties" )
497501set (__ARDUINO_PROPERTIES_EXPANDED_FILENAME "properties-expanded.txt" )
498502set (__ARDUINO_PROPERTIES_EXPANDED_COMMAND board details "--fqbn=${ARDUINO_BOARD} " --format=text --show-properties=expanded)
@@ -618,7 +622,8 @@ function(__arduino_find_properties MODE)
618622endfunction ()
619623
620624# ----------------------------------------------------------------------------------------------------------------------
621- # Collects available libraries for the current board from arduino-cli.
625+ # Reads available libraries for the current board from `arduino-cli`
626+ # and stores the JSON in `__ARDUINO_INSTALLED_LIBRARIES`.
622627# ----------------------------------------------------------------------------------------------------------------------
623628function (__arduino_find_libraries)
624629 __arduino_read_cached_setting(INSTALLED_LIBRARIES)
@@ -636,6 +641,92 @@ function(__arduino_find_libraries)
636641 set (__ARDUINO_INSTALLED_LIBRARIES_CACHE "${__ARDUINO_INSTALLED_LIBRARIES_CACHE} " PARENT_SCOPE)
637642endfunction ()
638643
644+ # ----------------------------------------------------------------------------------------------------------------------
645+ # Reads configuration of `arduino-cli` and stores the JSON in `__ARDUINO_CLI_CONFIG`.
646+ # ----------------------------------------------------------------------------------------------------------------------
647+ function (__arduino_find_config)
648+ __arduino_read_cached_setting(CLI_CONFIG)
649+
650+ set (__ARDUINO_CLI_CONFIG "${__ARDUINO_CLI_CONFIG} " PARENT_SCOPE)
651+ set (__ARDUINO_CLI_CONFIG_CACHE "${__ARDUINO_CLI_CONFIG_CACHE} " PARENT_SCOPE)
652+ endfunction ()
653+
654+ # ----------------------------------------------------------------------------------------------------------------------
655+ # Finds and verifies the location of user sketches.
656+ # ----------------------------------------------------------------------------------------------------------------------
657+ function (__arduino_find_user_sketches_dirpath)
658+ string (
659+ JSON _user_sketches_dirpath ERROR_VARIABLE _error
660+ GET "${__ARDUINO_CLI_CONFIG} " config directories user)
661+
662+ if (NOT _error AND _user_sketches_dirpath)
663+ cmake_path(ABSOLUTE_PATH _user_sketches_dirpath NORMALIZE)
664+
665+ if (NOT IS_DIRECTORY "${_user_sketches_dirpath} " )
666+ set (_error_message
667+ "Your arduino-cli is configured to use \" ${_user_sketches_dirpath} \" "
668+ "for user sketches and libraries, but this directory does not exist." )
669+ endif ()
670+ else ()
671+ set (_error_message "Your arduino-cli doesn't know where to find user sketches and libraries." )
672+ endif ()
673+
674+ if (_error_message)
675+ list (APPEND _error_message
676+ "\n YOUR BUILDS MIGHT FAIL!\n Please consider running `arduino-cli config set "
677+ "directories.user PATH-TO-YOUR-SKETCHES` to address this issue." )
678+
679+ if (DEFINED ENV{USERPROFILE})
680+ list (APPEND _error_message "\n A typical path would be: \" $ENV{USERPROFILE} \\ Arduino\" " )
681+ elseif (DEFINED ENV{HOME})
682+ list (APPEND _error_message "\n A typical path would be: \" $ENV{HOME} /Arduino\" " )
683+ endif ()
684+
685+ message (WARNING ${_error_message} )
686+ set (_user_sketches_dirpath NOTFOUND )
687+ endif ()
688+
689+ set (__ARDUINO_USER_SKETCHES_DIRPATH "${_user_sketches_dirpath} " PARENT_SCOPE)
690+ endfunction ()
691+
692+ # ----------------------------------------------------------------------------------------------------------------------
693+ # Finds and verifies the location of IDE libraries.
694+ # ----------------------------------------------------------------------------------------------------------------------
695+ function (__arduino_find_ide_libraries_dirpath)
696+ string (
697+ JSON _ide_libraries_dirpath ERROR_VARIABLE _error
698+ GET "${__ARDUINO_CLI_CONFIG} " config directories builtin libraries)
699+
700+ if (NOT _error AND _ide_libraries_dirpath)
701+ cmake_path(ABSOLUTE_PATH _ide_libraries_dirpath NORMALIZE)
702+
703+ if (NOT IS_DIRECTORY "${_ide_libraries_dirpath} " )
704+ set (_error_message
705+ "Your arduino-cli is configured to use \" ${_ide_libraries_dirpath} \" "
706+ "for IDE provided libraries, but this directory does not exist." )
707+ endif ()
708+ else ()
709+ set (_error_message "Your arduino-cli doesn't know where to find IDE provided libraries." )
710+ endif ()
711+
712+ if (_error_message)
713+ list (APPEND _error_message
714+ "\n YOUR BUILDS MIGHT FAIL!\n Please consider running `arduino-cli config set "
715+ "directories.builtin.libraries PATH-TO-YOUR-IDE-LIBRARIES` to address this issue." )
716+
717+ if (DEFINED ENV{LOCALAPPDATA})
718+ list (APPEND _error_message "\n A typical path would be: \" $ENV{LOCALAPPDATA} \\ Arduino15\\ libraries\" " )
719+ elseif (DEFINED ENV{HOME})
720+ list (APPEND _error_message "\n A typical path would be: \" $ENV{HOME} /.arduino15/libraries\" " )
721+ endif ()
722+
723+ message (WARNING ${_error_message} )
724+ set (_user_sketches_dirpath NOTFOUND )
725+ endif ()
726+
727+ set (__ARDUINO_IDE_LIBRARIES_DIRPATH "${_ide_libraries_dirpath} " PARENT_SCOPE)
728+ endfunction ()
729+
639730# ======================================================================================================================
640731# Internal utility functions that inspect CMake targets.
641732# ======================================================================================================================
@@ -1019,7 +1110,10 @@ find_program( # <---------------------------------------------------------------
10191110 [HKLM/SOFTWARE/Arduino CLI;InstallDir]
10201111 "$ENV{PROGRAMFILES} /Arduino CLI" )
10211112
1022- __arduino_find_properties(EXPANDED) # <-------------------------------------- collect properties and installed libraries
1113+ __arduino_find_config() # <----------------------------------- collect configuration, properties and installed libraries
1114+ __arduino_find_user_sketches_dirpath()
1115+ __arduino_find_ide_libraries_dirpath()
1116+ __arduino_find_properties(EXPANDED)
10231117__arduino_find_properties(UNEXPANDED)
10241118__arduino_find_libraries()
10251119
@@ -1079,7 +1173,8 @@ __arduino_run_hooks("recipe.hooks.prebuild")
10791173list ( # <--------------------------------------------------------------------------------------- configure try_compile()
10801174 APPEND CMAKE_TRY_COMPILE_PLATFORM_VARIABLES
10811175 ARDUINO_BOARD # make it just work
1082- __ARDUINO_PROPERTIES_EXPANDED_CACHE # make it MUCH faster
1176+ __ARDUINO_CLI_CONFIG_CACHE # make it MUCH faster
1177+ __ARDUINO_PROPERTIES_EXPANDED_CACHE
10831178 __ARDUINO_PROPERTIES_UNEXPANDED_CACHE
10841179 __ARDUINO_INSTALLED_LIBRARIES_CACHE
10851180 __ARDUINO_IMPORTED_TARGET_CACHE)
0 commit comments