User forums > Using Code::Blocks
[Squirrel] How to set variable value visible in project?
DejaVu:
I've got build script which I use for several projects:
--- Code: ---// set build version (global variable):
buildVersion <- "1.0.0";
// generate build options (called by codeblocks while building):
function SetBuildOptions(base)
{
// enable all warnings:
base.AddCompilerOption(_T("-Wall"));
// enable C++11 standard:
base.AddCompilerOption(_T("-std=c++11"));
// set directory with libraries:
base.AddLibDir(_T("$(WORKSPACE_DIR)/../_tmp_/$(TARGET_NAME)-libs/"));
// set macro with version number:
local macroVersion = "-DBUILD_VERSION=\"" + buildVersion + "\"";
base.AddCompilerOption(_T(macroVersion));
}
--- End code ---
I would like to set VERSION variable which will be visible in Project Options/Build Targets/Output Filename. Currently I have 'Output filename' set to value:
--- Code: ---$(WORKSPACE_DIR)/../bin/$(PROJECT_NAME)-$(VERSION)
--- End code ---
Currently output file name doesn't contain $(VERSION) because variable is not set. I have tried to create global variable in build script but it didn't work. I have also spent few hours on looking solution in Google, but I didn't find solution for this issue.
Question: How to set environment variable from build script which will be visible in project settings?
stahta01:
--- Code: ---$(VERSION)
--- End code ---
Do you want to use a CB Global variable or a CB custom variable?
Because your post seems to NOT clearly state which you want to use!
I know scripts can be used to create a CB custom variable; I have no idea if this is true for CB Global variables.
I also am NOT sure if environment variables are able to be created by scripting.
I would guess NOT because it likely would be a major security hole.
Tim S.
DejaVu:
I don't care if variable will be global or local. All what I want to achieve is to create variable from build script which will be visible by Code::Blocks in project settings.
1. I don't want to declare any variable in GLOBAL IDE SETTINGS (solution must be portable via reposittory);
2. I don't want to declare any variable via Project Build Options/Custom Variables, because this variable is visible only per project;
3. I want to declare variable by build script, because all projects are using the same build script and changing version in one place will affect to all projects.
stahta01:
For what objects/classes have you tried the method "SetVar" and it failed to work?
http://wiki.codeblocks.org/index.php?title=Scripting_commands
It worked for me in the past to set a CB custom variable at the target level.
I never figured out if setting one at the project level was possible.
Edit: I have never used SetBuildOptions script before; I have just edited CB wizards.
Edit2: I am guessing you will need to call "GetParentProject"
Tim S.
stahta01:
I just thought of a simpler solution if you fail to get the build script to work.
Just create a CB Project template with the value of the CB Custom variable set in there to the default value.
If that not good enough, the only other thing I know to try after the build script fails is to create a CB project wizard.
Tim S.
Navigation
[0] Message Index
[#] Next page
Go to full version