diff --git a/components/esp32/CMakeLists.txt b/components/esp32/CMakeLists.txt index 371023789..0fca8aa0c 100644 --- a/components/esp32/CMakeLists.txt +++ b/components/esp32/CMakeLists.txt @@ -58,7 +58,8 @@ else() # Process the template file through the linker script generation mechanism, and use the output for linking the # final binary - target_linker_script(${COMPONENT_LIB} "${CMAKE_CURRENT_LIST_DIR}/ld/esp32.project.ld.in" PROCESS) + target_linker_script(${COMPONENT_LIB} "${CMAKE_CURRENT_LIST_DIR}/ld/esp32.project.ld.in" + PROCESS "${CMAKE_CURRENT_BINARY_DIR}/ld/esp32.project.ld") target_linker_script(${COMPONENT_LIB} "ld/esp32.peripherals.ld") target_link_libraries(${COMPONENT_LIB} gcc) diff --git a/tools/cmake/ldgen.cmake b/tools/cmake/ldgen.cmake index 9161ecd8f..b8cfaad49 100644 --- a/tools/cmake/ldgen.cmake +++ b/tools/cmake/ldgen.cmake @@ -27,7 +27,7 @@ endfunction() # # Passes a linker script template to the linker script generation tool for # processing -function(__ldgen_process_template output_var template) +function(__ldgen_process_template template output) idf_build_get_property(idf_target IDF_TARGET) idf_build_get_property(idf_path IDF_PATH) @@ -36,11 +36,6 @@ function(__ldgen_process_template output_var template) file(GENERATE OUTPUT ${build_dir}/ldgen_libraries.in CONTENT $) file(GENERATE OUTPUT ${build_dir}/ldgen_libraries INPUT ${build_dir}/ldgen_libraries.in) - get_filename_component(filename "${template}" NAME) - - set(output ${CMAKE_CURRENT_BINARY_DIR}/${filename}.ld) - set(${output_var} ${output} PARENT_SCOPE) - set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "${build_dir}/ldgen_libraries.in" diff --git a/tools/cmake/utilities.cmake b/tools/cmake/utilities.cmake index 4e64c1620..f5f7f9693 100644 --- a/tools/cmake/utilities.cmake +++ b/tools/cmake/utilities.cmake @@ -131,13 +131,14 @@ endfunction() # and then adds -T with the filename only. This allows INCLUDE directives to be # used to include other linker scripts in the same directory. function(target_linker_script target scriptfiles) - cmake_parse_arguments(_ "PROCESS" "" "" ${ARGN}) + cmake_parse_arguments(_ "" "PROCESS" "" ${ARGN}) foreach(scriptfile ${scriptfiles}) get_filename_component(abs_script "${scriptfile}" ABSOLUTE) message(STATUS "Adding linker script ${abs_script}") if(__PROCESS) - __ldgen_process_template(output ${abs_script}) + get_filename_component(output "${__PROCESS}" ABSOLUTE) + __ldgen_process_template(${abs_script} ${output}) set(abs_script ${output}) endif() diff --git a/tools/ldgen/ldgen.py b/tools/ldgen/ldgen.py index 7829e4dfb..dcc0db4e0 100755 --- a/tools/ldgen/ldgen.py +++ b/tools/ldgen/ldgen.py @@ -19,6 +19,8 @@ import argparse import sys import tempfile import subprocess +import os +import errno from fragments import FragmentFile from sdkconfig import SDKConfig @@ -111,6 +113,14 @@ def main(): with tempfile.TemporaryFile("w+") as output: script_model.write(output) output.seek(0) + + if not os.path.exists(os.path.dirname(output_path)): + try: + os.makedirs(os.path.dirname(output_path)) + except OSError as exc: + if exc.errno != errno.EEXIST: + raise + with open(output_path, "w") as f: # only create output file after generation has suceeded f.write(output.read()) except LdGenFailure as e: