Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

Manipulate "Compiler defines" for conditional compile

fh6
2018-05-30
2018-06-20
  • fh6 - 2018-05-30

    Hi,

    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?

    Thanks.

     
  • fh6 - 2018-06-20

    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():
            printtree(obj)
    \# 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","")
    else:
            props.compiler_defines = props.compiler_defines + ";FOOBAR"
    print("--- Script finished. ---")
    
     

Log in to post a comment.