This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Assign a value to variable before build.



Hi.

I am working with CCS 8.3.1 and v21.6 compiler version, and F28335 microcontroller. 

Is there any way that the compiler, at the start of build, ask you for a variable value and then assign this value to the variable or to an environment variable, and continue the build proccess with this value in the variable?

Thanks.

  • Hello,

    Can you discribe the actual use case in more detail? What is the main goal for this? If you wish to assign a specific value to a variable at run time, you can also pass arguments to main when you run it and one of those arguments can be the value you wish to assign the variable.

    Thanks

    ki

  • Yes, I have a project that can be compiled for different boards. To do that I can change a variable or a #define manually between 5 different options, and then I build the project. It can happen that someone else compiles the project and forgets to put the correct #define. To avoid that I would like there to be a reminder, for example when you build the project automatically appears a message: "Wich is the board model? (Target1, Target2... Target5)" and waits for you to enter the name of the board. When you enter the name assigns this name to the variable or #define and starts the build proccess.

    Thanks.

  • To do that I can change a variable or a #define manually between 5 different options, and then I build the project. 

    One option is to create multiple Build Configurations in the CCS project, where each build configuration has a different #define in the CCS project properties under Build -> C2000 Compiler -> Predefined Symbols.

    Then, to select which board to compile for select the active build configuration.

  • To avoid that I would like there to be a reminder, for example when you build the project automatically appears a message: "Wich is the board model? (Target1, Target2... Target5)" and waits for you to enter the name of the board. When you enter the name assigns this name to the variable or #define and starts the build proccess.

    This is not something natively supported with CCS. I suppose you can experiment with the pre-build steps where you have some custom script executed which can prompt the user and the generate a command file (see section 2.3.2 of the C28x compiler user's guide on the --cmd_file option) with the desired --define option that would get passed to the compiler. But that seems a lot of hassle for this. The other option is to do what Chester suggested and take advantage of multiple build configurarions. That is actually a very common use case for build configurations.

    Thanks

    ki