I've got build script which I use for several projects:
// 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));
}
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:
$(WORKSPACE_DIR)/../bin/$(PROJECT_NAME)-$(VERSION)
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?
For what objects/classes have you tried the method "SetVar" and it failed to work?
http://wiki.codeblocks.org/index.php?title=Scripting_commands (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.
Thanks! Your post solved my problem :) Final solution provided below:
// set build version (global variable):
buildVersion <- "1.0.1";
// generate build options (called by codeblocks while building):
function SetBuildOptions(base)
{
// set value for variable $(VERSION) which is visible in project settings:
base.SetVar(_T("VERSION"),_T(buildVersion),false);
//(...)
}