Saturday, 3 April 2021

Build C library with CMakeLists.txt while packaging python library

I use Cython to wrap C library and extend its functionality. C library is developed by separate team and is provided with CMakeLists.txt. For now I use source .c and .h files to build this library. This is how my build.py file for poetry (setup.py analog) looks like:

...
# source_files_paths - list of full paths to .c files
c_library = ('c_library', {'sources': source_files_paths})
...
def build(setup_kwargs):
    setup_kwargs.update({
        ...,
        'libraries': [c_library],  # Here c library is built with build_clib command
        ...
    })

Is it possible to use CMakeLists.txt to build c_library in build function (or in setuptools.setup function)?

UPD: It is also ok for me to define variable that is used in .c files. I tried to add define_macros:

c_library = ('c_library', {'sources': source_files_paths,
                           'define_macros': [('MY_MACRO': True)]})

Still no luck with it.

UPD2: I finally found the solution to my problem though it is not the answer to my initial question. To add macros you should add it in this way:

c_library = ('c_library', {'sources': source_files_paths,
                           'macros': [('MY_MACRO': True)]})

According to build_libraries function from http://svn.python.org/projects/python/branches/pep-0384/Lib/distutils/command/build_clib.py you can also specify 'include_dirs', 'obj_deps' and 'cflags' arguments.



from Build C library with CMakeLists.txt while packaging python library

No comments:

Post a Comment