Author Topic: Can I substitute variables in a project file?  (Read 2561 times)

Offline alexchen

  • Multiple posting newcomer
  • *
  • Posts: 84
Can I substitute variables in a project file?
« on: January 20, 2019, 11:55:03 pm »
Can I use the same workspace and project files to build the code with different compiler configurations by substituting variables with macros?
For instance, say, I have a workspace, Prog.workspace, that includes a project, A.cbp, and I want to use this to build with normal release build and with Clang address sanitizer.
The file A.cbp, will look like the following.  Can I make the compiler/linker settings for address sanitizer a variable and set them from some kind of variable that can controlled from the workspace?

Thanks for any help.

Alex

===========
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
   <FileVersion major="1" minor="6" />
   <Project>
      <Option title="A" />
      <Option platforms="Unix;" />
      <Option pch_mode="2" />
      <Option compiler="clang" />
      <Build>
         <Target title="Debug64">
            <Option platforms="Unix;" />
            <Option output="$(WORKSPACE_DIR)/$(TARGET_NAME)/A" prefix_auto="1" extension_auto="1" />
            <Option working_dir="" />
            <Option object_output="$(WORKSPACE_DIR)/$(TARGET_NAME)/obj" />
            <Option type="2" />
            <Option compiler="clang" />
            <Option createDefFile="1" />
            <Compiler>
               <Add option="-DDEBUG" />
            </Compiler>
            <Linker>
               <Add option="-Wl,-rpath=$(WORKSPACE_DIR)/$(TARGET_NAME)" />
            </Linker>
         </Target>
         <Target title="Release64">
            <Option platforms="Unix;" />
            <Option output="$(WORKSPACE_DIR)/$(TARGET_NAME)/A" prefix_auto="1" extension_auto="1" />
            <Option working_dir="" />
            <Option object_output="$(WORKSPACE_DIR)/$(TARGET_NAME)/obj" />
            <Option type="2" />
            <Option compiler="clang" />
            <Option createDefFile="1" />
            <Compiler>
               <Add option="-O3" />
            </Compiler>
         </Target>
      </Build>
      <Compiler>
         <Add option="-fsanitize=address" />
         <Add option="-fno-omit-frame-pointer" />

         <Add option="-std=c++11" />
         <Add option="-g" />
         <Add option="-Wall" />
   ....         
         <Add directory="$(PROJECT_DIR)../../Linux/$(TARGET_NAME)/OpenSSL/include" />
      </Compiler>
      <Linker>
         <Add option="-fsanitize=address" />
         <Add directory="$(WORKSPACE_DIR)/$(TARGET_NAME)" />
      </Linker>
   

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Can I substitute variables in a project file?
« Reply #1 on: January 22, 2019, 02:11:33 pm »
No, compilers can not be replaced with variables...

I see two options you can do:
1) Create targets for every compiler in every project (you probably could use scripting to automate this)
2) Use the project options manipulator plugin to replace the compiler every time you want to switch the compiler in every project (probably the easiest and fastest way) The plugin can be started from the plugins menu if you have installed contrib plugins

[edit:]
If you want to add speciffic flags for every compiler number 1) would be the easiest. You probably could also add some wired squirrel script to switch flags according to the selected compiler for number 2)

Offline alexchen

  • Multiple posting newcomer
  • *
  • Posts: 84
Re: Can I substitute variables in a project file?
« Reply #2 on: January 22, 2019, 08:54:53 pm »
Thanks for the tips.
Alex