Running a CMakeLists.txt programmatically

Hi Julia community,

I have a C library that needs to be built with a CMakeLists, but I haven’t figured out how to do that programmatically.

I know that packages like CMakeWrapper and BinDeps. Yet I find the documentation to be a bit lacking and unsuitable to my needs.

I have a build directory, which contains my CMakeLists.txt and a C++ wrapper library so I can call the functions in my library a little easier.
In my /build dir:
CMakeLists.txt:

cmake_minimum_required(VERSION 3.12)
project("My Lib")

include_directories(${CMAKE_CURRENT_SOURCE_DIR})

add_library(my_lib main.cpp main.h)
target_sources(my_lib
  PRIVATE
  main.cpp
  PUBLIC
  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/main.h>
)

find_package(OtherLib CONFIG REQUIRED)

target_link_libraries(
  my_lib
  OtherLib::other_lib
)

in my deps/build.jl I tried something like:

build_dir = string(pwd(), "/build")
build = CMakeBuild(
       srcdir = build_dir,
       builddir = build_dir,
       prefix = "",
       libtarget = ["my_lib"],
       installed_libpath = [build_dir],
       cmake_args = [""],
       targetname = "install"
       )

How do I run my CMakeLists.txt when I add my package?

1 Like

If it’s a C library you are probably looking for GitHub - JuliaPackaging/BinaryBuilder.jl: Binary Dependency Builder for Julia about the C++ wrapper you might look at GitHub - JuliaInterop/CxxWrap.jl: Package to make C++ libraries available in Julia.