Skip to content

Commit

Permalink
fix UF2 version with cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
hathach committed Dec 14, 2023
1 parent 08625fa commit 12f1651
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 28 deletions.
28 changes: 19 additions & 9 deletions ports/family_support.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ include_guard()

include(CMakePrintHelpers)
find_package(Python COMPONENTS Interpreter)
find_package(Git REQUIRED)

# TOP is path to root directory
set(TOP ${CMAKE_CURRENT_LIST_DIR}/..)
Expand Down Expand Up @@ -171,17 +172,26 @@ function(family_add_tinyusb TARGET OPT_MCU RTOS)
endfunction()

function(family_add_uf2version TARGET DEPS_REPO)
execute_process(COMMAND git describe --dirty --always --tags OUTPUT_VARIABLE GIT_VERSION)
execute_process(COMMAND ${GIT_EXECUTABLE} describe --dirty --always --tags OUTPUT_VARIABLE GIT_VERSION)
string(STRIP ${GIT_VERSION} GIT_VERSION)
string(REPLACE ${TOP}/ "" DEPS_REPO "${DEPS_REPO}")
foreach (DEP ${DEPS_REPO})
execute_process(COMMAND ${GIT_EXECUTABLE} -C ${TOP} submodule status ${DEP}
OUTPUT_VARIABLE DEP_VERSION
)
string(STRIP ${DEP_VERSION} DEP_VERSION)
string(FIND "${DEP_VERSION}" " " SPACE_POS)
string(SUBSTRING "${DEP_VERSION}" ${SPACE_POS} -1 DEP_VERSION)
string(STRIP ${DEP_VERSION} DEP_VERSION)

set(GIT_SUBMODULE_VERSIONS "${GIT_SUBMODULE_VERSIONS} ${DEP_VERSION}")
endforeach ()

execute_process(COMMAND bash "-c" "git -C ${TOP}/lib submodule status ${DEPS_REPO} | cut -d\" \" -f3,4 | paste -s -d\" \" -"
OUTPUT_VARIABLE GIT_SUBMODULE_VERSIONS
)
string(REPLACE ../ "" GIT_SUBMODULE_VERSIONS ${GIT_SUBMODULE_VERSIONS})
string(REPLACE lib/ "" GIT_SUBMODULE_VERSIONS ${GIT_SUBMODULE_VERSIONS})
string(STRIP ${GIT_SUBMODULE_VERSIONS} GIT_SUBMODULE_VERSIONS)
string(REPLACE lib/ "" GIT_SUBMODULE_VERSIONS ${GIT_SUBMODULE_VERSIONS})

cmake_print_variables(GIT_VERSION GIT_SUBMODULE_VERSIONS)
cmake_print_variables(GIT_VERSION)
cmake_print_variables(GIT_SUBMODULE_VERSIONS)

target_compile_definitions(${TARGET} PUBLIC
UF2_VERSION_BASE="${GIT_VERSION}"
Expand All @@ -191,13 +201,14 @@ endfunction()

function(family_configure_tinyuf2 TARGET OPT_MCU)
family_configure_common(${TARGET})
family_add_bin_hex(${TARGET})

#target_include_directories(${TARGET} PUBLIC)
#target_compile_definitions(${TARGET} PUBLIC)
include(${TOP}/src/tinyuf2.cmake)
add_tinyuf2(${TARGET})

family_add_uf2version(${TARGET} "${FAMILY_SUBMODULE_DEPS}")

family_add_tinyusb(tinyuf2 ${OPT_MCU} none)
endfunction()

Expand Down Expand Up @@ -337,7 +348,6 @@ if (DEFINED FAMILY_SUBMODULE_DEPS)
# Check if the submodule is present. If not, fetch it
if(NOT EXISTS ${DEP}/.git)
string(REPLACE ${TOP}/ "" DEP_REL ${DEP})
find_package(Git REQUIRED)
execute_process(
COMMAND ${GIT_EXECUTABLE} -C ${TOP} submodule update --init ${DEP_REL}
)
Expand Down
2 changes: 1 addition & 1 deletion ports/stm32f3/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ family_flash_jlink(tinyuf2)
#------------------------------------
# Application (e.g self update)
#------------------------------------
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/apps/self_update)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/apps/self_update)
18 changes: 0 additions & 18 deletions src/tinyuf2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,4 @@ function (add_tinyuf2 TARGET)
${CMAKE_CURRENT_FUNCTION_LIST_DIR}
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/favicon
)

execute_process(COMMAND git describe --dirty --always --tags OUTPUT_VARIABLE GIT_VERSION)
string(STRIP ${GIT_VERSION} GIT_VERSION)

get_target_property(deps_repo ${TARGET} DEPS_SUBMODULES)
set(deps_repo "${deps_repo} ${TINYUSB_DIR}/..")

execute_process(COMMAND bash "-c" "git -C ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/.. submodule status ${deps_repo} | cut -d\" \" -f3,4 | paste -s -d\" \" -"
OUTPUT_VARIABLE GIT_SUBMODULE_VERSIONS
)
string(REPLACE ../ "" GIT_SUBMODULE_VERSIONS ${GIT_SUBMODULE_VERSIONS})
string(REPLACE lib/ "" GIT_SUBMODULE_VERSIONS ${GIT_SUBMODULE_VERSIONS})
string(STRIP ${GIT_SUBMODULE_VERSIONS} GIT_SUBMODULE_VERSIONS)

target_compile_definitions(${TARGET} PUBLIC
UF2_VERSION_BASE="${GIT_VERSION}"
UF2_VERSION="${GIT_VERSION} - ${GIT_SUBMODULE_VERSIONS}"
)
endfunction()

0 comments on commit 12f1651

Please sign in to comment.