Skip to content

Commit

Permalink
Refactor build system (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
onkwon authored Jan 3, 2024
1 parent 1d765a7 commit e4095df
Show file tree
Hide file tree
Showing 10 changed files with 143 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/memsize.baseline
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
text data bss dec hex filename
159061 46756 367669 573486 8c02e build/template.elf
159173 46760 367669 573602 8c0a2 build/template.elf
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ jobs:
body: body
})
- name: Store codechecker baseline
if: always()
if: always() && github.event_name == 'pull_request'
uses: EndBug/add-and-commit@v9
with:
add: '[${{ env.CODECHECKER_BASE }}, ${{ env.MEMSEG_BASE }}]'
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
15 changes: 14 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
cmake_minimum_required(VERSION 3.16)

include($ENV{IDF_PATH}/tools/cmake/project.cmake)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
cmake_policy(SET CMP0135 NEW)
endif()

if (NOT DEFINED IDF_TARGET)
set(IDF_TARGET esp32s3)
endif()
set(CMAKE_TOOLCHAIN_FILE $ENV{IDF_PATH}/tools/cmake/toolchain-${IDF_TARGET}.cmake)

project(template)

include($ENV{IDF_PATH}/tools/cmake/idf.cmake)
include(${CMAKE_SOURCE_DIR}/ports/esp_idf/build.cmake)
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Kyunghwan Kwon

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ export Q

include version.mk

all: build size

build:
cmake -GNinja -B build
cmake --build build

.PHONY: confirm
confirm:
@echo 'Are you sure? [y/N] ' && read ans && [ $${ans:-N} = y ]
Expand Down
80 changes: 80 additions & 0 deletions ports/esp_idf/build.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
set(COMPONENTS_USED
freertos
esptool_py
bt
esp-tls
esp_http_server
esp_http_client
esp_https_ota
app_update
)

if ($ENV{IDF_VERSION} VERSION_GREATER_EQUAL "5.0.0")
list(APPEND COMPONENTS_USED esp_adc)
else()
list(APPEND COMPONENTS_USED esp_adc_cal)
endif()

idf_build_process(${IDF_TARGET}
COMPONENTS
${COMPONENTS_USED}
SDKCONFIG_DEFAULTS
"${CMAKE_CURRENT_LIST_DIR}/sdkconfig.defaults"
BUILD_DIR
${CMAKE_CURRENT_BINARY_DIR}
)

set(mapfile "${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}.map")
# project_description.json metadata file used for the flash and the monitor of
# idf.py to get the project information.
set(PROJECT_EXECUTABLE ${CMAKE_PROJECT_NAME}.elf)
set(PROJECT_BIN ${CMAKE_PROJECT_NAME}.bin)
set(build_components_json "[]")
set(build_component_paths_json "[]")
configure_file("${IDF_PATH}/tools/cmake/project_description.json.in"
"${CMAKE_CURRENT_BINARY_DIR}/project_description.json")

add_executable(${PROJECT_EXECUTABLE}
${CMAKE_SOURCE_DIR}/src/main.c
)

target_compile_definitions(${PROJECT_EXECUTABLE}
PRIVATE
ESP_PLATFORM=1
xPortIsInsideInterrupt=xPortInIsrContext
)
target_include_directories(${PROJECT_EXECUTABLE}
PRIVATE
$ENV{IDF_PATH}/components/freertos/FreeRTOS-Kernel/include/freertos
$ENV{IDF_PATH}/components/freertos/include/freertos
${CMAKE_CURRENT_LIST_DIR}
)

target_link_libraries(${PROJECT_EXECUTABLE}
idf::freertos
idf::spi_flash
idf::nvs_flash
idf::driver
idf::pthread
idf::esp_http_server
idf::esp_http_client
idf::esp_https_ota
idf::app_update

-Wl,--cref
-Wl,--Map=\"${mapfile}\"
)
if ($ENV{IDF_VERSION} VERSION_GREATER_EQUAL "5.0.0")
target_link_libraries(${PROJECT_EXECUTABLE} idf::esp_adc)
else()
target_link_libraries(${PROJECT_EXECUTABLE} idf::esp_adc_cal)
endif()

set(idf_size ${python} $ENV{IDF_PATH}/tools/idf_size.py)
add_custom_target(size DEPENDS ${mapfile} COMMAND ${idf_size} ${mapfile})
add_custom_target(size-files DEPENDS ${mapfile} COMMAND ${idf_size} --files ${mapfile})
add_custom_target(size-components DEPENDS ${mapfile} COMMAND ${idf_size} --archives ${mapfile})

# Attach additional targets to the executable file for flashing,
# linker script generation, partition_table generation, etc.
idf_build_executable(${PROJECT_EXECUTABLE})
11 changes: 11 additions & 0 deletions ports/esp_idf/partitions.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Espressif ESP32 Partition Table
# Name , Type, SubType, Offset, Size, Flags
nvs , data, nvs, 0x10000, 0xc000
nvs_key , data, nvs_keys, 0x1c000, 0x1000, encrypted
otadata , data, ota, 0x1d000, 0x2000
phy_init , data, phy, 0x1f000, 0x1000
ota_0 , app, ota_0, 0x20000, 0x300000
ota_1 , app, ota_1, 0x320000, 0x300000
fs , data, spiffs, 0x620000, 0x80000
nvs_eeprom, data, nvs, 0x6a0000, 0x4000
spare , data, nvs, 0x6a4000, 0x40000
8 changes: 8 additions & 0 deletions ports/esp_idf/sdkconfig.defaults
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CONFIG_PARTITION_TABLE_CUSTOM=y
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="ports/esp_idf/partitions.csv"
CONFIG_PARTITION_TABLE_FILENAME="ports/esp_idf/partitions.csv"
CONFIG_PARTITION_TABLE_OFFSET=0xE000

CONFIG_ESPTOOLPY_FLASHSIZE_8MB=y

CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE=y
File renamed without changes.

0 comments on commit e4095df

Please sign in to comment.