Skip to content

kryochronic/c_source_tools

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build System wrapper for Cmake aka c_source_tools


🆕 Update as on 2024 March

Have also added support for a building for AVR, using CMAKE + IAR toolchain + Micruim's ucOS-II. Will Publish an example for the same.

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


Cmake Generator Source Core in Python.

This software can be used to generate a Cmake Make include file(args['CmakeIncludes']) suitable for importing into the main(root)
CmakeLists.txt with the following features:

  • Exclude file / folders as per exclude list paths
  • install header search paths as configured in arguments args[application_libraries] add add_library directive as configured in the arguments for each subfolder,
    • recursively add each (sub)-subfolder via subdirs if it contains Source
      files as specified by args['pattern']
    • Automatically generate the Library name & add all files in (sub)-subfolder
      to the subfolder named library name basis path
    • add a CmakeLists.txt into the folder for each listed (sub)-subfolder
    • ignores files / paths as specified in argument via args['exclude']
    • add target_compile_definitions for directory specific files
    • Link all the included subfolders via target_link_libraries directives

Table of Contents for c_source_tools

Arguments Keyword Glossary

Key word type Description Quick Example
root path Root of the Project.
All paths are relative to this
c-flags [] Tokens to be defined with '-D'
prefix string Unused
application_libs {} Include Paths to include with -I
suf path Unused
pattern [] Pattern of files to look for
headers [] Extension of Header files, so as to not add to the Cmake add_sources directive
sources [] Extension of Header files, so as to add to the Cmake add_sources directive
exclude [] Patterns to ignore in the path
CmakeIncludes string Name of the file to generate
subfolders [] Target include folders to parse for files as per 'pattern'
Format of sublist:
* folder:required
* #defines: optional

Arguments in detail

root - Directory Start Point

Defined by the keyword root

c-flags - Application wide Complie Flags

These are global symbols, same formart as on the commandline with a -D

Example in use

Have a look around in the AM335X-FreeRTOS-lwip to use the c_source_tools

Example Arguments dict for the AM335x(Click to Expand)

def make_args(root=None, subfolders=None) -> dict:
    import os
    args = {}
    
    if root is None:
        root = os.getcwd()
    args['application_libs'] = {
        'lwip':             [
            'amazon-freertos/lib/third_party/lwip',
        ],
        'ti_starterware':   [
            'ti_starterware/include',
        ],
        'application':      [
            'src',
        ],
        'aws':              [
            'amazon-freertos/lib/include',
            'amazon-freertos/lib/include/private',
        ],
    }
    args['suf'] = ''
    args['pattern'] = ['*.c', '*.h', '*.S']
    args['exclude'] = [
        # path to exclude
        'binary',
        'fatfs/port',
        # File names to ignore
        'some_specific_c_file.c',
    ]

    args['root'] = root
    # the name of the CMAKE INCLUDE FILE to generate
    args['CmakeIncludes'] = "ProjectIncludes.cmake"
    if subfolders is None:
        args['subfolders'] = [  # a list in the form of [['path/to/traverse','FLAGS NEEDED'],]
            ['some/thirdparty/lib/drivers', '-DBOOT=MMCSD -DCONSOLE=UARTCONSOLE'],
            ['src', '-DBOOT=MMCSD -DCONSOLE=UARTCONSOLE'],
            ['another/thirdparty/lib/bufferpool'],
            ['yet/another/lib/OSetc'],
            ['yet/another/lib/some/subfolder'],
        ]
    return args


🚧 Requirements to be added

Key word type Quick Example
asm_source_ext string args['asm_source_ext'] = ['*.s']
args['asm_source_ext'] = ['*.s','*.s90','*.S']
app_targets list Under Dev

🚧 Multiple Targets

For a Project P1 and a library L1 and a target 'T1', c_source_tools will generate a Target Library definition with the name 'L1.T1' for Target '${PROJECT}.T1' Example below:

add_library(L1.+3V+LIC+IRR "")
target_compile_options(L1.+3V+LIC+IRR PUBLIC "--preinclude \"${PROJECT_SOURCE_DIR}/+3V-IRR-LIC.txt\"")
add_target(${PROJECT}.+3V+LIC+IRR)

Format required in c_source_tools args file as below:

Key word type Quick Example
app_targets list of dicts { 'app_targets' : [{ 'T1' : { 'TYPE':'PUBLIC' } , { 'FLAGS':['List','of','Target','Options'] } }]

An Example in for usage!

{ 
  'app_targets' : [{ 
    '+3V+LIC+IRR' : {
      'TYPE':'PUBLIC',
      'FLAGS':['--preinclude ${PROJECT_SOURCE_DIR}/+3V-IRR-LIC.txt']
    }
  }]
}
  

🚧 Assembler Source Separation

Flags are needed for separating the Assembler files from C Files as the IAR compiler, unlike GCC, does not invoke the assembler. Hence let assembler files be compiled into another library all together.

About

python based cmake tools for C Sources

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages