CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum by 3S-Smart Software Solutions GmbH | A member of the CODESYS Group
Deutsche Version English version russian version 
It is currently Tue Aug 20, 2019 1:38 pm

All times are UTC+01:00

Post new topic  Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Wed May 30, 2018 10:46 am 
User avatar

Joined: Mon Jan 16, 2017 3:10 pm
Posts: 8

is it possible to manipulate (read-modify-write) the compiler arguments (aka "Compiler defines") of an object?
How can I set global compiler arguments for the current project?


PostPosted: Wed Jun 20, 2018 8:55 am 
User avatar

Joined: Mon Jan 16, 2017 3:10 pm
Posts: 8
Yes it is possible. Here the example code of 3S.

# Prints out all devices in the currently open project
# and manipulates the compiler defines in the VICTIM object.

# We enable the new python 3 print syntax
from __future__ import print_function

# define the printing function
def printtree(treeobj, depth=0):
    name = treeobj.get_name(False)
    print("{0}- {1} {2} {3}".format("--"*depth, name, treeobj.effectively_excluded_from_build, treeobj.exclusion_from_build_is_inherited))
    props = treeobj.build_properties;
    if props:
        print("{0}  + {1} {2} {3}".format("--"*depth, "external", props.external_is_valid, props.external_is_valid and props.external))
        print("{0}  + {1} {2} {3}".format("--"*depth, "enable_system_call", props.enable_system_call_is_valid, props.enable_system_call_is_valid and props.enable_system_call))
        print("{0}  + {1} {2} {3}".format("--"*depth, "compiler_defines", props.compiler_defines_is_valid, props.compiler_defines_is_valid and props.compiler_defines))
        print("{0}  + {1} {2} {3}".format("--"*depth, "link_always", props.link_always_is_valid, props.link_always_is_valid and props.link_always))
        print("{0}  + {1} {2} {3}".format("--"*depth, "exclude_from_build", props.exclude_from_build_is_valid, props.exclude_from_build_is_valid and props.exclude_from_build))
    for child in treeobj.get_children(False):
        printtree(child, depth+1)

for obj in projects.primary.get_children():

# Find Object VICTIM in projecttree
victim = projects.primary.find("VICTIM", True)[0]
props = victim.build_properties

props.external = not props.external
props.enable_system_call = not props.enable_system_call
props.link_always = not props.link_always
props.exclude_from_build = not props.exclude_from_build
if ";FOOBAR" in props.compiler_defines:
        props.compiler_defines = props.compiler_defines.replace(";FOOBAR","")
        props.compiler_defines = props.compiler_defines + ";FOOBAR"

print("--- Script finished. ---")

Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 2 posts ] 

All times are UTC+01:00

Who is online

Users browsing this forum: No registered users and 2 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited