Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 5273

SDK • Defining C defines at the "cmake .." stage

$
0
0
I'd like to build different executables from the same source. Not much different but for a single define.

Imagine my project having a Launchpad.c, a build-LP1 directory, and a build-LP2 directory. I'd go to build-LP1 and run "cmake .. -DNODENAME=LP1" there and then goto build-LP2 and run "cmake .. -DNODENAME=LP2". Well, this dies not work, as cmake complains "Manually-specified variables were not used by the project: NODENAME". What I had hoped in my attempt is that this -DNODENAME would somehow make its way into the Makefile so I could access the NODENAME definition in my code.

Is there a way for me to get a definition from the cmake command line via the Makefile into my C source as a macro? I'd really, really would like to avoid hacking into of the generated files, because they can look totally different with the next version of whatever tool they generated it. And then I'd be back to the drawing board. Apart from this, that Makefile is nearly 2000 lines long! For a simple, one-source "Hello, World!"! - Who the heck thinks this is a good idea?

The very idea of this is that the code is identical across a number of executables in my project, apart from the NODENAME macro that the controller uses as a call sign. I could have a "master Makefile" walking through all build directories and re-create all images that need recreation, and download the image file from build-LP1 into the "Launchpad 1" board and the image from build-LP2 into the "Lauchpad 2" board.

Statistics: Posted by ChTreczoks — Tue Jul 16, 2024 11:54 am



Viewing all articles
Browse latest Browse all 5273

Trending Articles