set(CMAKE_SYSTEM_NAME Generic) set(CMAKE_SYSTEM_PROCESSOR arm) set(CMAKE_CROSSCOMPILING 1) cmake_minimum_required(VERSION 3.0) set(CMAKE_TOOLCHAIN_FILE "arm-none-eabi-gcc.cmake") project(reflow-controller) if(NOT WIN32) string(ASCII 27 Esc) set(ColorReset "${Esc}[m") set(ColorBold "${Esc}[1m") set(Red "${Esc}[31m") set(Green "${Esc}[32m") set(Yellow "${Esc}[33m") set(Blue "${Esc}[34m") set(Magenta "${Esc}[35m") set(Cyan "${Esc}[36m") set(White "${Esc}[37m") set(BoldRed "${Esc}[1;31m") set(BoldGreen "${Esc}[1;32m") set(BoldYellow "${Esc}[1;33m") set(BoldBlue "${Esc}[1;34m") set(BoldMagenta "${Esc}[1;35m") set(BoldCyan "${Esc}[1;36m") set(BoldWhite "${Esc}[1;37m") endif() find_package(Git) if (GIT_FOUND) message("Git found") execute_process( COMMAND ${GIT_EXECUTABLE} describe --always --tags --dirty WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} OUTPUT_VARIABLE GIT_DESCRIBE OUTPUT_STRIP_TRAILING_WHITESPACE ) message("${BoldGreen}Git based version number: ${GIT_DESCRIBE}${ColorReset}") else (GIT_FOUND) set(GIT_DESCRIBE "v0.0.0-unknown") message("${BoldRed}No git installation found. It is highly recommended using git to generate the version number") message("Version is set to: ${GIT_DESCRIBE}${ColorReset}") endif (GIT_FOUND) find_program(VIRTUALENV virtualenv) if (VIRTUALENV) message("Python virtual environment found") execute_process( COMMAND ${VIRTUALENV} venv WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} OUTPUT_QUIET COMMAND_ERROR_IS_FATAL ANY ) set(VENV_BIN "${CMAKE_CURRENT_BINARY_DIR}/venv/bin") execute_process( COMMAND ./pip install -r "${CMAKE_CURRENT_SOURCE_DIR}/crc-patcher/requirements.txt" WORKING_DIRECTORY ${VENV_BIN} OUTPUT_QUIET COMMAND_ERROR_IS_FATAL ANY ) message("${BoldGreen}python virtual environment set up!${ColorReset}") else(VIRTUALENV) message(FATAL_ERROR "${BoldRed}Python virtual environment not set up: virtualenv: command not found!${ColorReset}") endif (VIRTUALENV) set(ELFFILE ${PROJECT_NAME}.elf) set(HEXFILE ${PROJECT_NAME}.hex) set(MAPFILE ${PROJECT_NAME}.map) set(LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/stm32f407vet6_flash.ld) add_compile_options(-Wall -Wextra -Wold-style-declaration -Wuninitialized -Wmaybe-uninitialized -Wunused-parameter) add_compile_options(-mlittle-endian -mthumb -mcpu=cortex-m4 -mthumb-interwork -mfloat-abi=hard -mfpu=fpv4-sp-d16 -nostartfiles -Wimplicit-fallthrough=3 -Wsign-compare) set(GIT_DESCRIBE "${GIT_DESCRIBE}") add_definitions(-DBASE64_LOOKUP_TABLE_SECTION=\".ccm.bss\" -DSHELLMATTA_HELP_ALIAS=\"?\" -DGIT_VER=${GIT_DESCRIBE} -DHSE_VALUE=8000000UL -DSTM32F407xx -DSTM32F4XX -DARM_MATH_CM4) add_subdirectory(doxygen) add_subdirectory(updater/ram-code) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) IF(CMAKE_BUILD_TYPE STREQUAL "Debug") add_definitions(-DDEBUGBUILD) add_compile_options(-O0 -g) add_link_options(-Wl,-Map=${MAPFILE}) ELSE() add_compile_options(-O3 -g) add_link_options(-Wl,--gc-sections) ENDIF(CMAKE_BUILD_TYPE STREQUAL "Debug") if (UART_ON_DEBUG_HEADER) add_definitions(-DUART_ON_DEBUG_HEADER) message("${BoldRed}UART forced to debug header${ColorReset}") endif (UART_ON_DEBUG_HEADER) add_subdirectory(base64-lib) add_subdirectory(linklist-lib) aux_source_directory("." MAIN_SOURCES) aux_source_directory("config-parser" CFG_PARSER_SRCS) aux_source_directory("ui" UI_SRCS) aux_source_directory("fatfs" FAT_SRCS) aux_source_directory("fatfs/shimatta_sdio_driver" SDIO_SRCS) aux_source_directory("boot" BOOT_SRCS) aux_source_directory("setup" SETUP_SRCS) aux_source_directory("stm-periph" STM_PERIPH_SRCS) aux_source_directory("settings" SETTINGS_SRCS) aux_source_directory("safety" SAFETY_SRCS) aux_source_directory("shellmatta/src" SHELLMATTA_SRCS) aux_source_directory("updater" UPDATER_SRCS) aux_source_directory("temp-profile" PROFILE_SRCS) add_executable(${ELFFILE} ${MAIN_SOURCES} ${CFG_PARSER_SRCS} ${UI_SRCS} ${FAT_SRCS} ${SDIO_SRCS} ${BOOT_SRCS} ${SETUP_SRCS} ${STM_PERIPH_SRCS} ${SETTINGS_SRCS} ${SAFETY_SRCS} ${SHELLMATTA_SRCS} ${UPDATER_SRCS} ${PROFILE_SRCS} ) add_dependencies(${ELFFILE} updater-ram-code-header-blob) target_include_directories(${ELFFILE} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/shellmatta/api ${CMAKE_CURRENT_SOURCE_DIR}/config-parser/include) target_link_options(${ELFFILE} PRIVATE -mlittle-endian -mthumb -mcpu=cortex-m4 -mthumb-interwork -mfloat-abi=hard -mfpu=fpv4-sp-d16 --disable-newlib-supplied-syscalls -nostartfiles -T${LINKER_SCRIPT} -Wl,--print-memory-usage) target_link_libraries(${ELFFILE} base64-lib linklist-lib) target_include_directories(${ELFFILE} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/updater/ram-code/include/") add_custom_command( TARGET ${ELFFILE} POST_BUILD COMMAND ./python "${CMAKE_CURRENT_SOURCE_DIR}/crc-patcher/crc-patch-elf.py" "${CMAKE_CURRENT_BINARY_DIR}/${ELFFILE}" WORKING_DIRECTORY ${VENV_BIN} COMMENT "Running Flash CRC Patcher" ) set(HEX_PATH "${CMAKE_CURRENT_BINARY_DIR}/${HEXFILE}") add_custom_target(update-image ALL DEPENDS ${HEX_PATH} "${HEX_PATH}.sha") add_custom_command( DEPENDS ${ELFFILE} OUTPUT ${HEX_PATH} COMMAND ${CMAKE_OBJCOPY} -O ihex ${ELFFILE} ${HEX_PATH} ) add_custom_command( DEPENDS ${HEX_PATH} OUTPUT "${HEX_PATH}.sha" COMMAND sha256sum "${HEX_PATH}" | cut -d " " -f 1 > "${HEX_PATH}.sha" )