|
|
@@ -47,8 +47,34 @@ endfunction()
|
|
|
#
|
|
|
macro(__target_set_toolchain)
|
|
|
idf_build_get_property(idf_path IDF_PATH)
|
|
|
+
|
|
|
+ # See if Clang toolchain should be used
|
|
|
+ set(env_idf_toolchain $ENV{IDF_TOOLCHAIN})
|
|
|
+ if(NOT env_idf_toolchain)
|
|
|
+ # IDF_TOOLCHAIN not set in environment, see if it is set in cache
|
|
|
+ if(IDF_TOOLCHAIN)
|
|
|
+ set(env_idf_toolchain ${IDF_TOOLCHAIN})
|
|
|
+ else()
|
|
|
+ set(env_idf_toolchain gcc)
|
|
|
+ endif()
|
|
|
+ else()
|
|
|
+ # IDF_TOOLCHAIN set both in environment and in cache, must be the same
|
|
|
+ if(NOT ${IDF_TOOLCHAIN} STREQUAL ${env_idf_toolchain})
|
|
|
+ message(FATAL_ERROR "IDF_TOOLCHAIN in CMake cache does not match "
|
|
|
+ "IDF_TOOLCHAIN environment variable. To change the toolchain, clear "
|
|
|
+ "the build directory and sdkconfig file, and build the project again")
|
|
|
+ endif()
|
|
|
+ endif()
|
|
|
+
|
|
|
+ # Finally, set IDF_TOOLCHAIN in cache
|
|
|
+ set(IDF_TOOLCHAIN ${env_idf_toolchain} CACHE STRING "IDF Build Toolchain Type")
|
|
|
+
|
|
|
+ if(${env_idf_toolchain} STREQUAL "clang")
|
|
|
+ set(toolchain_type "clang-")
|
|
|
+ endif()
|
|
|
+
|
|
|
# First try to load the toolchain file from the tools/cmake/directory of IDF
|
|
|
- set(toolchain_file_global ${idf_path}/tools/cmake/toolchain-${IDF_TARGET}.cmake)
|
|
|
+ set(toolchain_file_global ${idf_path}/tools/cmake/toolchain-${toolchain_type}${IDF_TARGET}.cmake)
|
|
|
if(EXISTS ${toolchain_file_global})
|
|
|
set(CMAKE_TOOLCHAIN_FILE ${toolchain_file_global})
|
|
|
else()
|