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

Moving to CPM. #537

Merged
merged 4 commits into from
Oct 15, 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
2 changes: 1 addition & 1 deletion .github/workflows/ubuntu-s390x.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
githubToken: ${{ github.token }}
install: |
apt-get update -q -y
apt-get install -y cmake make g++
apt-get install -y cmake make g++ git
apt-get install -y ninja-build
run: |
cmake -DCMAKE_BUILD_TYPE=Release -G Ninja -B build
Expand Down
48 changes: 37 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,49 @@ 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 Google Benchmark, but it does not build under several 32-bit systems.
if((BUILD_TESTING OR ADA_BENCHMARKS) AND (CMAKE_SIZEOF_VOID_P EQUAL 8))
include(${PROJECT_SOURCE_DIR}/cmake/import.cmake)
import_dependency(simdjson simdjson/simdjson 14d927128ba14e13913fc0e7c2cf538790bd1622)
add_dependency(simdjson)
import_dependency(gtest google/googletest 797b0ad2a3a45608ecf5c67e6e289d377a3521ca)
add_dependency(gtest)
if(Git_FOUND AND (BUILD_TESTING OR ADA_BENCHMARKS) AND (CMAKE_SIZEOF_VOID_P EQUAL 8))
CPMAddPackage("gh:simdjson/[email protected]")
CPMAddPackage(
NAME GTest
GITHUB_REPOSITORY google/googletest
VERSION 1.14.0
OPTIONS "BUILD_GMOCK OFF" "INSTALL_GTEST OFF"
)
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)
message(STATUS "The tests are enabled.")
add_subdirectory(tests)
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(BUILD_TESTING AND NOT EMSCRIPTEN)

If(ADA_BENCHMARKS AND NOT EMSCRIPTEN)
message(STATUS "Ada benchmarks enabled.")
add_subdirectory(benchmarks)
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.")
Expand Down Expand Up @@ -72,7 +94,11 @@ if(NOT ADA_COVERAGE AND NOT EMSCRIPTEN)
endif()

if(ADA_TOOLS)
add_subdirectory(tools)
if(Git_FOUND)
add_subdirectory(tools)
else()
message(STATUS "The tools are disabled because git was not found.")
endif()
endif()

