diff --git a/CMakeLists.txt b/CMakeLists.txt index 2f33368bc..5e631f3a4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) + 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) diff --git a/singleheader/CMakeLists.txt b/singleheader/CMakeLists.txt index a0afcde89..9dc62a444 100644 --- a/singleheader/CMakeLists.txt +++ b/singleheader/CMakeLists.txt @@ -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 $) - if (BUILD_TESTING) + if (ADA_TESTING) add_executable(demo $) target_link_libraries(demo ada-singleheader-include-source) @@ -63,4 +63,4 @@ if (Python3_Interpreter_FOUND) endif() else() MESSAGE( STATUS "Python not found, we are unable to test amalgamate.py." ) -endif() \ No newline at end of file +endif()