Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmake: support disabling CPM #557

Merged
merged 1 commit into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 63 additions & 55 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,65 +23,73 @@ 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})

# There are cases where when embedding ada as a dependency for other CMake
# projects as submodules or subdirectories (via FetchContent) can lead to
# errors due to CPM, so this is here to support disabling all the testing
# and tooling for ada if one only wishes to use the ada library.
if(ADA_TESTING OR ADA_BENCHMARKS OR ADA_TOOLS)
anonrig marked this conversation as resolved.
Show resolved Hide resolved
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
4 changes: 2 additions & 2 deletions singleheader/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ if (Python3_Interpreter_FOUND)
target_link_libraries(ada-singleheader-source INTERFACE ada-singleheader-include-source)
add_library(ada-singleheader-lib STATIC $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/ada.cpp>)

if (BUILD_TESTING)
if (ADA_TESTING)
add_executable(demo $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/demo.cpp>)
target_link_libraries(demo ada-singleheader-include-source)

Expand All @@ -63,4 +63,4 @@ if (Python3_Interpreter_FOUND)
endif()
else()
MESSAGE( STATUS "Python not found, we are unable to test amalgamate.py." )
endif()
endif()
Loading