2018-09-13 02:54:59 -04:00
|
|
|
cmake_minimum_required(VERSION 3.5)
|
|
|
|
|
|
|
|
include(${IDF_PATH}/tools/cmake/utilities.cmake)
|
|
|
|
project(${ULP_APP_NAME} ASM C)
|
|
|
|
|
2020-04-17 15:34:56 -04:00
|
|
|
option(ULP_COCPU_IS_RISCV "Use RISC-V based ULP" OFF)
|
|
|
|
|
2018-08-31 05:32:24 -04:00
|
|
|
set(version_pattern "[a-z0-9\.-]+")
|
|
|
|
|
|
|
|
# Check assembler version
|
|
|
|
execute_process(
|
|
|
|
COMMAND ${CMAKE_ASM_COMPILER} --version
|
|
|
|
OUTPUT_VARIABLE as_output
|
|
|
|
ERROR_QUIET)
|
|
|
|
|
2020-09-09 04:11:29 -04:00
|
|
|
string(REGEX MATCH "\\(GNU Binutils\\) (${version_pattern})" as_version ${as_output})
|
2018-08-31 05:32:24 -04:00
|
|
|
set(as_version ${CMAKE_MATCH_1})
|
|
|
|
|
2020-04-17 15:34:56 -04:00
|
|
|
|
2018-11-27 06:31:46 -05:00
|
|
|
message(STATUS "Building ULP app ${ULP_APP_NAME}")
|
|
|
|
|
2020-04-17 15:34:56 -04:00
|
|
|
if(ULP_COCPU_IS_RISCV)
|
|
|
|
set(ULP_LD_TEMPLATE ${IDF_PATH}/components/ulp/ld/esp32s2.ulp.riscv.ld)
|
|
|
|
else()
|
|
|
|
message(STATUS "ULP assembler version: ${as_version}")
|
|
|
|
|
|
|
|
# Check the supported assembler version
|
|
|
|
file(STRINGS ${IDF_PATH}/components/ulp/toolchain_ulp_version.mk version_file_contents)
|
2020-11-10 01:51:08 -05:00
|
|
|
string(REGEX MATCH
|
|
|
|
"SUPPORTED_ULP_ASSEMBLER_VERSION = (${version_pattern})"
|
|
|
|
as_supported_version
|
|
|
|
${version_file_contents})
|
2020-04-17 15:34:56 -04:00
|
|
|
set(as_supported_version ${CMAKE_MATCH_1})
|
|
|
|
|
|
|
|
if(NOT as_version STREQUAL as_supported_version)
|
|
|
|
message(WARNING "WARNING: ULP assembler version ${as_version} is not supported. Expected to see version: \
|
|
|
|
${as_supported_version}. Please check ESP-IDF ULP setup instructions and update \
|
|
|
|
the toolchain, or proceed at your own risk.")
|
|
|
|
endif()
|
2018-08-31 05:32:24 -04:00
|
|
|
|
2020-11-10 02:40:01 -05:00
|
|
|
set(ULP_LD_TEMPLATE ${IDF_PATH}/components/ulp/ld/esp32.ulp.ld)
|
2018-08-31 05:32:24 -04:00
|
|
|
endif()
|
|
|
|
|
2018-09-13 02:54:59 -04:00
|
|
|
|
2020-04-17 15:34:56 -04:00
|
|
|
set(ULP_MAP_GEN ${PYTHON} ${IDF_PATH}/components/ulp/esp32ulp_mapgen.py)
|
2018-09-13 02:54:59 -04:00
|
|
|
get_filename_component(sdkconfig_dir ${SDKCONFIG} DIRECTORY)
|
|
|
|
|
|
|
|
foreach(include ${COMPONENT_INCLUDES})
|
|
|
|
list(APPEND component_includes -I${include})
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
list(APPEND ULP_PREPROCESSOR_ARGS ${component_includes})
|
2019-05-09 22:53:08 -04:00
|
|
|
list(APPEND ULP_PREPROCESSOR_ARGS -I${COMPONENT_DIR})
|
2018-09-13 02:54:59 -04:00
|
|
|
list(APPEND ULP_PREPROCESSOR_ARGS -I${sdkconfig_dir})
|
|
|
|
|
2020-04-17 15:34:56 -04:00
|
|
|
include_directories(${COMPONENT_INCLUDES})
|
2018-09-13 02:54:59 -04:00
|
|
|
|
|
|
|
list(APPEND ULP_PREPROCESSOR_ARGS -D__ASSEMBLER__)
|
|
|
|
|
|
|
|
# Preprocess linker script, pre-linking
|
|
|
|
get_filename_component(ULP_LD_SCRIPT ${ULP_LD_TEMPLATE} NAME)
|
2020-11-10 01:51:08 -05:00
|
|
|
add_custom_command(OUTPUT ${ULP_LD_SCRIPT}
|
|
|
|
COMMAND ${CMAKE_C_COMPILER} -E -P -xc -o ${ULP_LD_SCRIPT} ${ULP_PREPROCESSOR_ARGS} ${ULP_LD_TEMPLATE}
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
|
|
|
DEPENDS ${ULP_LD_TEMPLATE}
|
|
|
|
VERBATIM)
|
2018-09-13 02:54:59 -04:00
|
|
|
add_custom_target(${ULP_APP_NAME}_ld_script
|
2020-11-10 01:51:08 -05:00
|
|
|
DEPENDS ${ULP_LD_SCRIPT}
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
2018-09-13 02:54:59 -04:00
|
|
|
|
2020-04-17 15:34:56 -04:00
|
|
|
if(ULP_COCPU_IS_RISCV)
|
|
|
|
#risc-v ulp uses extra files for building:
|
2020-11-10 02:40:01 -05:00
|
|
|
list(APPEND ULP_S_SOURCES
|
2020-04-17 15:34:56 -04:00
|
|
|
"${IDF_PATH}/components/ulp/ulp_riscv/start.S"
|
|
|
|
"${IDF_PATH}/components/ulp/ulp_riscv/ulp_riscv_utils.c")
|
|
|
|
|
|
|
|
#dummy loop to force pre-processed linker file generation:
|
|
|
|
foreach(ulp_s_source ${ULP_S_SOURCES})
|
|
|
|
set(noop ${ulp_s_source})
|
2020-11-10 02:40:01 -05:00
|
|
|
|
2020-04-17 15:34:56 -04:00
|
|
|
add_custom_command(OUTPUT ${noop}
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
|
|
|
COMMAND cmake -E echo
|
|
|
|
DEPENDS ${ULP_LD_SCRIPT}
|
|
|
|
)
|
|
|
|
|
|
|
|
set_source_files_properties(${noop} PROPERTIES NOOP_PROPERTY ${ULP_LD_SCRIPT})
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
#creates the executable:
|
2020-11-10 02:40:01 -05:00
|
|
|
add_executable(${ULP_APP_NAME} ${ULP_S_SOURCES})
|
2020-04-17 15:34:56 -04:00
|
|
|
set(DUMP_SYMBOL_ARGS -g)
|
|
|
|
set(MAP_GEN_EXTRA_ARGS --riscv)
|
2020-11-10 01:51:08 -05:00
|
|
|
set(EXTRA_LINKER_ARGS "-nostartfiles -Wl,--gc-sections -Xlinker \
|
|
|
|
-Map=${CMAKE_CURRENT_BINARY_DIR}/${ULP_APP_NAME}.map")
|
2020-04-17 15:34:56 -04:00
|
|
|
#Makes the csr utillies for riscv visible:
|
|
|
|
target_include_directories(${ULP_APP_NAME} PRIVATE "${IDF_PATH}/components/ulp/ulp_riscv/include")
|
|
|
|
|
|
|
|
else()
|
|
|
|
|
|
|
|
foreach(ulp_s_source ${ULP_S_SOURCES})
|
|
|
|
get_filename_component(ulp_ps_source ${ulp_s_source} NAME_WE)
|
|
|
|
set(ulp_ps_output ${CMAKE_CURRENT_BINARY_DIR}/${ulp_ps_source}.ulp.S)
|
|
|
|
# Generate preprocessed assembly files.
|
2020-11-10 01:51:08 -05:00
|
|
|
add_custom_command(OUTPUT ${ulp_ps_output}
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
|
|
|
COMMAND ${CMAKE_C_COMPILER} -E -P -xc ${ULP_PREPROCESSOR_ARGS}
|
|
|
|
-o ${ulp_ps_output} ${ulp_s_source}
|
|
|
|
DEPENDS ${ulp_s_source} ${ULP_LD_SCRIPT}
|
|
|
|
VERBATIM)
|
2020-04-17 15:34:56 -04:00
|
|
|
# During assembly file compilation, output listing files as well.
|
|
|
|
set_source_files_properties(${ulp_ps_output}
|
|
|
|
PROPERTIES COMPILE_FLAGS
|
|
|
|
"-al=${CMAKE_CURRENT_BINARY_DIR}/${ulp_ps_source}.lst")
|
|
|
|
list(APPEND ULP_PS_SOURCES ${ulp_ps_output})
|
|
|
|
endforeach()
|
2020-11-10 02:40:01 -05:00
|
|
|
|
2020-04-17 15:34:56 -04:00
|
|
|
# Create an executable
|
|
|
|
add_executable(${ULP_APP_NAME} ${ULP_PS_SOURCES})
|
|
|
|
set(DUMP_SYMBOL_ARGS -g -f posix)
|
|
|
|
set(MAP_GEN_EXTRA_ARGS .)
|
|
|
|
set(EXTRA_LINKER_ARGS "-Map=${CMAKE_CURRENT_BINARY_DIR}/${ULP_APP_NAME}.map")
|
2018-09-13 02:54:59 -04:00
|
|
|
|
2020-04-17 15:34:56 -04:00
|
|
|
endif()
|
2018-09-13 02:54:59 -04:00
|
|
|
|
|
|
|
# Dump the list of global symbols in a convenient format
|
2020-11-10 01:51:08 -05:00
|
|
|
add_custom_command(OUTPUT ${ULP_APP_NAME}.sym
|
|
|
|
COMMAND ${CMAKE_NM} ${DUMP_SYMBOL_ARGS} $<TARGET_FILE:${ULP_APP_NAME}> > ${ULP_APP_NAME}.sym
|
|
|
|
DEPENDS ${ULP_APP_NAME}
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
2018-09-13 02:54:59 -04:00
|
|
|
|
|
|
|
# Dump the binary for inclusion into the project
|
2020-11-10 01:51:08 -05:00
|
|
|
add_custom_command(OUTPUT ${ULP_APP_NAME}.bin
|
|
|
|
COMMAND ${CMAKE_OBJCOPY} -O binary $<TARGET_FILE:${ULP_APP_NAME}> ${ULP_APP_NAME}.bin
|
|
|
|
DEPENDS ${ULP_APP_NAME}
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
|
|
|
|
|
|
|
add_custom_command(OUTPUT ${ULP_APP_NAME}.ld ${ULP_APP_NAME}.h
|
|
|
|
COMMAND ${ULP_MAP_GEN} ${MAP_GEN_EXTRA_ARGS} -s ${ULP_APP_NAME}.sym -o ${ULP_APP_NAME}
|
|
|
|
DEPENDS ${ULP_APP_NAME}.sym
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
2018-09-13 02:54:59 -04:00
|
|
|
|
|
|
|
# Building the component separately from the project should result in
|
|
|
|
# ULP files being built.
|
|
|
|
add_custom_target(build
|
|
|
|
DEPENDS ${ULP_APP_NAME} ${ULP_APP_NAME}.bin ${ULP_APP_NAME}.sym
|
2018-08-31 05:32:24 -04:00
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/${ULP_APP_NAME}.ld
|
2018-09-13 02:54:59 -04:00
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/${ULP_APP_NAME}.h
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
|
|
|
|
2020-09-09 04:11:29 -04:00
|
|
|
target_link_libraries(${ULP_APP_NAME} -T${CMAKE_CURRENT_BINARY_DIR}/${ULP_LD_SCRIPT} ${EXTRA_LINKER_ARGS})
|
2021-05-05 03:54:41 -04:00
|
|
|
set_target_properties(${ULP_APP_NAME} PROPERTIES LINK_DEPENDS ${ULP_LD_SCRIPT})
|