137 lines
4.1 KiB
Plaintext
137 lines
4.1 KiB
Plaintext
# Copyright 2010-2025 Google LLC
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
cmake_minimum_required(VERSION 3.14)
|
|
|
|
# fetch_git_dependency()
|
|
#
|
|
# CMake function to download, build and install (in staging area) a dependency at configure
|
|
# time.
|
|
#
|
|
# Parameters:
|
|
# NAME: name of the dependency
|
|
# REPOSITORY: git url of the dependency
|
|
# TAG: tag of the dependency
|
|
# PATCH_COMMAND: apply patch
|
|
# SOURCE_SUBDIR: Path to source CMakeLists.txt relative to root dir
|
|
# CMAKE_ARGS: List of specific CMake args to add
|
|
#
|
|
# e.g.:
|
|
# fetch_git_dependency(
|
|
# NAME
|
|
# abseil-cpp
|
|
# URL
|
|
# https://github.com/abseil/abseil-cpp.git
|
|
# TAG
|
|
# main
|
|
# PATCH_COMMAND
|
|
# "git apply ${CMAKE_SOURCE_DIR}/patches/abseil-cpp.patch"
|
|
# )
|
|
function(fetch_git_dependency)
|
|
set(options "")
|
|
set(oneValueArgs NAME REPOSITORY TAG PATCH_COMMAND SOURCE_SUBDIR)
|
|
set(multiValueArgs CMAKE_ARGS)
|
|
cmake_parse_arguments(GIT_DEP
|
|
"${options}"
|
|
"${oneValueArgs}"
|
|
"${multiValueArgs}"
|
|
${ARGN}
|
|
)
|
|
message(STATUS "Building ${GIT_DEP_NAME}: ...")
|
|
string(TOLOWER ${GIT_DEP_NAME} NAME_LOWER)
|
|
|
|
if(GIT_DEP_PATCH_COMMAND)
|
|
set(PATCH_CMD "${GIT_DEP_PATCH_COMMAND}")
|
|
else()
|
|
set(PATCH_CMD "")
|
|
endif()
|
|
configure_file(
|
|
${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt.in
|
|
${CMAKE_BINARY_DIR}/_deps/${NAME_LOWER}-subbuild/CMakeLists.txt @ONLY)
|
|
|
|
execute_process(
|
|
COMMAND ${CMAKE_COMMAND} -S. -Bproject_build -G "${CMAKE_GENERATOR}"
|
|
RESULT_VARIABLE result
|
|
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/_deps/${NAME_LOWER}-subbuild)
|
|
if(result)
|
|
message(FATAL_ERROR "CMake step for ${GIT_DEP_NAME} failed: ${result}")
|
|
endif()
|
|
|
|
execute_process(
|
|
COMMAND ${CMAKE_COMMAND} --build project_build --config ${CMAKE_BUILD_TYPE}
|
|
RESULT_VARIABLE result
|
|
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/_deps/${NAME_LOWER}-subbuild)
|
|
if(result)
|
|
message(FATAL_ERROR "Build step for ${GIT_DEP_NAME} failed: ${result}")
|
|
endif()
|
|
|
|
if(GIT_DEP_SOURCE_SUBDIR)
|
|
add_subdirectory(
|
|
${CMAKE_BINARY_DIR}/_deps/${NAME_LOWER}-src/${GIT_DEP_SOURCE_SUBDIR}
|
|
${CMAKE_BINARY_DIR}/_deps/${NAME_LOWER}-build)
|
|
else()
|
|
add_subdirectory(
|
|
${CMAKE_BINARY_DIR}/_deps/${NAME_LOWER}-src
|
|
${CMAKE_BINARY_DIR}/_deps/${NAME_LOWER}-build)
|
|
endif()
|
|
|
|
message(STATUS "Building ${GIT_DEP_NAME}: ...DONE")
|
|
endfunction()
|
|
|
|
project(host-meta CXX)
|
|
|
|
include(FetchContent)
|
|
set(FETCHCONTENT_QUIET OFF)
|
|
set(FETCHCONTENT_UPDATES_DISCONNECTED ON)
|
|
set(BUILD_SHARED_LIBS OFF)
|
|
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
|
set(BUILD_TESTING OFF)
|
|
|
|
message(CHECK_START "Fetching Abseil-cpp")
|
|
list(APPEND CMAKE_MESSAGE_INDENT " ")
|
|
set(ABSL_ENABLE_INSTALL ON)
|
|
set(ABSL_USE_SYSTEM_INCLUDES ON)
|
|
set(ABSL_PROPAGATE_CXX_STD ON)
|
|
set(ABSL_BUILD_TESTING OFF)
|
|
FetchContent_Declare(
|
|
absl
|
|
GIT_REPOSITORY "https://github.com/abseil/abseil-cpp.git"
|
|
GIT_TAG "20250814.1"
|
|
GIT_SHALLOW TRUE
|
|
PATCH_COMMAND git apply --ignore-whitespace
|
|
"${CMAKE_CURRENT_LIST_DIR}/@PATCHES_PATH@/abseil-cpp-20250814.1.patch"
|
|
)
|
|
FetchContent_MakeAvailable(absl)
|
|
list(POP_BACK CMAKE_MESSAGE_INDENT)
|
|
message(CHECK_PASS "fetched")
|
|
|
|
message(CHECK_START "Fetching Protobuf")
|
|
list(APPEND CMAKE_MESSAGE_INDENT " ")
|
|
set(protobuf_BUILD_TESTS OFF)
|
|
set(protobuf_BUILD_SHARED_LIBS ON)
|
|
set(protobuf_BUILD_EXPORT OFF)
|
|
set(protobuf_MSVC_STATIC_RUNTIME OFF)
|
|
set(protobuf_WITH_ZLIB OFF)
|
|
FetchContent_Declare(
|
|
protobuf
|
|
GIT_REPOSITORY "https://github.com/protocolbuffers/protobuf.git"
|
|
GIT_TAG "v32.0"
|
|
GIT_SHALLOW TRUE
|
|
GIT_SUBMODULES ""
|
|
PATCH_COMMAND git apply --ignore-whitespace
|
|
"${CMAKE_CURRENT_LIST_DIR}/@PATCHES_PATH@/protobuf-v32.0.patch"
|
|
)
|
|
FetchContent_MakeAvailable(protobuf)
|
|
list(POP_BACK CMAKE_MESSAGE_INDENT)
|
|
message(CHECK_PASS "fetched")
|