pico-sdk icon indicating copy to clipboard operation
pico-sdk copied to clipboard

How to build when I can't add `pico_sdk_init()` to existing project?

Open parbo opened this issue 2 years ago • 4 comments

Normally, you'd just specify a CMAKE_TOOLCHAIN_FILE when invoking cmake. Why does the Pico SDK require modifying the CMakeLists.txt? Is there another way?

parbo avatar Aug 10 '22 16:08 parbo

I'm not entirely sure what you're asking, but perhaps some of the comments in https://github.com/raspberrypi/pico-feedback/issues/210 will point you in the right direction? (But if they don't, please excuse my ignorance!)

lurch avatar Aug 11 '22 00:08 lurch

Yeah, that's the same problem. For my use-case I can solve it like that. But in general it'd be nice to be able to build third party libraries without modifying them or adding them as submodules to a parent project that pulls in the pico stuff. Feel free to close this if that's not something you want to do.

parbo avatar Aug 12 '22 12:08 parbo

One issue with using CMAKE_TOOLCHAIN_FILE is that the SDK build also builds native tools used by the build (which was deemed easier for the majority of users/platforms). We may revisit this in the future.

Note also that today, libraries that depend on the SDK tend to be INTERFACE libraries (again we may make it easier to build static libraries dependent on the SDK in the future). if however you are building a pre-existing non Pico specifc static library (without pulling it into your project as a submodule), then surely you can just build it. why do you need to do pico_sdk_init() at all?

edit: or is your question... "can we have a CMake toolchain file that sets up the compiler?"

kilograham avatar Aug 12 '22 13:08 kilograham

@parbo I replaced project with a macro to work around this

ooxi avatar Aug 17 '22 18:08 ooxi

@ooxi could you elaborate?

ricardomatias avatar May 21 '23 15:05 ricardomatias

@ricardomatias ultimativly I went another way and just added a conditional call to pico_sdk_init() but what I intended to do was something akin to

macro(project)
    _project(${ARGV})
    pico_sdk_init()
endmacro()

However, this is not recommended. See Do Not Redefine CMake Commands

ooxi avatar May 25 '23 14:05 ooxi

seems like there is a workaround here

kilograham avatar May 26 '23 15:05 kilograham