install(
Expand Down
62 changes: 36 additions & 26 deletions benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ target_include_directories(bench PUBLIC "$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}
target_include_directories(bench PUBLIC "$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/benchmarks>")

# Benchdata
import_dependency(url-dataset ada-url/url-dataset 9749b92c13e970e70409948fa862461191504ccc)
CPMAddPackage("gh:ada-url/url-dataset#9749b92c13e970e70409948fa862461191504ccc")
add_executable(benchdata bench.cpp)
target_link_libraries(benchdata PRIVATE ada)
target_include_directories(benchdata PUBLIC "$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>")
Expand Down Expand Up @@ -45,14 +45,6 @@ if(CMAKE_SYSTEM_NAME MATCHES "Linux")
target_compile_definitions(model_bench PRIVATE ADA_URL_FILE="${url-dataset_SOURCE_DIR}/out.txt")
endif()

include(${PROJECT_SOURCE_DIR}/cmake/import.cmake)

set_off(BENCHMARK_ENABLE_TESTING)
set_off(BENCHMARK_ENABLE_INSTALL)
set_off(BENCHMARK_ENABLE_WERROR)

import_dependency(google_benchmarks google/benchmark f91b6b4)
add_dependency(google_benchmarks)
target_link_libraries(wpt_bench PRIVATE benchmark::benchmark)
target_link_libraries(bench PRIVATE benchmark::benchmark)
target_link_libraries(benchdata PRIVATE benchmark::benchmark)
Expand Down Expand Up @@ -96,10 +88,12 @@ if(NOT ICU_FOUND)
endif(NOT ICU_FOUND)

if(ICU_FOUND)
set_off(URL_BUILD_TESTS)
set_off(URL_USE_LIBS)
import_dependency(url_whatwg rmisev/url_whatwg cbcf3043eccb380cb4bef7486465ac3b02d2f674)
add_dependency(url_whatwg)
CPMAddPackage(
NAME url_whatwg
GITHUB_REPOSITORY rmisev/url_whatwg
GIT_TAG cbcf3043eccb380cb4bef7486465ac3b02d2f674
OPTIONS "URL_BUILD_TESTS OFF" "URL_USE_LIBS OFF"
)
add_library(url_whatwg_lib STATIC "${url_whatwg_SOURCE_DIR}/src/url.cpp"
"${url_whatwg_SOURCE_DIR}/src/url_idna.cpp"
"${url_whatwg_SOURCE_DIR}/src/url_ip.cpp"
Expand Down Expand Up @@ -129,22 +123,31 @@ endif(ICU_FOUND)

if(ADA_COMPETITION)
# URI Parser
set_off(URIPARSER_BUILD_TESTS)
set_off(URIPARSER_BUILD_DOCS)
import_dependency(uriparser uriparser/uriparser 634b678)
add_dependency(uriparser)
CPMAddPackage(
NAME uriparser
GITHUB_REPOSITORY uriparser/uriparser
GIT_TAG 634b678
OPTIONS "URIPARSER_BUILD_TESTS OFF" "URIPARSER_BUILD_DOCS OFF"
)
target_link_libraries(bench PRIVATE uriparser)
target_link_libraries(bbc_bench PRIVATE uriparser)

# URL Parser
import_dependency(urlparser netmindms/urlparser 69c09ed)
CPMAddPackage(
NAME urlparser
GITHUB_REPOSITORY netmindms/urlparser
GIT_TAG 69c09ed
)
add_library(urlparser STATIC "${urlparser_SOURCE_DIR}/src/EdUrlParser.cpp")
target_include_directories(urlparser PUBLIC "${urlparser_SOURCE_DIR}/src")
target_link_libraries(bench PRIVATE urlparser)
target_link_libraries(bbc_bench PRIVATE urlparser)

# HTTP Parser
import_dependency(httpparser nodejs/http-parser v2.9.4)
CPMAddPackage(
NAME httpparser
GITHUB_REPOSITORY nodejs/http-parser
VERSION 2.9.4
)
add_library(httpparser STATIC "${httpparser_SOURCE_DIR}/http_parser.c")
set_source_files_properties("${httpparser_SOURCE_DIR}/http_parser.c" PROPERTIES LANGUAGE C)
target_include_directories(httpparser PUBLIC "${httpparser_SOURCE_DIR}")
Expand Down Expand Up @@ -203,7 +206,11 @@ find_package(
endif(ADA_BOOST_URL)

if(Boost_FOUND)
import_dependency(boost_url boostorg/url boost-1.81.0)
CPMAddPackage(
NAME boost_url
GITHUB_REPOSITORY boostorg/url
GIT_TAG boost-1.81.0
)
add_library(boost_url INTERFACE)
target_include_directories(boost_url INTERFACE
"${boost_url_SOURCE_DIR}/include")
Expand Down Expand Up @@ -241,16 +248,19 @@ endif(ZURI_FOUND)


# We want the check whether Rust is available before trying to build a crate.
set(Rust_FIND_QUIETLY ON) # No need to alarm the user if rust is not available.
import_dependency(corrosion corrosion-rs/corrosion v0.3.4)
CPMAddPackage(
NAME corrosion
GITHUB_REPOSITORY corrosion-rs/corrosion
VERSION 0.4.4
DOWNLOAD_ONLY ON
OPTIONS "Rust_FIND_QUIETLY OFF"
)
include("${corrosion_SOURCE_DIR}/cmake/FindRust.cmake")


if(RUST_FOUND)
message(STATUS "Rust found: " ${Rust_VERSION} )
# Important: we only want to include corrosion *if* rust is available.
# Otherwise, it is impossible to run ada benchmarks without rust.
add_dependency(corrosion)
add_subdirectory("${corrosion_SOURCE_DIR}" "${PROJECT_BINARY_DIR}/_deps/corrosion" EXCLUDE_FROM_ALL)
# Important: we want to build in release mode!
corrosion_import_crate(MANIFEST_PATH "competitors/servo-url/Cargo.toml" NO_LINKER_OVERRIDE PROFILE release)

Expand Down
24 changes: 24 additions & 0 deletions cmake/CPM.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# SPDX-License-Identifier: MIT
#
# SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors

set(CPM_DOWNLOAD_VERSION 0.38.6)
set(CPM_HASH_SUM "11c3fa5f1ba14f15d31c2fb63dbc8628ee133d81c8d764caad9a8db9e0bacb07")

if(CPM_SOURCE_CACHE)
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
elseif(DEFINED ENV{CPM_SOURCE_CACHE})
set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
else()
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
endif()

# Expand relative path. This is important if the provided path contains a tilde (~)
get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE)

file(DOWNLOAD
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
${CPM_DOWNLOAD_LOCATION} EXPECTED_HASH SHA256=${CPM_HASH_SUM}
)

include(${CPM_DOWNLOAD_LOCATION})
52 changes: 0 additions & 52 deletions cmake/import.cmake

This file was deleted.

11 changes: 6 additions & 5 deletions tools/cli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ add_executable(adaparse adaparse.cpp line_iterator.h)
target_link_libraries(adaparse PRIVATE ada)
target_include_directories(adaparse PUBLIC "$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>")

include(${PROJECT_SOURCE_DIR}/cmake/import.cmake)
import_dependency(cxxopts jarro2783/cxxopts eb78730)
add_dependency(cxxopts)
import_dependency(fmt fmtlib/fmt a337011)
add_dependency(fmt)
CPMAddPackage("gh:fmtlib/fmt#7.1.3")
CPMAddPackage(
GITHUB_REPOSITORY jarro2783/cxxopts
VERSION 3.1.1
OPTIONS "CXXOPTS_BUILD_EXAMPLES NO" "CXXOPTS_BUILD_TESTS NO" "CXXOPTS_ENABLE_INSTALL YES"
)
target_link_libraries(adaparse PRIVATE cxxopts::cxxopts fmt::fmt)

if(MSVC OR MINGW)
Expand Down
Loading