Pass CFLAGS, -DSOME_VAR=7, etc. via particle compile?

Is there is a way to pass CFLAGS, -D etc to the preprocessor but from the particle compile ... build process?

I would like to define a few things at compile time, but don’t yet (I will eventually) want to invest in setting up my local non-CLI pipeline.

I see no mention of this capability in the CLI Documentation, nor other places in the forum, but am hoping it may exist nonetheless.

Thanks!

Hey @laughlin,

I don’t think you can pass additional flags to the cloud compiler, but you can do it locally by setting the EXTRA_CFLAGS environment variable.


If you’re looking for a premade solution you may be interested in neopo, an unofficial toolchain management utility compatible with Particle Workbench and Particle CLI projects that I maintain.

Neopo makes it incredibly simple to download and use the Particle toolchains to locally create, build, and flash Particle projects while providing many additional features. (It also facilitates the usage of Particle Workbench on unsupported Linux distributions.)

The following is an example of using neopo to create a project, set EXTRA_CFLAGS, and then build the project, downloading toolchains on the fly if necessary:

$ neopo create myProject boron 2.0.1
$ cd myProject
$ neopo flags "-DSOME_VAR=7"
$ neopo compile

I keep the man page (available online) and the neopo help text up to date. If you face any problems while using neopo, feel free to open an issue on the GitHub repo, or message me here on the Particle forums.

To get quick help for a neopo command you can use the help command in a similar way to Particle CLI. For example, to get help on the compile command:

$ neopo help compile
Compile the current or specified project locally
Usage: neopo compile [project] [verbosity]

Options:
  -v	Verbose compiler output
  -q	Quiet compiler output
1 Like

Thanks for the tip @nrobinson2000. I’ll give neopo a look, but looks like setting that env var might be just the ticket for the small compile-time flags I wish to set.

Cheers!

1 Like

You might be interested in the neopo export command, which will produce a shell script of the build process:

$ neopo export compile-user
Exported to /home/nrobinson/code/neopo/test/bin/neopo-compile-user.sh
#!/bin/bash
PATH="$PATH:/home/nrobinson/.particle/toolchains/gcc-arm/9.2.1/bin:/home/nrobinson/.particle/toolchains/buildtools/1.1.1"

make -f /home/nrobinson/.particle/toolchains/buildscripts/1.10.0/Makefile PARTICLE_CLI_PATH=/home/nrobinson/.neopo/particle -s APPDIR=/home/nrobinson/code/neopo/test DEVICE_OS_PATH=/home/nrobinson/.particle/toolchains/deviceOS/2.0.1 PLATFORM=photon EXTRA_CFLAGS= compile-user