Developer forums (C::B DEVELOPMENT STRICTLY!) > Plugins development

Compiler/Linker variables

<< < (2/2)

tiwag:
i also have similar needs as killerbot and tried to define a custom variable named <target> for each target with a different string, in the hope, that when i use the custom variable $(target) i'd get the appropriate string related to the actual selected target,
and use it in the output file, object dir and deps-dir settings.

you see the idea best when looking into the project file...
--- Code: ---<?xml version="1.0"?>
<!DOCTYPE CodeBlocks_project_file>
<CodeBlocks_project_file>
<FileVersion major="1" minor="1"/>
<Project>
<Option title="Target test"/>
<Option makefile="Makefile"/>
<Option makefile_is_custom="0"/>
<Option pch_mode="2"/>
<Option active_target="0"/>
<Option compiler="0"/>
<Build>
<Target title="target1">
<Option output="wxapp_$(target).exe"/>
<Option working_dir="."/>
<Option object_output=".objs_$(target)"/>
<Option deps_output=".deps_$(target)"/>
<Option type="0"/>
<Option compiler="0"/>
<Option projectResourceIncludeDirsRelation="0"/>
<Environment>
<Variable name="target" value="T1"/>
</Environment>
</Target>
<Target title="target2">
<Option output="wxapp_$(target).exe"/>
<Option working_dir="."/>
<Option object_output=".objs_$(target)"/>
<Option deps_output=".deps_$(target)"/>
<Option type="0"/>
<Option compiler="0"/>
<Option projectResourceIncludeDirsRelation="0"/>
<Environment>
<Variable name="target" value="T2"/>
</Environment>
</Target>
<Target title="target3">
<Option output="wxapp_$(target).exe"/>
<Option working_dir="."/>
<Option object_output=".objs_$(target)"/>
<Option deps_output=".deps_$(target)"/>
<Option type="0"/>
<Option compiler="0"/>
<Option projectResourceIncludeDirsRelation="0"/>
<Environment>
<Variable name="target" value="T3"/>
</Environment>
</Target>
<Environment>
<Variable name="WX_DIR" value="d:\wx261"/>
<Variable name="WX_CFG" value=""/>
</Environment>
</Build>
<Compiler>
<Add option="-pipe"/>
<Add option="-mthreads"/>
<Add option="-Winvalid-pch"/>
<Add option="-include &quot;wx_pch.h&quot;"/>
<Add option="-D__GNUWIN32__"/>
<Add option="-D__WXMSW__"/>
<Add option="-DWXUSINGDLL"/>
<Add option="-DUSE_PCH"/>
<Add directory="$(WX_DIR)\include"/>
<Add directory="$(WX_DIR)\lib\gcc_dll$(WX_CFG)\msw"/>
<Add directory="$(WX_DIR)\contrib\include"/>
</Compiler>
<ResourceCompiler>
<Add directory="$(WX_DIR)\include"/>
</ResourceCompiler>
<Linker>
<Add library="wxmsw26"/>
<Add directory="$(WX_DIR)\lib\gcc_dll$(WX_CFG)"/>
</Linker>
<Unit filename="main.cpp">
<Option compilerVar="CPP"/>
<Option target="target1"/>
<Option target="target2"/>
<Option target="target3"/>
</Unit>
<Unit filename="main.h">
<Option compilerVar=""/>
<Option compile="0"/>
<Option link="0"/>
<Option target="target1"/>
<Option target="target2"/>
<Option target="target3"/>
</Unit>
<Unit filename="wx_pch.h">
<Option compilerVar="CPP"/>
<Option link="0"/>
<Option weight="0"/>
<Option target="target1"/>
<Option target="target2"/>
<Option target="target3"/>
</Unit>
</Project>
</CodeBlocks_project_file>
--- End code ---


this approach almost works, when the custom variable <target> isn't defined at project level but only at target levels,
but the target-dependency of this custom variable is somehow scrambled.

* when i build target1, $(target) is set to "T3",

--- Code: ---Project   : Target test
Compiler  : GNU GCC Compiler (called directly)
Directory : D:\cpp\_projects\CodeBlocks\TESTS\target_test\
--------------------------------------------------------------------------------
Switching to target: target1
mingw32-g++.exe   -pipe -mthreads -Winvalid-pch -include "wx_pch.h" -D__GNUWIN32__ -D__WXMSW__ -DWXUSINGDLL -DUSE_PCH    -Id:\wx261\include -Id:\wx261\lib\gcc_dll\msw -Id:\wx261\contrib\include  -c main.cpp -o .objs_T3\main.o
mingw32-g++.exe   -Ld:\wx261\lib\gcc_dll  -o wxapp_T3.exe .objs_T3\main.o        -lwxmsw26  -mwindows
Process terminated with status 0 (0 minutes, 0 seconds)
0 errors, 0 warnings
--- End code ---


