element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Embedded and Microcontrollers
  • Technologies
  • More
Embedded and Microcontrollers
Blog CMake: a MACRO can simplify your Pico build
  • Blog
  • Forum
  • Documents
  • Quiz
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Embedded and Microcontrollers to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Jan Cumps
  • Date Created: 27 Aug 2024 12:45 PM Date Created
  • Views 955 views
  • Likes 11 likes
  • Comments 15 comments
  • raspberry
  • pico
  • cmake
  • vscode
  • teseo_c++
Related
Recommended

CMake: a MACRO can simplify your Pico build

Jan Cumps
Jan Cumps
27 Aug 2024

The Pico C/C++ SDK, and its examples, make extensive use of CMake. If you develop projects that use the same principles, you 'll be familiar with the CMake configuration file  CMakeList.txt.

A simple project, that builds a single firmware and relies on the SDK API only, will have a straightforward CMake config file. If your project builds more than one deliverable, the file can get big. You may end up with (almost identical) repeating sections. In that case, a macro can help to keep this manageable. And to maintain integrity of the build when making changes later.

My project C++ library for ST Teseo GPS builds 3 different firmware binaries, and each of them has a UART and I2C version. I used a macro to keep the CMake configuration doable

A CMake macro is very similar to the C parameterised macro. During the project configuration, each declaration that uses the macro, will be expanded. The values used will replace the macro parameters.

Here is my firmware build macro:

# macro to build firmware binary for the examples
macro(__build_firmware example protocol)
message("building firmware for example ${example}, protocol ${protocol}")

add_executable(${CMAKE_PROJECT_NAME}_${example}_${protocol}
        ${CMAKE_CURRENT_SOURCE_DIR}/teseo_${example}.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/gps_nmea_lib/nmea/nmea.cpp       
)

target_link_libraries(${CMAKE_PROJECT_NAME}_${example}_${protocol} 
        ${CMAKE_PROJECT_NAME}_shared_${protocol}
)

target_include_directories(${CMAKE_PROJECT_NAME}_${example}_${protocol} PUBLIC 
${CMAKE_CURRENT_SOURCE_DIR}/gps_nmea_lib/nmea
)

# select the debug output (optional, not used by the GPS interface)
pico_enable_stdio_uart(${CMAKE_PROJECT_NAME}_${example}_${protocol} 1)
pico_enable_stdio_usb(${CMAKE_PROJECT_NAME}_${example}_${protocol} 0)

pico_add_extra_outputs(${CMAKE_PROJECT_NAME}_${example}_${protocol} )

endmacro()

The parameters are example and protocol.

Here is the code to build one of the 3 firmware binaries, for both their UART and I2C variant:

# build teseo reply response example --------------------------------------

__build_firmware("reply_response" "uart")

__build_firmware("reply_response" "i2c")

I repeated this for each of the examples. The outcome is that a build all nicely creates all binaries:

building firmware for example reply_response, protocol uart
building firmware for example reply_response, protocol i2c
building firmware for example with_nmea_parse, protocol uart
building firmware for example with_nmea_parse, protocol i2c
building firmware for example nmea_with_data_processing, protocol uart
building firmware for example nmea_with_data_processing, protocol i2c
-rw-r--r-- 1 runner docker 161280 Aug 26 16:31 build/pico_gps_teseo_reply_response_uart.uf2
-rw-r--r-- 1 runner docker 161280 Aug 26 16:31 build/pico_gps_teseo_reply_response_i2c.uf2
-rw-r--r-- 1 runner docker 198144 Aug 26 16:31 build/pico_gps_teseo_with_nmea_parse_uart.uf2
-rw-r--r-- 1 runner docker 198144 Aug 26 16:31 build/pico_gps_teseo_with_nmea_parse_i2c.uf2
-rw-r--r-- 1 runner docker 195584 Aug 26 16:32 build/pico_gps_teseo_nmea_with_data_processing_uart.uf2
-rw-r--r-- 1 runner docker 195584 Aug 26 16:32 build/pico_gps_teseo_nmea_with_data_processing_i2c.uf2

This is one example of how macros can help. Further reading: https://cmake.org/cmake/help/latest/command/macro.html.

Link to all posts.

  • Sign in to reply
  • Jan Cumps
    Jan Cumps 13 days ago in reply to Jan Cumps

    meanwhile I purchased a few Pico 2s, and the multicore FreeRTOS runs perfectly on the RISCVs:  RE: bought a set of Pico 2 

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps 10 months ago in reply to scottiebabe

    found it!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • scottiebabe
    scottiebabe 10 months ago in reply to Jan Cumps

    Do you have a show/hide button

    image

    On windows I have v0.15.2

    image

    I just used the version listed in vs code available extensions which turns out to be the latest

    https://github.com/raspberrypi/pico-vscode 

    On a PI4 I can't get the VSiX to install...

    image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps 10 months ago in reply to scottiebabe

    Do you use a nightly release? I don't see that option.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • scottiebabe
    scottiebabe 10 months ago in reply to Jan Cumps

    Yes its not as easy to switch in an existing project

    image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube