Author Topic: [solved]individual compiler options per file (not per target/project).  (Read 2891 times)

Offline DJLinux

  • Single posting newcomer
  • *
  • Posts: 2
First sorry about my bad english.
I portet my large project's from make files to *.cbp files.

I can't solve one problem: How i can add a compiler flag (in the *.cbp file) to only one file of an project ?

for example a project has 50 files are all compiled with option -NDEBUG and -O3 but one file of the project needs one extra option.

result while the codeblock project are build:
g++ -DNDEBUG  -IPATH -O3 -c file1.cpp -o file1.o
g++ -DNDEBUG  -IPATH -O3 -c file2.cpp -o file2.o
g++ -DNDEBUG  -IPATH -fno-strict-aliasing  -O3 -c file3.cpp -o file3.o
g++ -DNDEBUG  -IPATH -O3 -c file4.cpp -o file4.o
...

How looks the syntax inside the *.cbp file ?

thank you

DJ

edit: is it something like ?:
Code
<Unit filename="Unix\file3.cpp">
  <Option target="Window_L32" />
  <Option target="Window_L64" />
  <Compiler>
    <Add option="-fno-strict-aliasing" />
  </Compiler>
</Unit>
« Last Edit: January 13, 2015, 05:55:33 pm by DJLinux »

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7591
    • My Best Post
Re: individual compiler flag per file (not per target/project)
« Reply #1 on: January 13, 2015, 05:23:55 pm »
My educated guess is you need to do this on the File Properties.
Under the advanced tab and checkmark "Use custom command to build file"

Code
$compiler -fno-strict-aliasing $options $includes -c $file -o $object
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline DJLinux

  • Single posting newcomer
  • *
  • Posts: 2
Re: individual compiler flag per file (not per target/project)
« Reply #2 on: January 13, 2015, 05:54:55 pm »
@stahta01 Thank you now I can generate *.cbp files via scripts.

DJ
Code
<Unit filename="file3.cpp">
  <Option compiler="gnu_gcc_compiler_i686_w64" use="1" buildCommand="$compiler -fno-strict-aliasing $options $includes -c $file -o $object" />
</Unit>