chore: import upstream snapshot with attribution
cffconvert / validate (push) Has been skipped
License Check / license-check (push) Failing after 2s

This commit is contained in:
wehub-resource-sync
2026-07-13 12:14:16 +08:00
commit 8a852e4b4e
36502 changed files with 9277225 additions and 0 deletions
@@ -0,0 +1,41 @@
#
# Copyright 2020 The TensorFlow Authors. All Rights Reserved.
#
# 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
#
# https://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.
# tensorflow-lite uses find_package for this package, so override the system
# installation and build from source instead.
include(eigen)
if(eigen_POPULATED)
set(EIGEN_FOUND TRUE)
get_target_property(EIGEN_INCLUDE_DIRS eigen INTERFACE_DIRECTORIES)
# If using MSVC2015 (14) or below force Eigen to C++11.
if(MSVC_VERSION LESS_EQUAL 1900)
set(COMPILE_DEFINITIONS "EIGEN_MAX_CPP_VER=11")
get_target_property(EIGEN_COMPILE_DEFINITIONS eigen
INTERFACE_COMPILE_DEFINITIONS
)
if(EIGEN_COMPILE_DEFINITIONS)
list(APPEND COMPILE_DEFINITIONS ${EIGEN_COMPILE_DEFINITIONS})
endif()
set_property(
TARGET
eigen
PROPERTY
INTERFACE_COMPILE_DEFINITIONS
${COMPILE_DEFINITIONS}
)
endif()
set(EIGEN_LIBRARIES Eigen3::Eigen)
endif()
@@ -0,0 +1,28 @@
#
# Copyright 2020 The TensorFlow Authors. All Rights Reserved.
#
# 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
#
# https://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.
# tensorflow-lite uses find_package for this package, so override the system
# installation and build from source instead.
include(flatbuffers)
if(flatbuffers_POPULATED)
set(FLATBUFFERS_FOUND TRUE)
get_target_property(FLATBUFFERS_INCLUDE_DIRS flatbuffers INCLUDE_DIRECTORIES)
add_library(flatbuffers::flatbuffers ALIAS flatbuffers)
set(FLATBUFFERS_LIBRARIES flatbuffers)
set(FLATBUFFERS_PROJECT_DIR "${flatbuffers_SOURCE_DIR}" CACHE STRING
"Flatbuffers project dir"
)
endif()
@@ -0,0 +1,24 @@
#
# Copyright 2020 The TensorFlow Authors. All Rights Reserved.
#
# 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
#
# https://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.
# tensorflow-lite uses find_package for this package, so override the system
# installation and build from source instead.
include(neon2sse)
if(neon2sse_POPULATED)
set(NEON2SSE_FOUND TRUE)
get_target_property(NEON2SSE_INCLUDE_DIRS NEON_2_SSE INTERFACE_DIRECTORIES)
add_library(NEON_2_SSE::NEON_2_SSE ALIAS NEON_2_SSE)
set(NEON2SSE_LIBRARIES NEON_2_SSE)
endif()
@@ -0,0 +1,16 @@
#
# Copyright 2024 The TensorFlow Authors. All Rights Reserved.
#
# 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
#
# https://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.
include(protobuf)
@@ -0,0 +1,16 @@
#
# Copyright 2020 The TensorFlow Authors. All Rights Reserved.
#
# 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
#
# https://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.
include(xnnpack)
@@ -0,0 +1,187 @@
#
# Copyright 2020 The TensorFlow Authors. All Rights Reserved.
#
# 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
#
# https://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.
# grpc uses find_package in CONFIG mode for this package, so override the
# system installation and build from source instead.
include(abseil-cpp)
if(abseil-cpp_POPULATED)
set(_ABSL_LIBRARY_NAMES
algorithm
algorithm_container
any
atomic_hook
atomic_hook_test_helper
awesome
bad_any_cast
bad_any_cast_impl
bad_optional_access
bad_variant_access
base
base_internal
bind_front
bits
btree
btree_test_common
city
civil_time
compare
compressed_tuple
config
conformance_testing
container
container_common
container_memory
cord
cord_test_helpers
core_headers
counting_allocator
debugging
debugging_internal
demangle_internal
dynamic_annotations
endian
errno_saver
examine_stack
exception_safety_testing
exception_testing
exponential_biased
failure_signal_handler
fantastic_lib
fast_type_id
fixed_array
flags
flags_commandlineflag
flags_commandlineflag_internal
flags_config
flags_internal
flags_marshalling
flags_parse
flags_path_util
flags_private_handle_accessor
flags_program_name
flags_reflection
flags_usage
flags_usage_internal
flat_hash_map
flat_hash_set
function_ref
graphcycles_internal
hash
hash_function_defaults
hash_generator_testing
hash_policy_testing
hash_policy_traits
hash_testing
hashtable_debug
hashtable_debug_hooks
hashtablez_sampler
have_sse
hdrs
inlined_vector
inlined_vector_internal
int128
kernel_timeout_internal
layout
leak_check
leak_check_api_disabled_for_testing
leak_check_api_enabled_for_testing
leak_check_disable
log_severity
main_lib
malloc_internal
memory
meta
node_hash_map
node_hash_policy
node_hash_set
numeric
optional
per_thread_sem_test_common
periodic_sampler
pow10_helper
pretty_function
random_bit_gen_ref
random_distributions
random_internal_distribution_caller
random_internal_distribution_test_util
random_internal_explicit_seed_seq
random_internal_fast_uniform_bits
random_internal_fastmath
random_internal_generate_real
random_internal_iostream_state_saver
random_internal_mock_helpers
random_internal_mock_overload_set
random_internal_nonsecure_base
random_internal_pcg_engine
random_internal_platform
random_internal_pool_urbg
random_internal_randen
random_internal_randen_engine
random_internal_randen_hwaes
random_internal_randen_hwaes_impl
random_internal_randen_slow
random_internal_salted_seed_seq
random_internal_seed_material
random_internal_sequence_urbg
random_internal_traits
random_internal_uniform_helper
random_internal_wide_multiply
random_mocking_bit_gen
random_random
random_seed_gen_exception
random_seed_sequences
raw_hash_map
raw_hash_set
raw_logging_internal
scoped_set_env
span
spinlock_test_common
spinlock_wait
spy_hash_state
stack_consumption
stacktrace
status
str_format
str_format_internal
strerror
strings
strings_internal
symbolize
synchronization
test_instance_tracker
thread_pool
throw_delegate
time
time_internal_test_util
time_zone
tracked
type_traits
unordered_map_constructor_test
unordered_map_lookup_test
unordered_map_members_test
unordered_map_modifiers_test
unordered_set_constructor_test
unordered_set_lookup_test
unordered_set_members_test
unordered_set_modifiers_test
utility
variant
)
set(_ABSL_LIBRARIES ${_ABSL_LIBRARY_NAMES})
foreach(_LIBRARY ${_ABSL_LIBRARY_NAMES})
list(APPEND _ABSL_LIBRARIES "absl::${LIBRARY}")
endforeach()
set(ABSL_LIBRARIES ${ABSL_LIBRARIES} CACHE STRING "absl libs")
endif()
@@ -0,0 +1,16 @@
#
# Copyright 2021 The TensorFlow Authors. All Rights Reserved.
#
# 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
#
# https://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.
include(cpuinfo)
@@ -0,0 +1,16 @@
#
# Copyright 2020 The TensorFlow Authors. All Rights Reserved.
#
# 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
#
# https://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.
include(egl_headers)
@@ -0,0 +1,45 @@
#
# Copyright 2020 The TensorFlow Authors. All Rights Reserved.
#
# 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
#
# https://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.
# tensorflow-lite uses find_package for this package, so build from
# source if the system version is not enabled.
if(SYSTEM_FARMHASH)
include(FindPackageHandleStandardArgs)
find_path(FARMHASH_ROOT_DIR NAMES include/farmhash.h)
find_library(FARMHASH_LIB NAMES farmhash PATHS ${FARMHASH_ROOT_DIR}/lib ${FARMHASH_LIB_PATH})
find_path(FARMHASH_INCLUDE_DIRS NAMES farmhash.h PATHS ${FARMHASH_ROOT_DIR}/include)
find_package_handle_standard_args(farmhash DEFAULT_MSG FARMHASH_LIB FARMHASH_INCLUDE_DIRS)
endif()
if(farmhash_FOUND)
add_library(farmhash SHARED IMPORTED GLOBAL)
set_target_properties(farmhash PROPERTIES
IMPORTED_LOCATION ${FARMHASH_LIB}
INTERFACE_INCLUDE_DIRECTORIES ${FARMHASH_INCLUDE_DIRS}
)
else()
include(farmhash)
if(farmhash_POPULATED)
get_target_property(FARMHASH_INCLUDE_DIRS farmhash INTERFACE_DIRECTORIES)
endif()
endif()
if(farmhash_FOUND OR farmhash_POPULATED)
set(FARMHASH_FOUND TRUE)
add_library(farmhash::farmhash ALIAS farmhash)
set(FARMHASH_LIBRARIES farmhash::farmhash)
endif()
@@ -0,0 +1,37 @@
#
# Copyright 2020 The TensorFlow Authors. All Rights Reserved.
#
# 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
#
# https://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.
# tensorflow-lite uses find_package for this package, so override the system
# installation and build from source instead.
include(fft2d)
if(fft2d_POPULATED)
set(FFT2D_FOUND TRUE CACHE BOOL "Found FF2D")
get_target_property(FFT2D_INCLUDE_DIRS fft2d INCLUDE_DIRECTORIES)
set(FFT2D_INCLUDE_DIRS ${FFT2D_INCLUDE_DIRS} CACHE STRING
"FFT2D include dirs"
)
set(FFT2D_LIBRARIES
fft2d_alloc
fft2d_fft4f2d
fft2d_fftsg
fft2d_fftsg2d
fft2d_fftsg3d
fft2d_shrtdct
CACHE
STRING
"FFT2D libraries"
)
endif()
@@ -0,0 +1,16 @@
#
# Copyright 2021 The TensorFlow Authors. All Rights Reserved.
#
# 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
#
# https://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.
include(fp16_headers)
@@ -0,0 +1,25 @@
#
# Copyright 2020 The TensorFlow Authors. All Rights Reserved.
#
# 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
#
# https://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.
# tensorflow-lite uses find_package for this package, so override the system
# installation and build from source instead.
include(gemmlowp)
if(gemmlowp_POPULATED)
set(GEMMLOWP_FOUND TRUE)
get_target_property(GEMMLOWP_INCLUDE_DIRS gemmlowp INTERFACE_DIRECTORIES)
add_library(gemmlowp::gemmlowp ALIAS gemmlowp)
set(GEMMLOWP_LIBRARIES gemmlowp)
endif()
@@ -0,0 +1,46 @@
#
# Copyright 2022 The TensorFlow Authors. All Rights Reserved.
#
# 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
#
# https://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.
if(TARGET google_benchmark OR google_benchmark_POPULATED)
return()
endif()
include(OverridableFetchContent)
OverridableFetchContent_Declare(
google_benchmark
GIT_REPOSITORY https://github.com/google/benchmark.git
GIT_TAG v1.7.0
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
SOURCE_DIR "${CMAKE_BINARY_DIR}/google_benchmark"
)
OverridableFetchContent_GetProperties(google_benchmark)
if(NOT google_benchmark_POPULATED)
OverridableFetchContent_Populate(google_benchmark)
endif()
option(HAVE_GNU_POSIX_REGEX OFF)
add_subdirectory(
"${google_benchmark_SOURCE_DIR}"
"${google_benchmark_BINARY_DIR}"
EXCLUDE_FROM_ALL
)
include_directories(
AFTER
"${google_benchmark_SOURCE_DIR}/include"
)
@@ -0,0 +1,41 @@
#
# Copyright 2021 The TensorFlow Authors. All Rights Reserved.
#
# 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
#
# https://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.
if(TARGET googletest OR googletest_POPULATED)
return()
endif()
include(OverridableFetchContent)
OverridableFetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.12.1
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
SOURCE_DIR "${CMAKE_BINARY_DIR}/googletest"
)
OverridableFetchContent_GetProperties(googletest)
if(NOT googletest_POPULATED)
OverridableFetchContent_Populate(googletest)
endif()
option(INSTALL_GTEST OFF)
add_subdirectory(
"${googletest_SOURCE_DIR}"
"${googletest_BINARY_DIR}"
EXCLUDE_FROM_ALL
)
@@ -0,0 +1,28 @@
#
# Copyright 2023 The TensorFlow Authors. All Rights Reserved.
#
# 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
#
# https://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.
# tensorflow-lite uses find_package for this package, so build from
# source if the system version is not enabled.
include(ml_dtypes)
if(ml_dtypes_POPULATED)
get_target_property(ML_DTYPES_INCLUDE_DIRS ml_dtypes INTERFACE_DIRECTORIES)
endif()
if(ml_dtypes_FOUND OR ml_dtypes_POPULATED)
set(ML_DTYPES_FOUND TRUE)
add_library(ml_dtypes::ml_dtypes ALIAS ml_dtypes)
set(ML_DTYPES_LIBRARIES ml_dtypes::ml_dtypes)
endif()
@@ -0,0 +1,16 @@
#
# Copyright 2020 The TensorFlow Authors. All Rights Reserved.
#
# 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
#
# https://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.
include(opencl_headers)
@@ -0,0 +1,16 @@
#
# Copyright 2020 The TensorFlow Authors. All Rights Reserved.
#
# 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
#
# https://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.
include(opengl_headers)
@@ -0,0 +1,41 @@
#
# Copyright 2021 The TensorFlow Authors. All Rights Reserved.
#
# 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
#
# https://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.
if(TARGET re2 OR re2_POPULATED)
return()
endif()
include(OverridableFetchContent)
OverridableFetchContent_Declare(
re2
GIT_REPOSITORY https://github.com/google/re2.git
GIT_TAG 2021-02-02
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
SOURCE_DIR "${CMAKE_BINARY_DIR}/re2"
)
OverridableFetchContent_GetProperties(re2)
if(NOT re2_POPULATED)
OverridableFetchContent_Populate(re2)
endif()
option(RE2_BUILD_TESTING OFF)
add_subdirectory(
"${re2_SOURCE_DIR}"
"${re2_BINARY_DIR}"
EXCLUDE_FROM_ALL
)
@@ -0,0 +1,16 @@
#
# Copyright 2020 The TensorFlow Authors. All Rights Reserved.
#
# 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
#
# https://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.
include(ruy)
@@ -0,0 +1,16 @@
#
# Copyright 2020 The TensorFlow Authors. All Rights Reserved.
#
# 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
#
# https://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.
include(vulkan_headers)
@@ -0,0 +1,616 @@
#
# Copyright 2020 The TensorFlow Authors. All Rights Reserved.
#
# 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
#
# https://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.
include(FetchContent)
# Pairs of regex --> replacement strings that map Git repositories to archive
# URLs. GIT_COMMIT is replaced with the hash of the commit.
set(OVERRIDABLE_FETCH_CONTENT_GITHUB_MATCH
"^https?://github.com/([^/]+)/([^/.]+)(\\.git)?\$"
)
set(OVERRIDABLE_FETCH_CONTENT_GITHUB_REPLACE
"https://github.com/\\1/\\2/archive/GIT_COMMIT.zip"
)
set(OVERRIDABLE_FETCH_CONTENT_GITLAB_MATCH
"^https?://gitlab.com/([^/]+)/([^/.]+)(\\.git)?"
)
set(OVERRIDABLE_FETCH_CONTENT_GITLAB_REPLACE
"https://gitlab.com/\\1/\\2/-/archive/GIT_COMMIT/\\2-GIT_COMMIT.tar.gz"
)
set(OVERRIDABLE_FETCH_CONTENT_GOOGLESOURCE_MATCH
"^(https?://[^.]+\\.googlesource\\.com/.*)"
)
set(OVERRIDABLE_FETCH_CONTENT_GOOGLESOURCE_REPLACE
"\\1/+archive/GIT_COMMIT.tar.gz"
)
# List of prefixes for regex match and replacement variables that map Git
# repositories to archive URLs.
list(APPEND OVERRIDABLE_FETCH_CONTENT_GIT_TRANSFORMS
OVERRIDABLE_FETCH_CONTENT_GITHUB
OVERRIDABLE_FETCH_CONTENT_GITLAB
OVERRIDABLE_FETCH_CONTENT_GOOGLESOURCE
)
# Pairs of regex --> replacement strings that map Git repositories to raw file
# URLs.
set(OVERRIDABLE_FETCH_CONTENT_GITHUB_FILE_MATCH
"${OVERRIDABLE_FETCH_CONTENT_GITHUB_MATCH}"
)
set(OVERRIDABLE_FETCH_CONTENT_GITHUB_FILE_REPLACE
"https://raw.githubusercontent.com/\\1/\\2/GIT_COMMIT/FILE_PATH"
)
set(OVERRIDABLE_FETCH_CONTENT_GITLAB_FILE_MATCH
"${OVERRIDABLE_FETCH_CONTENT_GITLAB_MATCH}"
)
set(OVERRIDABLE_FETCH_CONTENT_GITLAB_FILE_REPLACE
"https://gitlab.com/\\1/\\2/-/raw/GIT_COMMIT/FILE_PATH"
)
set(OVERRIDABLE_FETCH_CONTENT_GOOGLESOURCE_FILE_MATCH
"${OVERRIDABLE_FETCH_CONTENT_GOOGLESOURCE_MATCH}"
)
# This isn't the raw file, gitiles doesn't support raw file download without
# decoding the file from base64.
set(OVERRIDABLE_FETCH_CONTENT_GOOGLESOURCE_FILE_REPLACE
"\\1/+/GIT_COMMIT/FILE_PATH"
)
# List of prefixes for regex match and replacement variables that map Git
# repositories to archive URLs.
list(APPEND OVERRIDABLE_FETCH_CONTENT_GIT_FILE_TRANSFORMS
OVERRIDABLE_FETCH_CONTENT_GITHUB_FILE
OVERRIDABLE_FETCH_CONTENT_GITLAB_FILE
OVERRIDABLE_FETCH_CONTENT_GOOGLESOURCE_FILE
)
# Try applying replacements to string.
#
# TRANSFORMS: List which contains prefixes for _MATCH / _REPLACE replacements
# to try. For example, given the list "FOO" this will try to apply a regex
# replacement with the value of FOO_MATCH and FOO_REPLACE.
# TO_REPLACE: String to apply replacements to.
# OUTPUT_VAR: Name of the variable to store the URL if successful. If
# conversion fails this variable will be empty.
function(_ApplyReplacements TRANSFORMS TO_REPLACE OUTPUT_VAR)
foreach(PREFIX ${TRANSFORMS})
message(VERBOSE "Try converting ${GIT_REPOSITORY} with ${${PREFIX}_MATCH}")
set(MATCH "${${PREFIX}_MATCH}")
set(REPLACE "${${PREFIX}_REPLACE}")
if(MATCH AND REPLACE)
string(REGEX REPLACE
"${MATCH}"
"${REPLACE}"
REPLACED
"${TO_REPLACE}"
)
if(NOT "${REPLACED}" STREQUAL "${TO_REPLACE}")
set(${OUTPUT_VAR} "${REPLACED}" PARENT_SCOPE)
endif()
endif()
endforeach()
endfunction()
# Try to convert a Git repository to an archive URL.
#
# GIT_REPOSITORY: Repository URL to convert.
# GIT_COMMIT: Commit hash or tag to convert.
# REPORT_WARNING: Whether to report a warning if conversion fails.
# OUTPUT_VAR: Name of the variable to store the URL if successful. If
# conversion fails this variable will be empty.
function(_GitRepoArchiveUrl GIT_REPOSITORY GIT_COMMIT REPORT_WARNING OUTPUT_VAR)
list(REMOVE_DUPLICATES OVERRIDABLE_FETCH_CONTENT_GIT_TRANSFORMS)
_ApplyReplacements(
"${OVERRIDABLE_FETCH_CONTENT_GIT_TRANSFORMS}"
"${GIT_REPOSITORY}"
REPLACED
)
if(REPLACED)
string(REPLACE "GIT_COMMIT" "${GIT_COMMIT}" WITH_COMMIT "${REPLACED}")
message(VERBOSE "${GIT_REPOSITORY} / ${GIT_COMMIT} --> ${WITH_COMMIT}")
set(${OUTPUT_VAR} "${WITH_COMMIT}" PARENT_SCOPE)
elseif(REPORT_WARNING)
message(WARNING
"Unable to map ${GIT_REPOSITORY} / ${GIT_COMMIT} to an archive URL"
)
endif()
endfunction()
# Try to convert a Git repository, commit and relative path to a link to the
# file.
#
# GIT_REPOSITORY: Repository URL to convert.
# GIT_COMMIT: Commit hash or tag to convert.
# FILE_PATH: Path to the file.
# OUTPUT_VAR: Name of the variable to store the URL if successful. If
# conversion fails this variable will be empty.
function(_GitRepoFileUrl GIT_REPOSITORY GIT_COMMIT FILE_PATH OUTPUT_VAR)
list(REMOVE_DUPLICATES OVERRIDABLE_FETCH_CONTENT_GIT_FILE_TRANSFORMS)
_ApplyReplacements(
"${OVERRIDABLE_FETCH_CONTENT_GIT_FILE_TRANSFORMS}"
"${GIT_REPOSITORY}"
REPLACED
)
if(REPLACED)
string(REPLACE "GIT_COMMIT" "${GIT_COMMIT}" WITH_COMMIT "${REPLACED}")
string(REPLACE "FILE_PATH" "${FILE_PATH}" WITH_FILE "${WITH_COMMIT}")
message(VERBOSE
"${GIT_REPOSITORY} / ${GIT_COMMIT} / ${FILE_PATH} --> ${WITH_FILE}"
)
set(${OUTPUT_VAR} "${WITH_FILE}" PARENT_SCOPE)
else()
message(WARNING
"Unable to map ${GIT_REPOSITORY} / ${GIT_COMMIT} / ${FILE_PATH} to a URL"
)
endif()
endfunction()
# Try to determine the license URL from a path within the content and
# cache LICENSE_FILE and LICENSE_URL properties.
#
# CONTENT_NAME: Name of the content that hosts the license.
# LICENSE_FILE: Relative path in the archive.
# OUTPUT_VAR: Name of variable to store / retrieve the license URL.
function(_LicenseFileToUrl CONTENT_NAME LICENSE_FILE OUTPUT_VAR)
foreach(PROPERTY GIT_REPOSITORY GIT_COMMIT LICENSE_URL)
_OverridableFetchContent_GetProperty(
"${CONTENT_NAME}"
"${PROPERTY}"
"${PROPERTY}"
)
endforeach()
_OverridableFetchContent_SetProperty(
"${CONTENT_NAME}"
LICENSE_FILE
"License for ${CONTENT_NAME}"
"${LICENSE_FILE}"
)
if(NOT LICENSE_URL)
if(GIT_REPOSITORY AND GIT_COMMIT)
# Try to synthesize the license URL from the repo path.
_GitRepoFileUrl(
"${GIT_REPOSITORY}"
"${GIT_COMMIT}"
"${LICENSE_FILE}"
LICENSE_URL
)
if(LICENSE_URL)
_OverridableFetchContent_SetProperty(
"${CONTENT_NAME}"
LICENSE_URL
"License URL for ${CONTENT_NAME}"
"${LICENSE_URL}"
)
set(${OUTPUT_VAR} "${LICENSE_URL}" PARENT_SCOPE)
endif()
endif()
endif()
endfunction()
# Replacement for FetchContent_Declare() that allows the user to override the
# download URL for Git and URL sources and also favor fetching via URL vs.
# a Git repo using variables external to this method.
#
# See FetchContent_Declare() and ExternalProject_Add() for the arguments
# supported by this method.
#
# In addition to FetchContent_Declare() and ExternalProject_Add() arguments,
# this method supports LICENSE_FILE that enables the caller to specify the
# relative path of the license in the downloaded archive which disables the
# search for a license in OverridableFetchContent_Populate().
# LICENSE_URL can be specified to override the URL of the LICENSE_FILE if
# a direct link to the URL can't be formed from the download path.
#
# It's possible to override, GIT_REPOSITORY, GIT_TAG, URL and URL_HASH for
# a target by setting
# OVERRIDABLE_FETCH_CONTENT_<contentName>_<variable> where <contentName> is the
# CONTENT_NAME argument content provided to this method and <variable> is the
# argument of this method to override. For example, given CONTENT_NAME = foo
# the GIT_REPOSITORY can be overridden by setting foo_GIT_REPOSITORY to the
# value to use instead.
#
# To convert a GIT_REPOSITORY / GIT_TAG reference to a URL,
# set OVERRIDABLE_FETCH_CONTENT_GIT_REPOSITORY_AND_TAG_TO_URL_<contentName>
# to ON for one repository or
# OVERRIDABLE_FETCH_CONTENT_GIT_REPOSITORY_AND_TAG_TO_URL to ON for all
# repositories. This will, where possible, convert a GIT_REPOSITORY / GIT_TAG
# reference to a URL to download instead which is much faster to copy than
# cloning a git repo.
#
# If OVERRIDABLE_FETCH_CONTENT_USE_GIT is ON, when a GIT_REPOSITORY and a
# download URL are specified this method will clone the GIT_REPOSITORY. When
# OVERRIDABLE_FETCH_CONTENT_USE_GIT is OFF or not set and both GIT_REPOSITORY
# and download URL are specified the download URL is used instead.
#
# To override the archive URL before it's passed to FetchContent_Declare()
# set OVERRIDABLE_FETCH_CONTENT_<contentName>_MATCH to a regular expression
# to match the archive URL and OVERRIDABLE_FETCH_CONTENT_<contentName>_REPLACE
# with the string to replace the archive URL.
#
# All content names passed to this method are added to the global property
# OVERRIDABLE_FETCH_CONTENT_LIST.
function(OverridableFetchContent_Declare CONTENT_NAME)
set(OVERRIDABLE_ARGS
GIT_REPOSITORY
GIT_TAG
URL
URL_HASH
URL_MD5
)
set(ALL_VALUE_ARGS LICENSE_FILE LICENSE_URL ${OVERRIDABLE_ARGS})
cmake_parse_arguments(ARGS
""
"${ALL_VALUE_ARGS}"
""
${ARGN}
)
# Optionally override parsed arguments with values from variables in the form
# ${CONTENT_NAME}_${OVERRIDABLE_ARG}.
foreach(OVERRIDABLE_ARG in ${OVERRIDABLE_ARGS})
set(OVERRIDE_VALUE
${OVERRIDABLE_FETCH_CONTENT_${CONTENT_NAME}_${OVERRIDABLE_ARG}}
)
if(NOT "${OVERRIDE_VALUE}" STREQUAL "")
set(ARGS_${OVERRIDABLE_ARG} "${OVERRIDE_VALUE}")
message(VERBOSE "Overriding ${OVERRIDABLE_ARG} of content "
"${CONTENT_NAME} with '${OVERRIDE_VALUE}'"
)
endif()
endforeach()
# If specified, save the source URL so it's possible to synthesize a link to
# the license when the content is populated.
if(ARGS_GIT_REPOSITORY AND ARGS_GIT_TAG)
_OverridableFetchContent_SetProperty(
"${CONTENT_NAME}"
GIT_REPOSITORY
"Git repo for ${CONTENT_NAME}"
"${ARGS_GIT_REPOSITORY}"
)
_OverridableFetchContent_SetProperty(
"${CONTENT_NAME}"
GIT_COMMIT
"Git commit for ${CONTENT_NAME}"
"${ARGS_GIT_TAG}"
)
endif()
# Set the license file and URL properties.
if(ARGS_LICENSE_URL)
_OverridableFetchContent_SetProperty(
"${CONTENT_NAME}"
LICENSE_URL
"License URL for ${CONTENT_NAME}"
"${ARGS_LICENSE_URL}"
)
endif()
if(ARGS_LICENSE_FILE)
_LicenseFileToUrl(
"${CONTENT_NAME}"
"${ARGS_LICENSE_FILE}"
ARGS_LICENSE_URL
)
endif()
# Try mapping to an archive URL.
set(ARCHIVE_URL "")
if(ARGS_GIT_REPOSITORY AND ARGS_GIT_TAG)
_GitRepoArchiveUrl(
"${ARGS_GIT_REPOSITORY}"
"${ARGS_GIT_TAG}"
OFF
ARCHIVE_URL
)
# If conversion from git repository to archive URL is enabled.
if(OVERRIDABLE_FETCH_CONTENT_GIT_REPOSITORY_AND_TAG_TO_URL_${CONTENT_NAME}
OR OVERRIDABLE_FETCH_CONTENT_GIT_REPOSITORY_AND_TAG_TO_URL)
# Try converting to an archive URL.
if(NOT ARGS_URL)
_GitRepoArchiveUrl(
"${ARGS_GIT_REPOSITORY}"
"${ARGS_GIT_TAG}"
ON
ARGS_URL
)
set(ARCHIVE_URL "${ARGS_URL}")
endif()
endif()
endif()
# If a download URL and git repository with tag are specified either use
# the git repo or the download URL.
if(ARGS_URL AND ARGS_GIT_REPOSITORY)
if(OVERRIDABLE_FETCH_CONTENT_USE_GIT)
unset(ARGS_URL)
unset(ARGS_URL_HASH)
unset(ARGS_URL_MD5)
else()
unset(ARGS_GIT_REPOSITORY)
unset(ARGS_GIT_TAG)
endif()
endif()
# Optionally map the archive URL to a mirror.
if(ARGS_URL)
_ApplyReplacements(
"OVERRIDABLE_FETCH_CONTENT_${CONTENT_NAME}"
"${ARGS_URL}"
REPLACED
)
if(REPLACED)
set(ARGS_URL "${REPLACED}")
endif()
endif()
# Save the archive URL.
if(ARGS_URL)
set(ARCHIVE_URL "${ARGS_URL}")
endif()
if(ARCHIVE_URL)
_OverridableFetchContent_SetProperty(
"${CONTENT_NAME}"
ARCHIVE_URL
"Archive URL for ${CONTENT_NAME}"
"${ARCHIVE_URL}"
)
endif()
# Build the list of arguments to pass to FetchContent_Declare() starting with
# the overridable arguments.
set(OUTPUT_ARGS "")
foreach(OVERRIDABLE_ARG ${OVERRIDABLE_ARGS})
set(OVERRIDABLE_ARG_VALUE "${ARGS_${OVERRIDABLE_ARG}}")
if(OVERRIDABLE_ARG_VALUE)
list(APPEND OUTPUT_ARGS ${OVERRIDABLE_ARG} "${OVERRIDABLE_ARG_VALUE}")
endif()
endforeach()
list(APPEND OUTPUT_ARGS ${ARGS_UNPARSED_ARGUMENTS})
# Add all defined packages to a global property.
get_property(OVERRIDABLE_FETCH_CONTENT_LIST GLOBAL PROPERTY
OVERRIDABLE_FETCH_CONTENT_LIST
)
set(DOCUMENTATION "List of all fetched content")
define_property(GLOBAL PROPERTY OVERRIDABLE_FETCH_CONTENT_LIST
BRIEF_DOCS "${DOCUMENTATION}"
FULL_DOCS "${DOCUMENTATION}"
)
list(APPEND OVERRIDABLE_FETCH_CONTENT_LIST "${CONTENT_NAME}")
set_property(GLOBAL PROPERTY OVERRIDABLE_FETCH_CONTENT_LIST
"${OVERRIDABLE_FETCH_CONTENT_LIST}"
)
message(VERBOSE "FetchContent_Declare(${CONTENT_NAME} ${OUTPUT_ARGS}")
FetchContent_Declare("${CONTENT_NAME}" ${OUTPUT_ARGS})
endfunction()
# Get a property name for this module.
# CONTENT_NAME: Name of the content associated with the FetchContent function.
# PROPERTY_NAME: Name of the property.
# OUTPUT_VAR: Variable to store the name in.
function(_OverridableFetchContent_GetPropertyName CONTENT_NAME PROPERTY_NAME
OUTPUT_VAR)
# The implementation of FetchContent_GetProperties() uses the lower case
# content name to prefix property names so follow the same pattern here.
string(TOLOWER "${CONTENT_NAME}" CONTENT_NAME_LOWER)
set(${OUTPUT_VAR}
"_OverridableFetchContent_${CONTENT_NAME_LOWER}_${PROPERTY_NAME}"
PARENT_SCOPE
)
endfunction()
# Set a global property for this module.
# CONTENT_NAME: Name of the content associated with the FetchContent function.
# PROPERTY_NAME: Name of the property to set.
# DOCUMENTATION: Documentation string for the property.
# PROPERTY_VALUE: Value to set the property to.
function(_OverridableFetchContent_SetProperty CONTENT_NAME PROPERTY_NAME
DOCUMENTATION PROPERTY_VALUE)
_OverridableFetchContent_GetPropertyName(
"${CONTENT_NAME}"
"${PROPERTY_NAME}"
GLOBAL_PROPERTY_NAME
)
define_property(GLOBAL PROPERTY "${GLOBAL_PROPERTY_NAME}"
BRIEF_DOCS "${DOCUMENTATION}"
FULL_DOCS "${DOCUMENTATION}"
)
set_property(
GLOBAL PROPERTY "${GLOBAL_PROPERTY_NAME}"
"${PROPERTY_VALUE}"
)
endfunction()
# Get a global property for this module.
# CONTENT_NAME: Name of the content associated with the FetchContent function.
# PROPERTY_NAME: Name of the property to get.
# OUTPUT_VAR: Variable to store the value in.
function(_OverridableFetchContent_GetProperty CONTENT_NAME PROPERTY_NAME
OUTPUT_VAR)
_OverridableFetchContent_GetPropertyName(
"${CONTENT_NAME}"
"${PROPERTY_NAME}"
GLOBAL_PROPERTY_NAME
)
get_property(VALUE GLOBAL PROPERTY "${GLOBAL_PROPERTY_NAME}")
if(VALUE)
set(${OUTPUT_VAR} "${VALUE}" PARENT_SCOPE)
endif()
endfunction()
# Export a list of variables to the parent scope of the caller function.
macro(_OverridableFetchContent_ExportToParentScope)
# Export requested variables to the parent scope.
foreach(VARIABLE_NAME ${ARGN})
if(${VARIABLE_NAME})
message(DEBUG "Export ${VARIABLE_NAME} ${${VARIABLE_NAME}}")
set(${VARIABLE_NAME} "${${VARIABLE_NAME}}" PARENT_SCOPE)
endif()
endforeach()
endmacro()
# Wrapper around FetchContent_GetProperties().
#
# Sets the same variables as FetchContent_GetProperties() in addition to:
# * <contentName>_LICENSE_FILE: License file relative to
# <contentName>_SOURCE_DIR if found.
# * <contentName>_LICENSE_URL: License URL if the file is found.
# * <contentName_ARCHIVE_URL: URL to the source package.
function(OverridableFetchContent_GetProperties CONTENT_NAME)
set(EXPORT_VARIABLE_ARGS SOURCE_DIR BINARY_DIR POPULATED)
cmake_parse_arguments(ARGS
""
"${EXPORT_VARIABLE_ARGS}"
""
${ARGN}
)
# The implementation of FetchContent_Populate() uses the lower case
# content name to prefix returned variable names.
string(TOLOWER "${CONTENT_NAME}" CONTENT_NAME_LOWER)
# Get the names of the variables to export to the parent scope.
set(EXPORT_VARIABLES "")
set(OUTPUT_ARGS "")
foreach(ARG_NAME ${EXPORT_VARIABLE_ARGS})
set(ARG_VARIABLE_NAME "ARGS_${ARG_NAME}")
set(ARG_VARIABLE_VALUE "${${ARG_VARIABLE_NAME}}")
list(APPEND EXPORT_VARIABLES "${CONTENT_NAME_LOWER}_${ARG_NAME}")
if(ARG_VARIABLE_VALUE)
list(APPEND EXPORT_VARIABLES "${ARG_VARIABLE_VALUE}")
list(APPEND OUTPUT_ARGS "${ARG_NAME}" "${ARG_VARIABLE_VALUE}")
endif()
endforeach()
list(APPEND OUTPUT_ARGS ${ARGS_UNPARSED_ARGUMENTS})
foreach(EXPORT_PROPERTY LICENSE_FILE LICENSE_URL ARCHIVE_URL)
_OverridableFetchContent_GetProperty("${CONTENT_NAME}"
"${EXPORT_PROPERTY}"
"${EXPORT_PROPERTY}"
)
set(PROPERTY_VALUE "${${EXPORT_PROPERTY}}")
if(PROPERTY_VALUE)
set(${CONTENT_NAME_LOWER}_${EXPORT_PROPERTY}
"${PROPERTY_VALUE}"
PARENT_SCOPE
)
endif()
endforeach()
FetchContent_GetProperties("${CONTENT_NAME}" ${OUTPUT_ARGS})
_OverridableFetchContent_ExportToParentScope(${EXPORT_VARIABLES})
endfunction()
# Replacement for FetchContent_Populate() that searches a newly cloned
# repository for a top level license file and provides it to the caller
# via the <contentName>_LICENSE_FILE and <contentName>_LICENSE_URL variables
# where <contentName> is the value passed as the CONTENT_NAME argument of this
# method.
#
# To ensure a fetched repo has a license file and URL
# OVERRIDABLE_FETCH_CONTENT_LICENSE_CHECK_<contentName> to ON for one
# repository or OVERRIDABLE_FETCH_CONTENT_LICENSE_CHECK to ON for all
# repositories.
function(OverridableFetchContent_Populate CONTENT_NAME)
# The implementation of FetchContent_Populate() uses the lower case
# content name to prefix returned variable names.
string(TOLOWER "${CONTENT_NAME}" CONTENT_NAME_LOWER)
FetchContent_Populate("${CONTENT_NAME}")
OverridableFetchContent_GetProperties("${CONTENT_NAME}")
# If a license file isn't cached try finding it in the repo.
set(LICENSE_FILE "${${CONTENT_NAME_LOWER}_LICENSE_FILE}")
set(LICENSE_URL "${${CONTENT_NAME_LOWER}_LICENSE_URL}")
set(SOURCE_DIR "${${CONTENT_NAME_LOWER}_SOURCE_DIR}")
if(${CONTENT_NAME}_POPULATED AND NOT LICENSE_FILE)
find_file(_${CONTENT_NAME_LOWER}_LICENSE_FILE
NAMES LICENSE LICENSE.md LICENSE.txt NOTICE COPYING
PATHS "${SOURCE_DIR}"
DOC "${CONTENT_NAME} license file"
NO_DEFAULT_PATH
NO_CMAKE_FIND_ROOT_PATH
)
set(LICENSE_FILE "${_${CONTENT_NAME_LOWER}_LICENSE_FILE}")
if(LICENSE_FILE)
file(RELATIVE_PATH LICENSE_FILE "${SOURCE_DIR}" "${LICENSE_FILE}")
file(TO_CMAKE_PATH "${LICENSE_FILE}" LICENSE_FILE)
endif()
endif()
# If LICENSE_FILE was not found but a URL was specified then try downloading
# the license.
set(LICENSE_FILE_FULL_PATH "${SOURCE_DIR}/${LICENSE_FILE}")
if(NOT EXISTS "${LICENSE_FILE_FULL_PATH}" AND LICENSE_URL)
set(LICENSE_FILE_DOWNLOAD "${SOURCE_DIR}/${CONTENT_NAME}_LICENSE.txt")
if(NOT EXISTS "${LICENSE_FILE_DOWNLOAD}")
message(STATUS
"${CONTENT_NAME} '${LICENSE_FILE_FULL_PATH}' does not exist "
"downloading ${LICENSE_URL} --> ${LICENSE_FILE_DOWNLOAD}")
file(DOWNLOAD "${LICENSE_URL}" "${LICENSE_FILE_DOWNLOAD}" STATUS RESULT)
list(GET RESULT 0 RESULT)
if(NOT RESULT EQUAL 0)
message(
FATAL_ERROR
"Failed to download ${LICENSE_URL} for ${CONTENT_NAME} to "
"${LICENSE_FILE_DOWNLOAD}"
)
endif()
endif()
file(RELATIVE_PATH LICENSE_FILE "${SOURCE_DIR}" "${LICENSE_FILE_DOWNLOAD}")
_OverridableFetchContent_SetProperty(
"${CONTENT_NAME}"
LICENSE_FILE
"License for ${CONTENT_NAME}"
"${LICENSE_FILE}"
)
endif()
# If a LICENSE_FILE was found populate the URL.
if(LICENSE_FILE AND NOT LICENSE_URL)
_LicenseFileToUrl(
"${CONTENT_NAME}"
"${LICENSE_FILE}"
LICENSE_URL
)
endif()
# If enabled, check for source licenses.
if(OVERRIDABLE_FETCH_CONTENT_LICENSE_CHECK OR
OVERRIDABLE_FETCH_CONTENT_LICENSE_CHECK_${CONTENT_NAME})
message(DEBUG "LICENSE_FILE: ${LICENSE_FILE}, LICENSE_URL: ${LICENSE_URL}")
if(NOT LICENSE_FILE)
message(FATAL_ERROR
"Required license file not found for ${CONTENT_NAME}"
)
endif()
if(NOT LICENSE_URL)
message(FATAL_ERROR
"Required license URL not found for ${CONTENT_NAME}"
)
endif()
endif()
# Export return values to the parent scope.
set(EXPORT_VARIABLES "")
foreach(VARIABLE_POSTFIX SOURCE_DIR BINARY_DIR POPULATED)
list(APPEND EXPORT_VARIABLES "${CONTENT_NAME_LOWER}_${VARIABLE_POSTFIX}")
endforeach()
_OverridableFetchContent_ExportToParentScope(${EXPORT_VARIABLES})
endfunction()
@@ -0,0 +1,44 @@
#
# Copyright 2020 The TensorFlow Authors. All Rights Reserved.
#
# 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
#
# https://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.
# Use absl_base as a proxy for the project being included.
if(TARGET absl_base OR abseil-cpp_POPULATED)
return()
endif()
include(OverridableFetchContent)
OverridableFetchContent_Declare(
abseil-cpp
GIT_REPOSITORY https://github.com/abseil/abseil-cpp
# Sync with tensorflow/third_party/absl/workspace.bzl
GIT_TAG 20260526.0
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
PREFIX "${CMAKE_BINARY_DIR}"
SOURCE_DIR "${CMAKE_BINARY_DIR}/abseil-cpp"
)
OverridableFetchContent_GetProperties(abseil-cpp)
if(NOT abseil-cpp_POPULATED)
OverridableFetchContent_Populate(abseil-cpp)
endif()
set(ABSL_USE_GOOGLETEST_HEAD OFF CACHE BOOL "Disable googletest")
set(ABSL_RUN_TESTS OFF CACHE BOOL "Disable build of ABSL tests")
add_subdirectory(
"${abseil-cpp_SOURCE_DIR}"
"${abseil-cpp_BINARY_DIR}"
)
@@ -0,0 +1,44 @@
#
# Copyright 2021 The TensorFlow Authors. All Rights Reserved.
#
# 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
#
# https://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.
if(TARGET cpuinfo OR cpuinfo_POPULATED)
return()
endif()
include(OverridableFetchContent)
OverridableFetchContent_Declare(
cpuinfo
GIT_REPOSITORY https://github.com/pytorch/cpuinfo
# Sync with tensorflow/workspace2.bzl
GIT_TAG bc3c01e230c6974283e4b89421cfb0e232435589
GIT_PROGRESS TRUE
SOURCE_DIR "${CMAKE_BINARY_DIR}/cpuinfo"
)
OverridableFetchContent_GetProperties(cpuinfo)
if(NOT cpuinfo_POPULATED)
OverridableFetchContent_Populate(cpuinfo)
endif()
set(CPUINFO_SOURCE_DIR "${cpuinfo_SOURCE_DIR}" CACHE PATH "CPUINFO source directory")
set(CPUINFO_BUILD_TOOLS OFF CACHE BOOL "Disable cpuinfo command-line tools")
set(CPUINFO_BUILD_UNIT_TESTS OFF CACHE BOOL "Disable cpuinfo unit tests")
set(CPUINFO_BUILD_MOCK_TESTS OFF CACHE BOOL "Disable cpuinfo cpuinfo mock tests")
set(CPUINFO_BUILD_BENCHMARKS OFF CACHE BOOL "Disable cpuinfo micro-benchmarks")
add_subdirectory(
"${cpuinfo_SOURCE_DIR}"
"${cpuinfo_BINARY_DIR}"
)
@@ -0,0 +1,43 @@
#
# Copyright 2020 The TensorFlow Authors. All Rights Reserved.
#
# 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
#
# https://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.
if(TARGET egl_headers OR egl_headers_POPULATED)
return()
endif()
include(OverridableFetchContent)
OverridableFetchContent_Declare(
egl_headers
GIT_REPOSITORY https://github.com/KhronosGroup/EGL-Registry.git
# No reference in TensorFlow Bazel rule since it's used for GPU Delegate
# build without using Android NDK.
GIT_TAG 649981109e263b737e7735933c90626c29a306f2
GIT_PROGRESS TRUE
PREFIX "${CMAKE_BINARY_DIR}"
SOURCE_DIR "${CMAKE_BINARY_DIR}/egl_headers"
# Per https://www.khronos.org/legal/Khronos_Apache_2.0_CLA
LICENSE_URL "https://www.apache.org/licenses/LICENSE-2.0.txt"
)
OverridableFetchContent_GetProperties(egl_headers)
if(NOT egl_headers)
OverridableFetchContent_Populate(egl_headers)
endif()
include_directories(
AFTER
"${egl_headers_SOURCE_DIR}/api"
)
@@ -0,0 +1,102 @@
#
# Copyright 2020 The TensorFlow Authors. All Rights Reserved.
#
# 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
#
# https://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.
if(TARGET eigen OR eigen_POPULATED)
return()
endif()
include(OverridableFetchContent)
OverridableFetchContent_Declare(
eigen
GIT_REPOSITORY https://gitlab.com/libeigen/eigen.git
# Sync with tensorflow/third_party/eigen3/workspace.bzl
GIT_TAG ea13a98decd497a8c5588fb5de71b57bcf10d864
# It's not currently (cmake 3.17) possible to shallow clone with a GIT TAG
# as cmake attempts to git checkout the commit hash after the clone
# which doesn't work as it's a shallow clone hence a different commit hash.
# https://gitlab.kitware.com/cmake/cmake/-/issues/17770
# GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
PREFIX "${CMAKE_BINARY_DIR}"
SOURCE_DIR "${CMAKE_BINARY_DIR}/eigen"
LICENSE_FILE "COPYING.MPL2"
)
OverridableFetchContent_GetProperties(eigen)
if(NOT eigen_POPULATED)
OverridableFetchContent_Populate(eigen)
endif()
# Patch Eigen to disable Fortran compiler check for BLAS and LAPACK tests.
if(NOT EIGEN_DISABLED_FORTRAN_COMPILER_CHECK)
file(WRITE "${eigen_SOURCE_DIR}/cmake/language_support.cmake" "
function(workaround_9220 language language_works)
set(\${language_works} OFF PARENT_SCOPE)
endfunction()"
)
endif()
# Patch Eigen to disable benchmark suite.
if(NOT EIGEN_BUILD_BTL)
file(WRITE "${eigen_SOURCE_DIR}/bench/spbench/CMakeLists.txt" "")
endif()
# Patch Eigen to disable doc generation, as it builds C++ standalone apps with
# the host toolchain which breaks cross compiled builds.
if(NOT EIGEN_GENERATE_DOCS)
file(WRITE "${eigen_SOURCE_DIR}/doc/CMakeLists.txt" "")
file(WRITE "${eigen_SOURCE_DIR}/unsupported/doc/CMakeLists.txt" "")
endif()
set(EIGEN_DISABLED_FORTRAN_COMPILER_CHECK ON CACHE BOOL "Disabled Fortran")
set(EIGEN_LEAVE_TEST_IN_ALL_TARGET OFF CACHE BOOL
"Remove tests from all target."
)
set(BUILD_TESTING OFF CACHE BOOL "Disable tests.")
set(EIGEN_TEST_CXX11 OFF CACHE BOOL "Disable tests of C++11 features.")
set(EIGEN_BUILD_BTL OFF CACHE BOOL "Disable benchmark suite.")
set(EIGEN_BUILD_PKGCONFIG OFF CACHE BOOL "Disable pkg-config.")
set(EIGEN_SPLIT_LARGE_TESTS OFF CACHE BOOL "Disable test splitting.")
set(EIGEN_DEFAULT_TO_ROW_MAJOR OFF CACHE BOOL
"Disable row-major matrix storage"
)
set(EIGEN_TEST_NOQT ON CACHE BOOL "Disable Qt support in tests.")
set(EIGEN_TEST_SSE2 OFF CACHE BOOL "Disable SSE2 test.")
set(EIGEN_TEST_SSE3 OFF CACHE BOOL "Disable SSE3 test.")
set(EIGEN_TEST_SSSE3 OFF CACHE BOOL "Disable SSSE3 test.")
set(EIGEN_TEST_SSE4_1 OFF CACHE BOOL "Disable SSE4.1 test.")
set(EIGEN_TEST_SSE4_2 OFF CACHE BOOL "Disable SSE4.2 test.")
set(EIGEN_TEST_AVX OFF CACHE BOOL "Disable AVX test.")
set(EIGEN_TEST_FMA OFF CACHE BOOL "Disable FMA test.")
set(EIGEN_TEST_AVX512 OFF CACHE BOOL "Disable AVX512 test.")
set(EIGEN_TEST_F16C OFF CACHE BOOL "Disable F16C test.")
set(EIGEN_TEST_ALTIVEC OFF CACHE BOOL "Disable AltiVec test.")
set(EIGEN_TEST_VSX OFF CACHE BOOL "Disable VSX test.")
set(EIGEN_TEST_MSA OFF CACHE BOOL "Disable MSA test.")
set(EIGEN_TEST_NEON OFF CACHE BOOL "Disable NEON test.")
set(EIGEN_TEST_NEON64 OFF CACHE BOOL "Disable NEON64 test.")
set(EIGEN_TEST_Z13 OFF CACHE BOOL "Disable Z13 test.")
set(EIGEN_TEST_Z14 OFF CACHE BOOL "Disable Z14 test.")
set(EIGEN_TEST_OPENMP OFF CACHE BOOL "Disable OpenMP test.")
set(EIGEN_TEST_NO_EXPLICIT_VECTORIZATION OFF CACHE BOOL "Disable vectorization")
set(EIGEN_TEST_X87 OFF CACHE BOOL "Disable X87 instructions test")
set(EIGEN_TEST_32BIT OFF CACHE BOOL "Disable 32-bit instructions test")
set(EIGEN_TEST_NO_EXPLICIT_ALIGNMENT OFF CACHE BOOL "Disable alignment test")
set(EIGEN_TEST_NO_EXCEPTIONS OFF CACHE BOOL "Disable exceptions test")
set(EIGEN_TEST_SYCL OFF CACHE BOOL "Disable Sycl test")
set(EIGEN_SYCL_TRISYCL OFF CACHE BOOL "Disable triSYCL test")
# Make sure only MPL2.0 or more permissively licensed code is included.
add_compile_definitions(EIGEN_MPL2_ONLY)
add_subdirectory("${eigen_SOURCE_DIR}" "${eigen_BINARY_DIR}")
@@ -0,0 +1,47 @@
#
# Copyright 2020 The TensorFlow Authors. All Rights Reserved.
#
# 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
#
# https://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.
if(TARGET farmhash OR farmhash_POPULATED)
return()
endif()
include(OverridableFetchContent)
OverridableFetchContent_Declare(
farmhash
GIT_REPOSITORY https://github.com/google/farmhash
# Sync with tensorflow/third_party/farmhash/workspace.bzl
GIT_TAG 0d859a811870d10f53a594927d0d0b97573ad06d
# It's not currently possible to shallow clone with a GIT TAG
# as cmake attempts to git checkout the commit hash after the clone
# which doesn't work as it's a shallow clone hence a different commit hash.
# https://gitlab.kitware.com/cmake/cmake/-/issues/17770
# GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
SOURCE_DIR "${CMAKE_BINARY_DIR}/farmhash"
)
OverridableFetchContent_GetProperties(farmhash)
if(NOT farmhash_POPULATED)
OverridableFetchContent_Populate(farmhash)
endif()
set(FARMHASH_SOURCE_DIR "${farmhash_SOURCE_DIR}" CACHE PATH
"Source directory for the CMake project."
)
add_subdirectory(
"${CMAKE_CURRENT_LIST_DIR}/farmhash"
"${farmhash_BINARY_DIR}"
)
@@ -0,0 +1,50 @@
#
# Copyright 2020 The TensorFlow Authors. All Rights Reserved.
#
# 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
#
# https://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.
project(farmhash CXX)
set(FARMHASH_SOURCE_DIR "" CACHE PATH
"Directory that contains the farmhash project"
)
if(NOT FARMHASH_SOURCE_DIR)
message(FATAL_ERROR "Must specify source directory")
endif()
# Transcribed from farmhash/src/Makefile.am
include(CheckCXXSourceCompiles)
check_cxx_source_compiles(
"int main(int argc, char* argv[]) { return (int)__builtin_expect(0, 0); }"
FARMHASH_HAS_BUILTIN_EXPECT
)
add_library(farmhash
"${FARMHASH_SOURCE_DIR}/src/farmhash.cc"
"${FARMHASH_SOURCE_DIR}/src/farmhash.h"
)
set_target_properties(farmhash PROPERTIES PUBLIC_HEADER "${FARMHASH_SOURCE_DIR}/src/farmhash.h")
target_include_directories(farmhash PUBLIC $<BUILD_INTERFACE:${FARMHASH_SOURCE_DIR}/src> $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
if(NOT FARMHASH_HAS_BUILTIN_EXPECT)
target_compile_definitions(farmhash PUBLIC -DFARMHASH_NO_BUILTIN_EXPECT)
endif()
if(TFLITE_ENABLE_INSTALL)
install(
TARGETS farmhash
EXPORT tensorflow-liteTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
endif()
@@ -0,0 +1,40 @@
#
# Copyright 2020 The TensorFlow Authors. All Rights Reserved.
#
# 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
#
# https://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.
if(TARGET fft2d OR fft2d_POPULATED)
return()
endif()
include(OverridableFetchContent)
OverridableFetchContent_Declare(
fft2d
URL https://storage.googleapis.com/mirror.tensorflow.org/github.com/petewarden/OouraFFT/archive/v1.0.tar.gz
# Sync with tensorflow/workspace2.bzl
URL_HASH SHA256=5f4dabc2ae21e1f537425d58a49cdca1c49ea11db0d6271e2a4b27e9697548eb
SOURCE_DIR "${CMAKE_BINARY_DIR}/fft2d"
LICENSE_FILE "readme2d.txt"
LICENSE_URL "http://www.kurims.kyoto-u.ac.jp/~ooura/fft.html"
)
OverridableFetchContent_GetProperties(fft2d)
if(NOT fft2d_POPULATED)
OverridableFetchContent_Populate(fft2d)
endif()
set(FFT2D_SOURCE_DIR "${fft2d_SOURCE_DIR}" CACHE PATH "fft2d source")
add_subdirectory(
"${CMAKE_CURRENT_LIST_DIR}/fft2d"
"${fft2d_BINARY_DIR}"
)
@@ -0,0 +1,73 @@
#
# Copyright 2020 The TensorFlow Authors. All Rights Reserved.
#
# 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
#
# https://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.
project(fft2d C)
set(FFT2D_SOURCE_DIR "" CACHE PATH
"Directory that contains the fft2d project"
)
if(NOT FFT2D_SOURCE_DIR)
message(FATAL_ERROR "Must specify source directory")
endif()
# fft2d doesn't have a CMake project so define it here transcribed from
# sample2d/Makefile.
# A developer should link this library if they haven't provided their own
# implementation of these allocation methods.
add_library(fft2d_alloc
"${FFT2D_SOURCE_DIR}/alloc.c"
"${FFT2D_SOURCE_DIR}/alloc.h"
)
target_include_directories(fft2d_alloc PUBLIC "${FFT2D_SOURCE_DIR}")
# Requires implementation of fft2d_alloc.
add_library(fft2d_fft4f2d "${FFT2D_SOURCE_DIR}/fft4f2d.c")
target_include_directories(fft2d_fft4f2d PRIVATE "${FFT2D_SOURCE_DIR}")
add_library(fft2d_fftsg "${FFT2D_SOURCE_DIR}/fftsg.c")
if(NOT CMAKE_SYSTEM_NAME STREQUAL Windows)
target_link_libraries(fft2d_fftsg m)
endif()
install(
TARGETS fft2d_fftsg
EXPORT tensorflow-liteTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
# Requires implementation of fft2d_alloc.
add_library(fft2d_fftsg2d "${FFT2D_SOURCE_DIR}/fftsg2d.c")
target_link_libraries(fft2d_fftsg2d fft2d_fftsg)
target_include_directories(fft2d_fftsg2d PRIVATE "${FFT2D_SOURCE_DIR}")
# Requires implementation of fft2d_alloc.
add_library(fft2d_fftsg3d "${FFT2D_SOURCE_DIR}/fftsg3d.c")
target_link_libraries(fft2d_fftsg3d fft2d_fftsg)
target_include_directories(fft2d_fftsg3d PRIVATE "${FFT2D_SOURCE_DIR}")
add_library(fft2d_shrtdct "${FFT2D_SOURCE_DIR}/shrtdct.c")
add_library(fft2d ALIAS fft2d_fftsg2d)
install(
TARGETS fft2d_fftsg2d
EXPORT tensorflow-liteTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
@@ -0,0 +1,81 @@
#
# Copyright 2020 The TensorFlow Authors. All Rights Reserved.
#
# 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
#
# https://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.
if(TARGET flatbuffers OR flatbuffers_POPULATED)
return()
endif()
include(OverridableFetchContent)
OverridableFetchContent_Declare(
flatbuffers
GIT_REPOSITORY https://github.com/google/flatbuffers
# Keep in sync with tensorflow/third_party/flatbuffers/workspace.bzl
GIT_TAG v25.9.23
# NOTE: b/340264458 - `GIT_SHALLOW TRUE` works for tag name only,
# so if you change the `GIT_TAG` above to a hash rather than a tag name,
# you need to also change the line below to `GIT_SHALLOW FALSE`.
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
SOURCE_DIR "${CMAKE_BINARY_DIR}/flatbuffers"
)
OverridableFetchContent_GetProperties(flatbuffers)
if(NOT flatbuffers_POPULATED)
OverridableFetchContent_Populate(flatbuffers)
endif()
option(FLATBUFFERS_BUILD_TESTS OFF)
# Required for Windows, since it has macros called min & max which
# clashes with std::min
add_definitions(-DNOMINMAX=1)
add_subdirectory(
"${flatbuffers_SOURCE_DIR}"
"${flatbuffers_BINARY_DIR}"
)
remove_definitions(-DNOMINMAX)
# For BuildFlatBuffers.cmake
set(CMAKE_MODULE_PATH
"${flatbuffers_SOURCE_DIR}/CMake"
${CMAKE_MODULE_PATH}
)
# The host-side flatc binary
include(ExternalProject)
# For native flatc build purposes the flatc needs to be included in 'all' target
if(NOT DEFINED FLATC_EXCLUDE_FROM_ALL)
set(FLATC_EXCLUDE_FROM_ALL TRUE)
endif()
# In case of a standalone (native) build of flatc for unit test cross-compilation
# purposes the FLATC_INSTALL_PREFIX is already in cache and is just used in this module.
# In case of standard flatbuffers build (as a dependency) the variable needs to be set.
if(NOT DEFINED FLATC_INSTALL_PREFIX)
set(FLATC_INSTALL_PREFIX <INSTALL_DIR> CACHE PATH "Flatc installation directory")
endif()
ExternalProject_Add(flatbuffers-flatc
PREFIX ${CMAKE_BINARY_DIR}/flatbuffers-flatc
SOURCE_DIR ${flatbuffers_SOURCE_DIR}
CMAKE_ARGS -DCMAKE_CXX_FLAGS="-DNOMINMAX=1"
-DFLATBUFFERS_BUILD_TESTS=OFF
-DFLATBUFFERS_BUILD_FLATLIB=OFF
-DFLATBUFFERS_STATIC_FLATC=OFF
-DFLATBUFFERS_BUILD_FLATHASH=OFF
-DCMAKE_INSTALL_PREFIX=$CACHE{FLATC_INSTALL_PREFIX}
EXCLUDE_FROM_ALL ${FLATC_EXCLUDE_FROM_ALL}
)
@@ -0,0 +1,41 @@
#
# Copyright 2021 The TensorFlow Authors. All Rights Reserved.
#
# 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
#
# https://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.
# Skip installation when xnnpack is used since it also has fp16 headers.
if(TARGET fp16_headers OR fp16_headers_POPULATED OR TFLITE_ENABLE_XNNPACK)
return()
endif()
include(OverridableFetchContent)
OverridableFetchContent_Declare(
fp16_headers
GIT_REPOSITORY https://github.com/Maratyszcza/FP16
# Sync with https://github.com/google/XNNPACK/blob/master/cmake/DownloadFP16.cmake
GIT_TAG 0a92994d729ff76a58f692d3028ca1b64b145d91
GIT_PROGRESS TRUE
PREFIX "${CMAKE_BINARY_DIR}"
SOURCE_DIR "${CMAKE_BINARY_DIR}/fp16_headers"
)
OverridableFetchContent_GetProperties(fp16_headers)
if(NOT fp16_headers)
OverridableFetchContent_Populate(fp16_headers)
endif()
include_directories(
AFTER
"${fp16_headers_SOURCE_DIR}/include"
)
@@ -0,0 +1,53 @@
#
# Copyright 2020 The TensorFlow Authors. All Rights Reserved.
#
# 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
#
# https://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.
if(TARGET gemmlowp OR gemmlowp_POPULATED)
return()
endif()
include(OverridableFetchContent)
OverridableFetchContent_Declare(
gemmlowp
GIT_REPOSITORY https://github.com/google/gemmlowp
# Sync with tensorflow/third_party/gemmlowp/workspace.bzl
GIT_TAG 16e8662c34917be0065110bfcd9cc27d30f52fdf
# It's not currently (cmake 3.17) possible to shallow clone with a GIT TAG
# as cmake attempts to git checkout the commit hash after the clone
# which doesn't work as it's a shallow clone hence a different commit hash.
# https://gitlab.kitware.com/cmake/cmake/-/issues/17770
# GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
SOURCE_DIR "${CMAKE_BINARY_DIR}/gemmlowp"
)
OverridableFetchContent_GetProperties(gemmlowp)
if(NOT gemmlowp_POPULATED)
OverridableFetchContent_Populate(gemmlowp)
endif()
# gemmlowp creates a benchmark target if BUILD_TESTING is set,
# which clashes with a target created by google_benchmark.
# https://github.com/google/gemmlowp/blob/master/contrib/CMakeLists.txt#L85
set(BUILD_TESTING_TMP ${BUILD_TESTING})
set(BUILD_TESTING OFF)
set(GEMMLOWP_SOURCE_DIR "${gemmlowp_SOURCE_DIR}" CACHE PATH "Source directory")
add_subdirectory(
"${gemmlowp_SOURCE_DIR}/contrib"
"${gemmlowp_BINARY_DIR}"
)
set(BUILD_TESTING ${BUILD_TESTING_TMP})
@@ -0,0 +1,49 @@
#
# Copyright 2023 The TensorFlow Authors. All Rights Reserved.
#
# 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
#
# https://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.
if(TARGET ml_dtypes OR ml_dtypes_POPULATED)
return()
endif()
include(OverridableFetchContent)
OverridableFetchContent_Declare(
ml_dtypes
GIT_REPOSITORY https://github.com/jax-ml/ml_dtypes
# Sync with tensorflow/third_party/py/ml_dtypes/workspace.bzl
# Github link:
# https://github.com/jax-ml/ml_dtypes/commit/0fa5313b65efe848c5968a15dd37dd220cc29567
GIT_TAG 00d98cd92ade342fef589c0470379abb27baebe9
# It's not currently possible to shallow clone with a GIT TAG
# as cmake attempts to git checkout the commit hash after the clone
# which doesn't work as it's a shallow clone hence a different commit hash.
# https://gitlab.kitware.com/cmake/cmake/-/issues/17770
# GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
SOURCE_DIR "${CMAKE_BINARY_DIR}/ml_dtypes"
)
OverridableFetchContent_GetProperties(ml_dtypes)
if(NOT ml_dtypes_POPULATED)
OverridableFetchContent_Populate(ml_dtypes)
endif()
set(ML_DTYPES_SOURCE_DIR "${ml_dtypes_SOURCE_DIR}" CACHE PATH
"Source directory for the CMake project."
)
add_subdirectory(
"${CMAKE_CURRENT_LIST_DIR}/ml_dtypes"
"${ml_dtypes_BINARY_DIR}"
)
@@ -0,0 +1,43 @@
#
# Copyright 2023 The TensorFlow Authors. All Rights Reserved.
#
# 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
#
# https://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.
project(ml_dtypes CXX)
set(ML_DTYPES_SOURCE_DIR "" CACHE PATH
"Directory that contains the ml_dtypes project"
)
if(NOT ML_DTYPES_SOURCE_DIR)
message(FATAL_ERROR "Must specify source directory")
endif()
add_library(ml_dtypes INTERFACE)
target_include_directories(ml_dtypes INTERFACE
"$<BUILD_INTERFACE:${ML_DTYPES_SOURCE_DIR}>"
"$<BUILD_INTERFACE:${ML_DTYPES_SOURCE_DIR}/ml_dtypes>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
file(GLOB ML_DTYPES_PUBLIC_HEADERS
${ML_DTYPES_SOURCE_DIR}/ml_dtypes/include/*.h)
set_target_properties(ml_dtypes PROPERTIES
PUBLIC_HEADER "${ML_DTYPES_PUBLIC_HEADERS}")
if(TFLITE_ENABLE_INSTALL)
install(
TARGETS ml_dtypes
EXPORT tensorflow-liteTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
endif()
@@ -0,0 +1,43 @@
#
# Copyright 2020 The TensorFlow Authors. All Rights Reserved.
#
# 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
#
# https://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.
include(ExternalProject)
if(TARGET neon2sse OR neon2sse_POPULATED)
return()
endif()
set(NEON2SSE_URL
https://storage.googleapis.com/mirror.tensorflow.org/github.com/intel/ARM_NEON_2_x86_SSE/archive/a15b489e1222b2087007546b4912e21293ea86ff.tar.gz
)
OverridableFetchContent_Declare(
neon2sse
URL "${NEON2SSE_URL}"
# Sync with tensorflow/workspace2.bzl
URL_HASH SHA256=019fbc7ec25860070a1d90e12686fc160cfb33e22aa063c80f52b363f1361e9d
LICENSE_FILE LICENSE
LICENSE_URL "${NEON2SSE_URL}"
SOURCE_DIR "${CMAKE_BINARY_DIR}/neon2sse"
)
OverridableFetchContent_GetProperties(neon2sse)
if(NOT neon2sse_POPULATED)
OverridableFetchContent_Populate(neon2sse)
endif()
add_subdirectory(
"${neon2sse_SOURCE_DIR}"
"${neon2sse_BINARY_DIR}"
)
@@ -0,0 +1,40 @@
#
# Copyright 2020 The TensorFlow Authors. All Rights Reserved.
#
# 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
#
# https://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.
if(TARGET opencl_headers OR opencl_headers_POPULATED)
return()
endif()
include(OverridableFetchContent)
OverridableFetchContent_Declare(
opencl_headers
GIT_REPOSITORY https://github.com/KhronosGroup/OpenCL-Headers
# Sync with tensorflow/third_party/opencl_headers/workspace.bzl
GIT_TAG dcd5bede6859d26833cd85f0d6bbcee7382dc9b3
GIT_PROGRESS TRUE
PREFIX "${CMAKE_BINARY_DIR}"
SOURCE_DIR "${CMAKE_BINARY_DIR}/opencl_headers"
)
OverridableFetchContent_GetProperties(opencl_headers)
if(NOT opencl_headers)
OverridableFetchContent_Populate(opencl_headers)
endif()
include_directories(
AFTER
"${opencl_headers_SOURCE_DIR}/"
)
@@ -0,0 +1,43 @@
#
# Copyright 2020 The TensorFlow Authors. All Rights Reserved.
#
# 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
#
# https://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.
if(TARGET opengl_headers OR opengl_headers_POPULATED)
return()
endif()
include(OverridableFetchContent)
OverridableFetchContent_Declare(
opengl_headers
GIT_REPOSITORY https://github.com/KhronosGroup/OpenGL-Registry.git
# No reference in TensorFlow Bazel rule since it's used for GPU Delegate
# build without using Android NDK.
GIT_TAG 0cb0880d91581d34f96899c86fc1bf35627b4b81
GIT_PROGRESS TRUE
PREFIX "${CMAKE_BINARY_DIR}"
SOURCE_DIR "${CMAKE_BINARY_DIR}/opengl_headers"
# Per https://www.khronos.org/legal/Khronos_Apache_2.0_CLA
LICENSE_URL "https://www.apache.org/licenses/LICENSE-2.0.txt"
)
OverridableFetchContent_GetProperties(opengl_headers)
if(NOT opengl_headers)
OverridableFetchContent_Populate(opengl_headers)
endif()
include_directories(
AFTER
"${opengl_headers_SOURCE_DIR}/api"
)
@@ -0,0 +1,50 @@
#
# Copyright 2024 The TensorFlow Authors. All Rights Reserved.
#
# 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
#
# https://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.
include(OverridableFetchContent)
OverridableFetchContent_Declare(
protobuf
GIT_REPOSITORY https://github.com/protocolbuffers/protobuf
# Sync with tensorflow/third_party/protobuf/protobuf.patch
GIT_TAG 90b73ac3f0b10320315c2ca0d03a5a9b095d2f66
GIT_PROGRESS TRUE
PREFIX "${CMAKE_BINARY_DIR}"
SOURCE_DIR "${CMAKE_BINARY_DIR}/protobuf"
)
set(protobuf_ABSL_PROVIDER "package" CACHE STRING "" FORCE)
set(protobuf_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(protobuf_BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
set(protobuf_INSTALL OFF CACHE BOOL "" FORCE)
set(protobuf_WITH_ZLIB OFF CACHE BOOL "" FORCE)
set(protobuf_BUILD_PROTOC_BINARIES ON CACHE BOOL "" FORCE)
OverridableFetchContent_GetProperties(protobuf)
if(NOT protobuf_POPULATED)
OverridableFetchContent_Populate(protobuf)
endif()
# Export basic variables expected by consumers
set(Protobuf_INCLUDE_DIR "${protobuf_SOURCE_DIR}/src" CACHE INTERNAL "")
set(Protobuf_LIBRARIES protobuf::libprotobuf CACHE INTERNAL "")
# Avoid adding the same subdirectory twice when multiple find_package calls
# occur in a single configure (e.g., from different subprojects).
if(NOT TARGET protobuf::libprotobuf)
add_subdirectory(${protobuf_SOURCE_DIR} ${protobuf_BINARY_DIR})
endif()
set(Protobuf_PROTOC_EXECUTABLE protoc CACHE INTERNAL "")
@@ -0,0 +1,40 @@
#
# Copyright 2020 The TensorFlow Authors. All Rights Reserved.
#
# 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
#
# https://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.
if(TARGET ruy OR ruy_POPULATED)
return()
endif()
include(OverridableFetchContent)
OverridableFetchContent_Declare(
ruy
GIT_REPOSITORY https://github.com/google/ruy
# Sync with tensorflow/third_party/ruy/workspace.bzl
GIT_TAG 3286a34cc8de6149ac6844107dfdffac91531e72
GIT_PROGRESS TRUE
SOURCE_DIR "${CMAKE_BINARY_DIR}/ruy"
)
OverridableFetchContent_GetProperties(ruy)
if(NOT ruy_POPULATED)
OverridableFetchContent_Populate(ruy)
endif()
set(RUY_SOURCE_DIR "${ruy_SOURCE_DIR}" CACHE PATH "RUY source directory")
add_subdirectory(
"${ruy_SOURCE_DIR}"
"${ruy_BINARY_DIR}"
)
@@ -0,0 +1,40 @@
#
# Copyright 2020 The TensorFlow Authors. All Rights Reserved.
#
# 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
#
# https://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.
if(TARGET vulkan_headers OR vulkan_headers_POPULATED)
return()
endif()
include(OverridableFetchContent)
OverridableFetchContent_Declare(
vulkan_headers
GIT_REPOSITORY https://github.com/KhronosGroup/Vulkan-Headers
# Sync with tensorflow/third_party/vulkan_headers/workspace.bzl
GIT_TAG 32c07c0c5334aea069e518206d75e002ccd85389
GIT_PROGRESS TRUE
PREFIX "${CMAKE_BINARY_DIR}"
SOURCE_DIR "${CMAKE_BINARY_DIR}/vulkan_headers"
)
OverridableFetchContent_GetProperties(vulkan_headers)
if(NOT vulkan_headers)
OverridableFetchContent_Populate(vulkan_headers)
endif()
include_directories(
AFTER
"${vulkan_headers_SOURCE_DIR}/include"
)
@@ -0,0 +1,54 @@
#
# Copyright 2020 The TensorFlow Authors. All Rights Reserved.
#
# 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
#
# https://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.
if(TARGET xnnpack OR xnnpack_POPULATED)
return()
endif()
include(OverridableFetchContent)
OverridableFetchContent_Declare(
xnnpack
GIT_REPOSITORY https://github.com/google/XNNPACK
# Sync with tensorflow/workspace2.bzl
GIT_TAG efa2e754e390ab3024f6aa617385cb28bdfa9969
GIT_PROGRESS TRUE
PREFIX "${CMAKE_BINARY_DIR}"
SOURCE_DIR "${CMAKE_BINARY_DIR}/xnnpack"
)
OverridableFetchContent_GetProperties(xnnpack)
if(NOT xnnpack_POPULATED)
OverridableFetchContent_Populate(xnnpack)
endif()
# May consider setting XNNPACK_USE_SYSTEM_LIBS if we want to control all
# dependencies by TFLite.
set(XNNPACK_BUILD_TESTS OFF CACHE BOOL "Disable XNNPACK test.")
set(XNNPACK_BUILD_BENCHMARKS OFF CACHE BOOL "Disable XNNPACK benchmarks.")
# The following line adds project of PTHREADPOOL, FP16 and XNNPACK which are
# needed to compile XNNPACK delegate of TFLite.
# Note, we introduce an intermediate subdirectory, see ${TFLITE_SOURCE_DIR}/tools/cmake/modules/xnnpack/CMakeLists.txt
# for details.
add_subdirectory(${TFLITE_SOURCE_DIR}/tools/cmake/modules/xnnpack)
include_directories(
AFTER
"${PTHREADPOOL_SOURCE_DIR}/include"
"${FP16_SOURCE_DIR}/include"
"${XNNPACK_SOURCE_DIR}/include"
"${XNNPACK_SOURCE_DIR}"
"${CPUINFO_SOURCE_DIR}/"
)
@@ -0,0 +1,33 @@
#
# Copyright 2022 The TensorFlow Authors. All Rights Reserved.
#
# 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
#
# https://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.
# The "-mcpu=" switch might be introduced externaly into CMake: either in <LANG>_FLAGS or
# as part of CC, CXX, ASM environmental variables (to be stored in CMAKE_<LANG>_COMPILER_ARG1).
# This switch is not compatible with XNNPACK build mechanism and causes the XNNPACK compilation
# break due to "unsupported instructions". This switch needs to be removed for XNNPACK
# In order to isolate the changes only for XNNPACK and its depencencies, a subfolder is
# introduced.
foreach(FLAG IN ITEMS CMAKE_ASM_FLAGS CMAKE_ASM_COMPILER_ARG1 CMAKE_C_FLAGS CMAKE_C_COMPILER_ARG1 CMAKE_CXX_FLAGS CMAKE_CXX_COMPILER_ARG1)
if(${FLAG})
string(REGEX REPLACE "-mcpu=[-a-zA-Z0-9_.^$*+?]*" "" _tmp ${${FLAG}})
set(${FLAG} ${_tmp})
endif()
endforeach()
add_subdirectory(
"${xnnpack_SOURCE_DIR}"
"${xnnpack_BINARY_DIR}"
)