5

I am using Buck for my own C++ project, but I depend on a third-party library that is built using CMake. The CMake file is complex, so I do not think it is practical to recreate their CMake file in Buck. Instead, I would like to call CMake from Buck.

What is the best way to call CMake from Buck?

How should I structure my project to minimise headaches?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
sdgfsdh
  • 33,689
  • 26
  • 132
  • 245

2 Answers2

4

My suggestion is using genrule and prebuilt_cxx_library.

This is my Buck study project using Google Test: https://github.com/ar90n/lab/tree/master/sandbox/buck-study/gtest

This project contains two Buck files. The one (./gtest/BUCK) is for fetching and building Google Test. The another (./BUCK) is for building and running test programs.

If you want to build and run this project, please execute the following commands,

$ buck fetch //gtest:googletest-src
$ buck build :sample1
$ buck run :sample1
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • Yes, that works. For Google Test there is a proper BUCK file here https://github.com/njlr/googletest/blob/a9384dbf3d795e730f942b468dae38158e6be863/BUCK – sdgfsdh May 16 '17 at 06:21
1

Calling CMake will break reproducibility, so it isn't the best approach. Instead, try the following:

  1. Fork the project that builds with CMake.
  2. Call CMake to generate any header files.
  3. Save the header files somewhere in the project (e.g. /cmake-generated).
  4. Create a header-only library of the header files generated by CMake.
  5. Build the rest of the project with Buck, depending on the CMake library.
  6. Commit everything to Git.
  7. Repeat step 2 for every target that you require.

This is not as good as a true port to Buck, but you get most of the benefits for a one-time manual step.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
sdgfsdh
  • 33,689
  • 26
  • 132
  • 245