|
| 1 | +# Copyright (c) 2022 Mr. Green's Workshop https://www.MrGreensWorkshop.com |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +# Set minimum CMake version |
| 5 | +cmake_minimum_required(VERSION 3.17) |
| 6 | + |
| 7 | +# Include the subsidiary .cmake file to get the SDK |
| 8 | +include($ENV{PICO_SDK_PATH}/external/pico_sdk_import.cmake) |
| 9 | + |
| 10 | +# Set the name and version of the project |
| 11 | +project(PicoBiosPostCodeReader VERSION 1.0.0) |
| 12 | + |
| 13 | +# Set top source code folder |
| 14 | +set(SOURCE_FOLDER "src") |
| 15 | + |
| 16 | +# Set build type (options: 'Debug', 'Release', 'MinSizeRel', 'RelWithDebInfo') |
| 17 | +set(default_build_type "Release") |
| 18 | + |
| 19 | +# Set CMAKE_BUILD_TYPE |
| 20 | +set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE STRING "Choose the type of build, options are: 'Debug', 'Release', 'MinSizeRel', 'RelWithDebInfo'." FORCE) |
| 21 | + |
| 22 | +# Initialize the SDK |
| 23 | +pico_sdk_init() |
| 24 | + |
| 25 | +# Add an executable target for the project |
| 26 | +add_executable(${PROJECT_NAME}) |
| 27 | + |
| 28 | +# Get all the pio files, when the glob value changes, cmake will run again and update the files |
| 29 | +file(GLOB_RECURSE pio_src CONFIGURE_DEPENDS "${SOURCE_FOLDER}/*.pio") |
| 30 | + |
| 31 | +# Convert List to String |
| 32 | +STRING(REPLACE ";" "\n" PIO_SRC_STR "${pio_src}") |
| 33 | + |
| 34 | +# Print the pio source file list |
| 35 | +message(STATUS "PIO code source files: \n${PIO_SRC_STR}") |
| 36 | + |
| 37 | +# If there are any PIO source files, include them to the build. |
| 38 | +if (NOT pio_src STREQUAL "") |
| 39 | + pico_generate_pio_header(${PROJECT_NAME} ${pio_src}) |
| 40 | +endif() |
| 41 | + |
| 42 | +# Get all C and C++ files, when the glob value changes, cmake will run again and update the files |
| 43 | +file(GLOB_RECURSE app_src CONFIGURE_DEPENDS "${SOURCE_FOLDER}/*.c" "${SOURCE_FOLDER}/*.cpp" ) |
| 44 | + |
| 45 | +# Convert List to String |
| 46 | +STRING(REPLACE ";" "\n" APP_SRC_STR "${app_src}") |
| 47 | + |
| 48 | +# Print the C and C++ source file list |
| 49 | +message(STATUS "C and C++ source files: \n${APP_SRC_STR}") |
| 50 | + |
| 51 | +# Add C and C++ source files to the build |
| 52 | +target_sources(${PROJECT_NAME} PRIVATE ${app_src}) |
| 53 | + |
| 54 | +# Link the Project to extra libraries |
| 55 | +target_link_libraries(${PROJECT_NAME} PRIVATE |
| 56 | + pico_stdlib |
| 57 | + hardware_pio |
| 58 | +) |
| 59 | + |
| 60 | +# Including header files directly from project directory |
| 61 | +target_include_directories(${PROJECT_NAME} PRIVATE |
| 62 | + ${CMAKE_CURRENT_LIST_DIR} |
| 63 | +) |
| 64 | + |
| 65 | +# Export binaries like hex, bin, and uf2 files. |
| 66 | +pico_add_extra_outputs(${PROJECT_NAME}) |
| 67 | + |
| 68 | +# Enable or Disable UART |
| 69 | +pico_enable_stdio_uart(${PROJECT_NAME} 0) |
| 70 | + |
| 71 | +# Enable or Disable USB CDC |
| 72 | +pico_enable_stdio_usb(${PROJECT_NAME} 1) |
| 73 | + |
| 74 | +# Disable DTR check for USB CDC connection |
| 75 | +add_definitions(-DPICO_STDIO_USB_CONNECTION_WITHOUT_DTR=1) |
| 76 | + |
| 77 | +# Set USB device as self powered device |
| 78 | +#add_definitions(-DPICO_STDIO_USB_DEVICE_SELF_POWERED=1) |
0 commit comments