How to create dynamic lib of `libgit2` using CMake

First of all I have no experience with c and its ecosystem so the questions I ask could be too basic.

I am trying to create dart bindings for libgit2. To do that I have to create dynamic library. I followed the steps from the Official documentation (dart .dev/guides/libraries/c-interop)

discourse .cmake .org is not allowing to post more than two links, thats why above text is not link

This repo nivekithan/git2dart contains my effort on creating dynamic library.

Before posting here I have also asked the same question in stack-overflow (stackoverflow .com/questions/67505823/cmake-is-not-making-makefile?noredirect=1#67507666)

I will repeat the content in stackoverflow here also

I am trying to create dynamic library in windows. I followed the instruction in (github .com/dart-lang/samples/tree/master/ffi).

This is my CMakelists.txt

cmake_minimum_required(VERSION 3.20.2 FATAL_ERROR)
project(libgit VERSION 1.0.0 LANGUAGES C)
add_library(libgit SHARED git2.h)

set_target_properties(libgit PROPERTIES
    PUBLIC_HEADER git2dart.h
    OUTPUT_NAME "git2dart"

You can clone the repo using in gh repo clone nivekithan/git2dart

You will find the CMakeFiles.txt in the directory libgit2.

If I were run cmake . from this directory then I would get this message

 Building for: Visual Studio 16 2019
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.21376.
-- The C compiler identification is MSVC 19.28.29914.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.28.29910/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/nivek/Documents/work/git2dart/libgit2

But then If I were to run make I would get this message

make: *** No targets specified and no makefile found.  Stop.

Thanks for the help

Right now your libgit only has a single source: git2.h. CMake recognizes this as a header file and thus doesn’t compile it. You need to add additional .c/.cpp/.cxx/whatever sources.

I copied the code from include directory from libgit2 . It only contains .h files. The .c files are in directory src if I were to copy those then what should I mention in add_libary(libgit SHARED <????>) there is no git2.c file

Let me back up a second… are you trying to build all of libgit2 from source, and add Dart bindings on top of that, or are you trying to use a pre-built version of libgit2 and add Dart bindings to that?

I dont know. As I said I am not entirely familiar with c ecosystem and this is my first building a binding library. So I am not entirely sure.

maybe this could be helpful C interop using dart:ffi | Dart, I am not sure though