diff --git a/circuits/cpp/barretenberg/README.md b/circuits/cpp/barretenberg/README.md index 382a0bc0a4e..7b51408af20 100644 --- a/circuits/cpp/barretenberg/README.md +++ b/circuits/cpp/barretenberg/README.md @@ -30,6 +30,14 @@ cd cpp ./bootstrap.sh ``` +### Installing + +After the project has been built, such as with `./bootstrap.sh`, you can install the library on your system: + +```sh +cmake --install build +``` + ### Formatting Code is formatted using `clang-format` and the `./cpp/format.sh` script which is called via a git pre-commit hook. diff --git a/circuits/cpp/barretenberg/cpp/CMakeLists.txt b/circuits/cpp/barretenberg/cpp/CMakeLists.txt index fe24d09aa09..bff44b7bbf9 100644 --- a/circuits/cpp/barretenberg/cpp/CMakeLists.txt +++ b/circuits/cpp/barretenberg/cpp/CMakeLists.txt @@ -17,6 +17,7 @@ option(FUZZING "Build fuzzing harnesses" OFF) option(DISABLE_TBB "Intel Thread Building Blocks" ON) option(COVERAGE "Enable collecting coverage from tests" OFF) option(ENABLE_HEAVY_TESTS "Enable heavy tests when collecting coverage" OFF) +option(INSTALL_BARRETENBERG "Enable installation of barretenberg. (Projects embedding barretenberg may want to turn this OFF.)" ON) if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64" OR CMAKE_SYSTEM_PROCESSOR MATCHES "arm64") message(STATUS "Compiling for ARM.") diff --git a/circuits/cpp/barretenberg/cpp/cmake/benchmark.cmake b/circuits/cpp/barretenberg/cpp/cmake/benchmark.cmake index d38a9dacf4d..c8f90548d66 100644 --- a/circuits/cpp/barretenberg/cpp/cmake/benchmark.cmake +++ b/circuits/cpp/barretenberg/cpp/cmake/benchmark.cmake @@ -13,6 +13,7 @@ if(BENCHMARKS) ) set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "Benchmark tests off") + set(BENCHMARK_ENABLE_INSTALL OFF CACHE BOOL "Benchmark installation off") FetchContent_MakeAvailable(benchmark) if(NOT benchmark_FOUND) diff --git a/circuits/cpp/barretenberg/cpp/cmake/gtest.cmake b/circuits/cpp/barretenberg/cpp/cmake/gtest.cmake index 19a7783153c..e86bf49756e 100644 --- a/circuits/cpp/barretenberg/cpp/cmake/gtest.cmake +++ b/circuits/cpp/barretenberg/cpp/cmake/gtest.cmake @@ -11,6 +11,7 @@ if(TESTING) ) set(BUILD_GMOCK OFF CACHE BOOL "Build with gMock disabled") + set(INSTALL_GTEST OFF CACHE BOOL "gTest installation disabled") FetchContent_MakeAvailable(GTest) diff --git a/circuits/cpp/barretenberg/cpp/cmake/module.cmake b/circuits/cpp/barretenberg/cpp/cmake/module.cmake index a6a6ace9c14..27b94b9adc7 100644 --- a/circuits/cpp/barretenberg/cpp/cmake/module.cmake +++ b/circuits/cpp/barretenberg/cpp/cmake/module.cmake @@ -12,11 +12,29 @@ # Then we declare executables/libraries that are to be built from these object files. # These assets will only be linked as their dependencies complete, but we can parallelise the compilation at least. +# This is an interface library that can be used as an install target to include all header files +# encountered by the `barretenberg_module` function. There is probably a better way to do this, +# especially if we want to exclude some of the header files being installed +add_library(barretenberg_headers INTERFACE) +target_sources( + barretenberg_headers + INTERFACE + FILE_SET HEADERS + BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/src +) + function(barretenberg_module MODULE_NAME) file(GLOB_RECURSE SOURCE_FILES *.cpp) - file(GLOB_RECURSE HEADER_FILES *.hpp) + file(GLOB_RECURSE HEADER_FILES *.hpp *.tcc) list(FILTER SOURCE_FILES EXCLUDE REGEX ".*\.(fuzzer|test|bench).cpp$") + target_sources( + barretenberg_headers + INTERFACE + FILE_SET HEADERS + FILES ${HEADER_FILES} + ) + if(SOURCE_FILES) add_library( ${MODULE_NAME}_objects diff --git a/circuits/cpp/barretenberg/cpp/src/aztec/CMakeLists.txt b/circuits/cpp/barretenberg/cpp/src/aztec/CMakeLists.txt index a778e332b04..301be6ab139 100644 --- a/circuits/cpp/barretenberg/cpp/src/aztec/CMakeLists.txt +++ b/circuits/cpp/barretenberg/cpp/src/aztec/CMakeLists.txt @@ -37,6 +37,7 @@ else() message(STATUS "Using optimized assembly for field arithmetic.") endif() +add_subdirectory(common) add_subdirectory(env) add_subdirectory(numeric) add_subdirectory(srs) @@ -55,6 +56,8 @@ if(BENCHMARKS) add_subdirectory(benchmark) endif() +include(GNUInstallDirs) + if(WASM) # Well, this is awkward. We can't build a wasm module by just linking to the libraries as that produces, nothing. # There are a couple of other ways to avoiding listing all the object files here and leveraging the dependency @@ -105,6 +108,10 @@ if(WASM) VERBATIM ) + if(INSTALL_BARRETENBERG) + install(TARGETS barretenberg.wasm DESTINATION ${CMAKE_INSTALL_BINDIR}) + endif() + # For use when compiling dependent cpp projects for WASM message(STATUS "Compiling all-in-one barretenberg WASM archive") add_library( @@ -131,7 +138,6 @@ if(WASM) $ $ ) - else() # For use when compiling dependent cpp projects message(STATUS "Compiling all-in-one barretenberg archive") @@ -160,4 +166,13 @@ else() $ $ ) -endif() \ No newline at end of file + + if(INSTALL_BARRETENBERG) + install( + TARGETS barretenberg barretenberg_headers + EXPORT barretenbergTargets + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + FILE_SET HEADERS DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + ) + endif() +endif() diff --git a/circuits/cpp/barretenberg/cpp/src/aztec/common/CMakeLists.txt b/circuits/cpp/barretenberg/cpp/src/aztec/common/CMakeLists.txt new file mode 100644 index 00000000000..4f815063ff4 --- /dev/null +++ b/circuits/cpp/barretenberg/cpp/src/aztec/common/CMakeLists.txt @@ -0,0 +1,8 @@ +# Collect our common/*.hpp files and include in installation +file(GLOB_RECURSE HEADER_FILES *.hpp) +target_sources( + barretenberg_headers + INTERFACE + FILE_SET HEADERS + FILES ${HEADER_FILES} +)