Skip to content

Commit

Permalink
cmake: support disabling CPM
Browse files Browse the repository at this point in the history
When using ada as a library and embedding it in our project via
FetchContent, we've run into errors like this:

```
[253/1413] Generating ada.cpp, ada.h, ada_c.h, demo.cpp, demo.c, README.md
fatal: detected dubious ownership in repository at '/src/redpanda'
```

In our CI environment we've seen flaky HTTP issues as well:

```
CMake Error at build/_deps/ada-src/cmake/CPM.cmake:19 (file):
  file DOWNLOAD cannot compute hash on failed download
    status: [22;"HTTP response code said error"]
Call Stack (most recent call first):
  build/_deps/ada-src/CMakeLists.txt:27 (include)
CMake Error at build/_deps/ada-src/CMakeLists.txt:32 (CPMAddPackage):
  Unknown CMake command "CPMAddPackage".
```

Actually building just the library seems very simple and uses vanilla
cmake. CPM is only used for testing/benchmarking/etc. We've seen some of
the dubious ownership issues just including CPM (hacking around trying
to disable GIT failed to fix the issue).

To support our usecase, I've added a flag allowing disabling tests, the
default value is the value of BUILD_TESTING so hopefully nothing changes
for anyone.

I tested this via the following commands:

```
cmake -B build && cmake --build build
cmake -B build -DADA_BENCHMARKS=ON && cmake --build build
cmake -B build -DADA_TESTING=OFF -DADA_TOOLS=OFF -DADA_BENCHMARKS=OFF && cmake --build build
```

Signed-off-by: Tyler Rockwood <rockwood@redpanda.com>
  • Loading branch information
rockwotj committed Nov 8, 2023
1 parent 1643c72 commit c6b58ab
Showing 1 changed file with 59 additions and 55 deletions.
114 changes: 59 additions & 55 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,65 +23,69 @@ add_subdirectory(src)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/scripts/cmake)

option(ADA_BENCHMARKS "Build benchmarks" OFF)

include(cmake/CPM.cmake)
# CPM requires git as an implicit dependency
find_package(Git QUIET)
# We use googletest in the tests
if(Git_FOUND AND BUILD_TESTING)
CPMAddPackage(
NAME GTest
GITHUB_REPOSITORY google/googletest
VERSION 1.14.0
OPTIONS "BUILD_GMOCK OFF" "INSTALL_GTEST OFF"
)
endif()
# We use simdjson in both the benchmarks and tests
if(Git_FOUND AND (BUILD_TESTING OR ADA_BENCHMARKS))
CPMAddPackage("gh:simdjson/simdjson@3.3.0")
endif()
# We use Google Benchmark, but it does not build under several 32-bit systems.
if(Git_FOUND AND ADA_BENCHMARKS AND (CMAKE_SIZEOF_VOID_P EQUAL 8))
CPMAddPackage(
NAME benchmark
GITHUB_REPOSITORY google/benchmark
GIT_TAG f91b6b4
OPTIONS "BENCHMARK_ENABLE_TESTING OFF"
"BENCHMARK_ENABLE_INSTALL OFF"
"BENCHMARK_ENABLE_WERROR OFF"

)
endif()

if (BUILD_TESTING AND NOT EMSCRIPTEN)
if(Git_FOUND)
message(STATUS "The tests are enabled.")
add_subdirectory(tests)
else()
message(STATUS "The tests are disabled because git was not found.")
option(ADA_TESTING "Build tests" ${BUILD_TESTING})

if(ADA_TESTING OR ADA_BENCHMARKS OR ADA_TOOLS)
include(cmake/CPM.cmake)
# CPM requires git as an implicit dependency
find_package(Git QUIET)
# We use googletest in the tests
if(Git_FOUND AND ADA_TESTING)
CPMAddPackage(
NAME GTest
GITHUB_REPOSITORY google/googletest
VERSION 1.14.0
OPTIONS "BUILD_GMOCK OFF" "INSTALL_GTEST OFF"
)
endif()
else()
if(is_top_project)
message(STATUS "The tests are disabled.")
# We use simdjson in both the benchmarks and tests
if(Git_FOUND AND (ADA_TESTING OR ADA_BENCHMARKS))
CPMAddPackage("gh:simdjson/simdjson@3.3.0")
endif()
endif(BUILD_TESTING AND NOT EMSCRIPTEN)

If(ADA_BENCHMARKS AND NOT EMSCRIPTEN)
if(Git_FOUND)
message(STATUS "Ada benchmarks enabled.")
add_subdirectory(benchmarks)
else()
message(STATUS "The benchmarks are disabled because git was not found.")
# We use Google Benchmark, but it does not build under several 32-bit systems.
if(Git_FOUND AND ADA_BENCHMARKS AND (CMAKE_SIZEOF_VOID_P EQUAL 8))
CPMAddPackage(
NAME benchmark
GITHUB_REPOSITORY google/benchmark
GIT_TAG f91b6b4
OPTIONS "BENCHMARK_ENABLE_TESTING OFF"
"BENCHMARK_ENABLE_INSTALL OFF"
"BENCHMARK_ENABLE_WERROR OFF"

)
endif()
else(ADA_BENCHMARKS AND NOT EMSCRIPTEN)
if(is_top_project)
message(STATUS "Ada benchmarks disabled. Set ADA_BENCHMARKS=ON to enable them.")
endif()
endif(ADA_BENCHMARKS AND NOT EMSCRIPTEN)

if (ADA_TESTING AND NOT EMSCRIPTEN)
if(Git_FOUND)
message(STATUS "The tests are enabled.")
add_subdirectory(tests)
else()
message(STATUS "The tests are disabled because git was not found.")
endif()
else()
if(is_top_project)
message(STATUS "The tests are disabled.")
endif()
endif(ADA_TESTING AND NOT EMSCRIPTEN)

If(ADA_BENCHMARKS AND NOT EMSCRIPTEN)
if(Git_FOUND)
message(STATUS "Ada benchmarks enabled.")
add_subdirectory(benchmarks)
else()
message(STATUS "The benchmarks are disabled because git was not found.")
endif()
else(ADA_BENCHMARKS AND NOT EMSCRIPTEN)
if(is_top_project)
message(STATUS "Ada benchmarks disabled. Set ADA_BENCHMARKS=ON to enable them.")
endif()
endif(ADA_BENCHMARKS AND NOT EMSCRIPTEN)

if (ADA_TESTING AND EMSCRIPTEN)
add_subdirectory(tests/wasm)
endif(ADA_TESTING AND EMSCRIPTEN)
endif()

if (BUILD_TESTING AND EMSCRIPTEN)
add_subdirectory(tests/wasm)
endif(BUILD_TESTING AND EMSCRIPTEN)

add_library(ada::ada ALIAS ada)

Expand Down

0 comments on commit c6b58ab

Please sign in to comment.