# Running a CMakeLists.txt programmatically

**URL:** <https://discourse.julialang.org/t/running-a-cmakelists-txt-programmatically/69238>\
**Category:** New to Julia\
**Tags:** c\
**Created:** [October 5, 2021, 2:25pm UTC](https://discourse.julialang.org/t/running-a-cmakelists-txt-programmatically/69238 "2021-10-05T14:25:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![MitchellWeg](https://avatars.discourse-cdn.com/v4/letter/m/5fc32e/32.png) [@MitchellWeg](https://discourse.julialang.org/u/MitchellWeg)\
**Post date:** [October 5, 2021, 2:25pm UTC](https://discourse.julialang.org/t/running-a-cmakelists-txt-programmatically/69238/1 "2021-10-05T14:25:47Z")

</div>

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](https://github.com/JuliaPackaging/CMakeWrapper.jl) and [BinDeps](https://github.com/JuliaPackaging/BinDeps.jl). 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:

```julia
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:

```julia
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?

---

<div class="post-metadata">

**Author:** ![gbaraldi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gbaraldi/32/22101_2.png) [@gbaraldi](https://discourse.julialang.org/u/gbaraldi)\
**Post date:** [October 5, 2021, 3:44pm UTC](https://discourse.julialang.org/t/running-a-cmakelists-txt-programmatically/69238/2 "2021-10-05T15:44:58Z")

</div>

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