* when i build target2, $(target) is set to "T1",

--- Code: ---Project   : Target test
Compiler  : GNU GCC Compiler (called directly)
Directory : D:\cpp\_projects\CodeBlocks\TESTS\target_test\
--------------------------------------------------------------------------------
Switching to target: target2
mingw32-g++.exe   -pipe -mthreads -Winvalid-pch -include "wx_pch.h" -D__GNUWIN32__ -D__WXMSW__ -DWXUSINGDLL -DUSE_PCH    -Id:\wx261\include -Id:\wx261\lib\gcc_dll\msw -Id:\wx261\contrib\include  -c main.cpp -o .objs_T1\main.o
mingw32-g++.exe   -Ld:\wx261\lib\gcc_dll  -o wxapp_T1.exe .objs_T1\main.o        -lwxmsw26  -mwindows
Process terminated with status 0 (0 minutes, 0 seconds)
0 errors, 0 warnings
--- End code ---


and finally

* when i build target3, $(target) is set to "T2"

--- Code: ---Project   : Target test
Compiler  : GNU GCC Compiler (called directly)
Directory : D:\cpp\_projects\CodeBlocks\TESTS\target_test\
--------------------------------------------------------------------------------
Switching to target: target3
mingw32-g++.exe   -pipe -mthreads -Winvalid-pch -include "wx_pch.h" -D__GNUWIN32__ -D__WXMSW__ -DWXUSINGDLL -DUSE_PCH    -Id:\wx261\include -Id:\wx261\lib\gcc_dll\msw -Id:\wx261\contrib\include  -c main.cpp -o .objs_T2\main.o
mingw32-g++.exe   -Ld:\wx261\lib\gcc_dll  -o wxapp_T2.exe .objs_T2\main.o        -lwxmsw26  -mwindows
Process terminated with status 0 (0 minutes, 0 seconds)
0 errors, 0 warnings
--- End code ---

when i select  build target All, $(target) is set to "" (blank)

 :)


attached is the project, if someone wants to test with it.

[attachment deleted by admin]

killerbot:
Thomas,


You lost me, don't understand the difference betwen the 2 things you are saying.  :oops:

Every target you build has a name, that name is known in the cbp file, there it has been specified.

Now when the build starts, there are variables that can be used by the compile, the linker, etc ...
Most of them are listed on the "Compiler Settings->Other tab -> Advanced Options -> Commands tab", if possible it would be of great help to have for example $(target)
Example from a cbp :
         <Target title="default">
         <Target title="dmc">

So for example I could specify for compiler x :  not using the target variable

$compiler $options $includes -c $file -o $object

for compiler y :
$compiler $options $includes -c $file -fr"$(target)blablablabla"

for compiler z:
$compiler $options $includes -c $file -o $object -myoption=$(target)

where I get's replaced for example by default, or by dmc, ...


I hope this falls under the "really easy" part you are mentioning.

kind regards,
Lieven

thomas:
What I meant with "really easy" was accessing that kind of information from cbCompilerPlugin or from Compiler. Providing it as a compiler variable is rather complicated, because you don't have that information at this time.

But don't worry, there's a workaround. The build target will soon be supported as a plain normal compiler variable, too. cbProject gets a new function to query the currently compiling target, and this is read by the macro manager to provide this information in a $(VARIABLE).
The information in cbProject is updated each time the compiler switches build targets in its run queue.
So much for the theory... I have it implemented so far, but updating on target switch alone seems not enough (it works after the 2nd build, but not before). I tried for a while, but ran out of ideas at some point.

Since tiwag has personal interest in the matter, too, I sent him the patch for review. He will very likely find the piece that is missing, and then we're set. :)

killerbot:
wonderfull news.

Time I learn to build CB from cvs, so I can test it once it is checked in ...

tiwag:

--- Quote from: thomas on November 04, 2005, 12:22:20 am ---...Since tiwag has personal interest in the matter, too, I sent him the patch for review. He will very likely find the piece that is missing, and then we're set. :)

--- End quote ---
i'll try to find time to look at it - but please don't be too optimistic - at the moment i've soo much troubles at work that i don't have any free time. It's a kind of short-time vacation when i look for 15 minutes into this forum and read a few articles - so please don't be disappointed if i can't respond with some solution very fast at the moment.

Navigation

[0] Message Index

[*] Previous page

Go to full version