1get_property(__idf_env_set GLOBAL PROPERTY __IDF_ENV_SET)
2if(NOT __idf_env_set)
3    # Infer an IDF_PATH relative to the tools/cmake directory
4    get_filename_component(_idf_path "${CMAKE_CURRENT_LIST_DIR}/../.." REALPATH)
5    file(TO_CMAKE_PATH "${_idf_path}" _idf_path)
6
7    # Get the path set in environment
8    set(idf_path $ENV{IDF_PATH})
9
10    # Environment IDF_PATH should match the inferred IDF_PATH. If not, warn the user.
11    # (Note: REALPATH is needed in both above steps to account for case on case
12    # insensitive filesystems, or relative paths)
13    if(idf_path)
14        get_filename_component(idf_path "${idf_path}" REALPATH)
15        file(TO_CMAKE_PATH "${idf_path}" idf_path)
16
17        if(NOT idf_path STREQUAL _idf_path)
18            message(WARNING "IDF_PATH environment variable is different from inferred IDF_PATH.
19                            Check if your project's top-level CMakeLists.txt includes the right
20                            CMake files. Environment IDF_PATH will be used for the build:
21                            ${idf_path}")
22        endif()
23    else()
24        message(WARNING "IDF_PATH environment variable not found. Setting IDF_PATH to '${_idf_path}'.")
25        set(idf_path ${_idf_path})
26        set(ENV{IDF_PATH} ${_idf_path})
27    endif()
28
29    # Include other CMake modules required
30    set(CMAKE_MODULE_PATH
31        "${idf_path}/tools/cmake"
32        "${idf_path}/tools/cmake/third_party"
33        ${CMAKE_MODULE_PATH})
34    include(build)
35
36    set(IDF_PATH ${idf_path})
37
38    include(GetGitRevisionDescription)
39    include(git_submodules)
40    include(crosstool_version_check)
41    include(kconfig)
42    include(component)
43    include(utilities)
44    include(targets)
45    include(ldgen)
46    include(dfu)
47    include(uf2)
48    include(version)
49
50    __build_init("${idf_path}")
51
52    set_property(GLOBAL PROPERTY __IDF_ENV_SET 1)
53endif()
54