Implement FetchPackage; a simple wrapper around FindOrFetch.
FetchPackage calls FindOrFetch, but sets USE_SYSTEM_PACKAGE to OFF (i.e. do not find, just fetch). It also sets EXCLUDE_FROM_ALL. PiperOrigin-RevId: 822565180 Change-Id: I70476f57b8d3371cefd02e840add279423913f3f
This commit is contained in:
committed by
Copybara-Service
parent
160b9480f9
commit
f217a8f987
+130
-78
@@ -11,7 +11,7 @@
|
|||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
|
||||||
#.rst:
|
#.rst:
|
||||||
# FindOrFetch
|
# FindOrFetch
|
||||||
# ----------------------
|
# ----------------------
|
||||||
@@ -56,85 +56,137 @@
|
|||||||
# https://cmake.org/cmake/help/latest/module/FetchContent.html#variables to
|
# https://cmake.org/cmake/help/latest/module/FetchContent.html#variables to
|
||||||
# override this macro behaviour.
|
# override this macro behaviour.
|
||||||
|
|
||||||
if(COMMAND FindOrFetch)
|
if(NOT COMMAND FindOrFetch)
|
||||||
return()
|
macro(FindOrFetch)
|
||||||
|
if(NOT FetchContent)
|
||||||
|
include(FetchContent)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Parse arguments.
|
||||||
|
set(options EXCLUDE_FROM_ALL)
|
||||||
|
set(one_value_args
|
||||||
|
USE_SYSTEM_PACKAGE
|
||||||
|
PACKAGE_NAME
|
||||||
|
LIBRARY_NAME
|
||||||
|
GIT_REPO
|
||||||
|
GIT_TAG
|
||||||
|
)
|
||||||
|
set(multi_value_args PATCH_COMMAND TARGETS)
|
||||||
|
cmake_parse_arguments(
|
||||||
|
_ARGS
|
||||||
|
"${options}"
|
||||||
|
"${one_value_args}"
|
||||||
|
"${multi_value_args}"
|
||||||
|
${ARGN}
|
||||||
|
)
|
||||||
|
|
||||||
|
# Check if all targets are found.
|
||||||
|
if(NOT _ARGS_TARGETS)
|
||||||
|
message(FATAL_ERROR "mujoco::FindOrFetch: TARGETS must be specified.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(targets_found TRUE)
|
||||||
|
message(CHECK_START
|
||||||
|
"mujoco::FindOrFetch: checking for targets in package `${_ARGS_PACKAGE_NAME}`"
|
||||||
|
)
|
||||||
|
foreach(target ${_ARGS_TARGETS})
|
||||||
|
if(NOT TARGET ${target})
|
||||||
|
message(CHECK_FAIL "target `${target}` not defined.")
|
||||||
|
set(targets_found FALSE)
|
||||||
|
break()
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
# If targets are not found, use `find_package` or `FetchContent...` to get it.
|
||||||
|
if(NOT targets_found)
|
||||||
|
if(${_ARGS_USE_SYSTEM_PACKAGE})
|
||||||
|
message(CHECK_START
|
||||||
|
"mujoco::FindOrFetch: finding `${_ARGS_PACKAGE_NAME}` in system packages..."
|
||||||
|
)
|
||||||
|
find_package(${_ARGS_PACKAGE_NAME} REQUIRED)
|
||||||
|
message(CHECK_PASS "found")
|
||||||
|
else()
|
||||||
|
message(CHECK_START
|
||||||
|
"mujoco::FindOrFetch: Using FetchContent to retrieve `${_ARGS_LIBRARY_NAME}`"
|
||||||
|
)
|
||||||
|
FetchContent_Declare(
|
||||||
|
${_ARGS_LIBRARY_NAME}
|
||||||
|
GIT_REPOSITORY ${_ARGS_GIT_REPO}
|
||||||
|
GIT_TAG ${_ARGS_GIT_TAG}
|
||||||
|
GIT_SHALLOW FALSE
|
||||||
|
PATCH_COMMAND ${_ARGS_PATCH_COMMAND}
|
||||||
|
UPDATE_DISCONNECTED TRUE
|
||||||
|
)
|
||||||
|
if(${_ARGS_EXCLUDE_FROM_ALL})
|
||||||
|
FetchContent_GetProperties(${_ARGS_LIBRARY_NAME})
|
||||||
|
if(NOT ${${_ARGS_LIBRARY_NAME}_POPULATED})
|
||||||
|
FetchContent_Populate(${_ARGS_LIBRARY_NAME})
|
||||||
|
add_subdirectory(
|
||||||
|
${${_ARGS_LIBRARY_NAME}_SOURCE_DIR} ${${_ARGS_LIBRARY_NAME}_BINARY_DIR}
|
||||||
|
EXCLUDE_FROM_ALL
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
FetchContent_MakeAvailable(${_ARGS_LIBRARY_NAME})
|
||||||
|
endif()
|
||||||
|
message(CHECK_PASS "Done")
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
message(CHECK_PASS "found")
|
||||||
|
endif()
|
||||||
|
endmacro()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
macro(FindOrFetch)
|
|
||||||
if(NOT FetchContent)
|
|
||||||
include(FetchContent)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Parse arguments.
|
#.rst:
|
||||||
set(options EXCLUDE_FROM_ALL)
|
# FetchPackage
|
||||||
set(one_value_args
|
# ----------------------
|
||||||
USE_SYSTEM_PACKAGE
|
#
|
||||||
PACKAGE_NAME
|
# Fetches a package from a Git repository in order to satisfy dependencies.
|
||||||
LIBRARY_NAME
|
#
|
||||||
GIT_REPO
|
# FetchPackage([PACKAGE_NAME [name]]
|
||||||
GIT_TAG
|
# [GIT_REPO [repo]]
|
||||||
)
|
# [GIT_TAG [tag]]
|
||||||
set(multi_value_args PATCH_COMMAND TARGETS)
|
# [PATCH_COMMAND [cmd] [args]]
|
||||||
cmake_parse_arguments(
|
# )
|
||||||
_ARGS
|
#
|
||||||
"${options}"
|
# The command has the following parameters:
|
||||||
"${one_value_args}"
|
#
|
||||||
"${multi_value_args}"
|
# Arguments:
|
||||||
${ARGN}
|
# - ``PACKAGE_NAME`` name of the package.
|
||||||
)
|
# - ``GIT_REPO`` git repository to fetch the library from.
|
||||||
|
# - ``GIT_TAG`` tag reference when fetching the library from the git repo.
|
||||||
# Check if all targets are found.
|
# - ``PATCH_COMMAND`` Specifies a custom command to patch the sources after an
|
||||||
if(NOT _ARGS_TARGETS)
|
# update. See https://cmake.org/cmake/help/latest/module/ExternalProject.html#command:externalproject_add
|
||||||
message(FATAL_ERROR "mujoco::FindOrFetch: TARGETS must be specified.")
|
# for details on the parameter.
|
||||||
endif()
|
# - ``TARGETS`` (optional) list of targets to be satisfied. If any of these
|
||||||
|
# targets are not currently defined, this macro will attempt to fetch the
|
||||||
set(targets_found TRUE)
|
# package. If not specified, the package name will be used as the target.
|
||||||
message(CHECK_START
|
#
|
||||||
"mujoco::FindOrFetch: checking for targets in package `${_ARGS_PACKAGE_NAME}`"
|
# Note: This is a wrapper around FindOrFetch that sets EXCLUDE_FROM_ALL and
|
||||||
)
|
# USE_SYSTEM_PACKAGE to OFF.
|
||||||
foreach(target ${_ARGS_TARGETS})
|
if(NOT COMMAND FetchPackage)
|
||||||
if(NOT TARGET ${target})
|
function(FetchPackage)
|
||||||
message(CHECK_FAIL "target `${target}` not defined.")
|
cmake_parse_arguments(
|
||||||
set(targets_found FALSE)
|
_ARGS
|
||||||
break()
|
"EXCLUDE_FROM_ALL"
|
||||||
|
"PACKAGE_NAME;GIT_REPO;GIT_TAG"
|
||||||
|
"PATCH_COMMAND;TARGETS"
|
||||||
|
${ARGN}
|
||||||
|
)
|
||||||
|
if(NOT _ARGS_TARGETS)
|
||||||
|
set(_ARGS_TARGETS ${_ARGS_PACKAGE_NAME})
|
||||||
endif()
|
endif()
|
||||||
endforeach()
|
|
||||||
|
|
||||||
# If targets are not found, use `find_package` or `FetchContent...` to get it.
|
FindOrFetch(
|
||||||
if(NOT targets_found)
|
PACKAGE_NAME ${_ARGS_PACKAGE_NAME}
|
||||||
if(${_ARGS_USE_SYSTEM_PACKAGE})
|
LIBRARY_NAME ${_ARGS_PACKAGE_NAME}
|
||||||
message(CHECK_START
|
GIT_REPO ${_ARGS_GIT_REPO}
|
||||||
"mujoco::FindOrFetch: finding `${_ARGS_PACKAGE_NAME}` in system packages..."
|
GIT_TAG ${_ARGS_GIT_TAG}
|
||||||
)
|
PATCH_COMMAND ${_ARGS_PATCH_COMMAND}
|
||||||
find_package(${_ARGS_PACKAGE_NAME} REQUIRED)
|
TARGETS ${_ARGS_TARGETS}
|
||||||
message(CHECK_PASS "found")
|
USE_SYSTEM_PACKAGE OFF
|
||||||
else()
|
EXCLUDE_FROM_ALL
|
||||||
message(CHECK_START
|
)
|
||||||
"mujoco::FindOrFetch: Using FetchContent to retrieve `${_ARGS_LIBRARY_NAME}`"
|
endfunction()
|
||||||
)
|
endif()
|
||||||
FetchContent_Declare(
|
|
||||||
${_ARGS_LIBRARY_NAME}
|
|
||||||
GIT_REPOSITORY ${_ARGS_GIT_REPO}
|
|
||||||
GIT_TAG ${_ARGS_GIT_TAG}
|
|
||||||
GIT_SHALLOW FALSE
|
|
||||||
PATCH_COMMAND ${_ARGS_PATCH_COMMAND}
|
|
||||||
UPDATE_DISCONNECTED TRUE
|
|
||||||
)
|
|
||||||
if(${_ARGS_EXCLUDE_FROM_ALL})
|
|
||||||
FetchContent_GetProperties(${_ARGS_LIBRARY_NAME})
|
|
||||||
if(NOT ${${_ARGS_LIBRARY_NAME}_POPULATED})
|
|
||||||
FetchContent_Populate(${_ARGS_LIBRARY_NAME})
|
|
||||||
add_subdirectory(
|
|
||||||
${${_ARGS_LIBRARY_NAME}_SOURCE_DIR} ${${_ARGS_LIBRARY_NAME}_BINARY_DIR}
|
|
||||||
EXCLUDE_FROM_ALL
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
else()
|
|
||||||
FetchContent_MakeAvailable(${_ARGS_LIBRARY_NAME})
|
|
||||||
endif()
|
|
||||||
message(CHECK_PASS "Done")
|
|
||||||
endif()
|
|
||||||
else()
|
|
||||||
message(CHECK_PASS "found")
|
|
||||||
endif()
|
|
||||||
endmacro()
|
|
||||||
|
|||||||
+130
-78
@@ -11,7 +11,7 @@
|
|||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
|
||||||
#.rst:
|
#.rst:
|
||||||
# FindOrFetch
|
# FindOrFetch
|
||||||
# ----------------------
|
# ----------------------
|
||||||
@@ -56,85 +56,137 @@
|
|||||||
# https://cmake.org/cmake/help/latest/module/FetchContent.html#variables to
|
# https://cmake.org/cmake/help/latest/module/FetchContent.html#variables to
|
||||||
# override this macro behaviour.
|
# override this macro behaviour.
|
||||||
|
|
||||||
if(COMMAND FindOrFetch)
|
if(NOT COMMAND FindOrFetch)
|
||||||
return()
|
macro(FindOrFetch)
|
||||||
|
if(NOT FetchContent)
|
||||||
|
include(FetchContent)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Parse arguments.
|
||||||
|
set(options EXCLUDE_FROM_ALL)
|
||||||
|
set(one_value_args
|
||||||
|
USE_SYSTEM_PACKAGE
|
||||||
|
PACKAGE_NAME
|
||||||
|
LIBRARY_NAME
|
||||||
|
GIT_REPO
|
||||||
|
GIT_TAG
|
||||||
|
)
|
||||||
|
set(multi_value_args PATCH_COMMAND TARGETS)
|
||||||
|
cmake_parse_arguments(
|
||||||
|
_ARGS
|
||||||
|
"${options}"
|
||||||
|
"${one_value_args}"
|
||||||
|
"${multi_value_args}"
|
||||||
|
${ARGN}
|
||||||
|
)
|
||||||
|
|
||||||
|
# Check if all targets are found.
|
||||||
|
if(NOT _ARGS_TARGETS)
|
||||||
|
message(FATAL_ERROR "mujoco::FindOrFetch: TARGETS must be specified.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(targets_found TRUE)
|
||||||
|
message(CHECK_START
|
||||||
|
"mujoco::FindOrFetch: checking for targets in package `${_ARGS_PACKAGE_NAME}`"
|
||||||
|
)
|
||||||
|
foreach(target ${_ARGS_TARGETS})
|
||||||
|
if(NOT TARGET ${target})
|
||||||
|
message(CHECK_FAIL "target `${target}` not defined.")
|
||||||
|
set(targets_found FALSE)
|
||||||
|
break()
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
# If targets are not found, use `find_package` or `FetchContent...` to get it.
|
||||||
|
if(NOT targets_found)
|
||||||
|
if(${_ARGS_USE_SYSTEM_PACKAGE})
|
||||||
|
message(CHECK_START
|
||||||
|
"mujoco::FindOrFetch: finding `${_ARGS_PACKAGE_NAME}` in system packages..."
|
||||||
|
)
|
||||||
|
find_package(${_ARGS_PACKAGE_NAME} REQUIRED)
|
||||||
|
message(CHECK_PASS "found")
|
||||||
|
else()
|
||||||
|
message(CHECK_START
|
||||||
|
"mujoco::FindOrFetch: Using FetchContent to retrieve `${_ARGS_LIBRARY_NAME}`"
|
||||||
|
)
|
||||||
|
FetchContent_Declare(
|
||||||
|
${_ARGS_LIBRARY_NAME}
|
||||||
|
GIT_REPOSITORY ${_ARGS_GIT_REPO}
|
||||||
|
GIT_TAG ${_ARGS_GIT_TAG}
|
||||||
|
GIT_SHALLOW FALSE
|
||||||
|
PATCH_COMMAND ${_ARGS_PATCH_COMMAND}
|
||||||
|
UPDATE_DISCONNECTED TRUE
|
||||||
|
)
|
||||||
|
if(${_ARGS_EXCLUDE_FROM_ALL})
|
||||||
|
FetchContent_GetProperties(${_ARGS_LIBRARY_NAME})
|
||||||
|
if(NOT ${${_ARGS_LIBRARY_NAME}_POPULATED})
|
||||||
|
FetchContent_Populate(${_ARGS_LIBRARY_NAME})
|
||||||
|
add_subdirectory(
|
||||||
|
${${_ARGS_LIBRARY_NAME}_SOURCE_DIR} ${${_ARGS_LIBRARY_NAME}_BINARY_DIR}
|
||||||
|
EXCLUDE_FROM_ALL
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
FetchContent_MakeAvailable(${_ARGS_LIBRARY_NAME})
|
||||||
|
endif()
|
||||||
|
message(CHECK_PASS "Done")
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
message(CHECK_PASS "found")
|
||||||
|
endif()
|
||||||
|
endmacro()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
macro(FindOrFetch)
|
|
||||||
if(NOT FetchContent)
|
|
||||||
include(FetchContent)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Parse arguments.
|
#.rst:
|
||||||
set(options EXCLUDE_FROM_ALL)
|
# FetchPackage
|
||||||
set(one_value_args
|
# ----------------------
|
||||||
USE_SYSTEM_PACKAGE
|
#
|
||||||
PACKAGE_NAME
|
# Fetches a package from a Git repository in order to satisfy dependencies.
|
||||||
LIBRARY_NAME
|
#
|
||||||
GIT_REPO
|
# FetchPackage([PACKAGE_NAME [name]]
|
||||||
GIT_TAG
|
# [GIT_REPO [repo]]
|
||||||
)
|
# [GIT_TAG [tag]]
|
||||||
set(multi_value_args PATCH_COMMAND TARGETS)
|
# [PATCH_COMMAND [cmd] [args]]
|
||||||
cmake_parse_arguments(
|
# )
|
||||||
_ARGS
|
#
|
||||||
"${options}"
|
# The command has the following parameters:
|
||||||
"${one_value_args}"
|
#
|
||||||
"${multi_value_args}"
|
# Arguments:
|
||||||
${ARGN}
|
# - ``PACKAGE_NAME`` name of the package.
|
||||||
)
|
# - ``GIT_REPO`` git repository to fetch the library from.
|
||||||
|
# - ``GIT_TAG`` tag reference when fetching the library from the git repo.
|
||||||
# Check if all targets are found.
|
# - ``PATCH_COMMAND`` Specifies a custom command to patch the sources after an
|
||||||
if(NOT _ARGS_TARGETS)
|
# update. See https://cmake.org/cmake/help/latest/module/ExternalProject.html#command:externalproject_add
|
||||||
message(FATAL_ERROR "mujoco::FindOrFetch: TARGETS must be specified.")
|
# for details on the parameter.
|
||||||
endif()
|
# - ``TARGETS`` (optional) list of targets to be satisfied. If any of these
|
||||||
|
# targets are not currently defined, this macro will attempt to fetch the
|
||||||
set(targets_found TRUE)
|
# package. If not specified, the package name will be used as the target.
|
||||||
message(CHECK_START
|
#
|
||||||
"mujoco::FindOrFetch: checking for targets in package `${_ARGS_PACKAGE_NAME}`"
|
# Note: This is a wrapper around FindOrFetch that sets EXCLUDE_FROM_ALL and
|
||||||
)
|
# USE_SYSTEM_PACKAGE to OFF.
|
||||||
foreach(target ${_ARGS_TARGETS})
|
if(NOT COMMAND FetchPackage)
|
||||||
if(NOT TARGET ${target})
|
function(FetchPackage)
|
||||||
message(CHECK_FAIL "target `${target}` not defined.")
|
cmake_parse_arguments(
|
||||||
set(targets_found FALSE)
|
_ARGS
|
||||||
break()
|
"EXCLUDE_FROM_ALL"
|
||||||
|
"PACKAGE_NAME;GIT_REPO;GIT_TAG"
|
||||||
|
"PATCH_COMMAND;TARGETS"
|
||||||
|
${ARGN}
|
||||||
|
)
|
||||||
|
if(NOT _ARGS_TARGETS)
|
||||||
|
set(_ARGS_TARGETS ${_ARGS_PACKAGE_NAME})
|
||||||
endif()
|
endif()
|
||||||
endforeach()
|
|
||||||
|
|
||||||
# If targets are not found, use `find_package` or `FetchContent...` to get it.
|
FindOrFetch(
|
||||||
if(NOT targets_found)
|
PACKAGE_NAME ${_ARGS_PACKAGE_NAME}
|
||||||
if(${_ARGS_USE_SYSTEM_PACKAGE})
|
LIBRARY_NAME ${_ARGS_PACKAGE_NAME}
|
||||||
message(CHECK_START
|
GIT_REPO ${_ARGS_GIT_REPO}
|
||||||
"mujoco::FindOrFetch: finding `${_ARGS_PACKAGE_NAME}` in system packages..."
|
GIT_TAG ${_ARGS_GIT_TAG}
|
||||||
)
|
PATCH_COMMAND ${_ARGS_PATCH_COMMAND}
|
||||||
find_package(${_ARGS_PACKAGE_NAME} REQUIRED)
|
TARGETS ${_ARGS_TARGETS}
|
||||||
message(CHECK_PASS "found")
|
USE_SYSTEM_PACKAGE OFF
|
||||||
else()
|
EXCLUDE_FROM_ALL
|
||||||
message(CHECK_START
|
)
|
||||||
"mujoco::FindOrFetch: Using FetchContent to retrieve `${_ARGS_LIBRARY_NAME}`"
|
endfunction()
|
||||||
)
|
endif()
|
||||||
FetchContent_Declare(
|
|
||||||
${_ARGS_LIBRARY_NAME}
|
|
||||||
GIT_REPOSITORY ${_ARGS_GIT_REPO}
|
|
||||||
GIT_TAG ${_ARGS_GIT_TAG}
|
|
||||||
GIT_SHALLOW FALSE
|
|
||||||
PATCH_COMMAND ${_ARGS_PATCH_COMMAND}
|
|
||||||
UPDATE_DISCONNECTED TRUE
|
|
||||||
)
|
|
||||||
if(${_ARGS_EXCLUDE_FROM_ALL})
|
|
||||||
FetchContent_GetProperties(${_ARGS_LIBRARY_NAME})
|
|
||||||
if(NOT ${${_ARGS_LIBRARY_NAME}_POPULATED})
|
|
||||||
FetchContent_Populate(${_ARGS_LIBRARY_NAME})
|
|
||||||
add_subdirectory(
|
|
||||||
${${_ARGS_LIBRARY_NAME}_SOURCE_DIR} ${${_ARGS_LIBRARY_NAME}_BINARY_DIR}
|
|
||||||
EXCLUDE_FROM_ALL
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
else()
|
|
||||||
FetchContent_MakeAvailable(${_ARGS_LIBRARY_NAME})
|
|
||||||
endif()
|
|
||||||
message(CHECK_PASS "Done")
|
|
||||||
endif()
|
|
||||||
else()
|
|
||||||
message(CHECK_PASS "found")
|
|
||||||
endif()
|
|
||||||
endmacro()
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
|
||||||
#.rst:
|
#.rst:
|
||||||
# FindOrFetch
|
# FindOrFetch
|
||||||
# ----------------------
|
# ----------------------
|
||||||
@@ -56,85 +56,137 @@
|
|||||||
# https://cmake.org/cmake/help/latest/module/FetchContent.html#variables to
|
# https://cmake.org/cmake/help/latest/module/FetchContent.html#variables to
|
||||||
# override this macro behaviour.
|
# override this macro behaviour.
|
||||||
|
|
||||||
if(COMMAND FindOrFetch)
|
if(NOT COMMAND FindOrFetch)
|
||||||
return()
|
macro(FindOrFetch)
|
||||||
|
if(NOT FetchContent)
|
||||||
|
include(FetchContent)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Parse arguments.
|
||||||
|
set(options EXCLUDE_FROM_ALL)
|
||||||
|
set(one_value_args
|
||||||
|
USE_SYSTEM_PACKAGE
|
||||||
|
PACKAGE_NAME
|
||||||
|
LIBRARY_NAME
|
||||||
|
GIT_REPO
|
||||||
|
GIT_TAG
|
||||||
|
)
|
||||||
|
set(multi_value_args PATCH_COMMAND TARGETS)
|
||||||
|
cmake_parse_arguments(
|
||||||
|
_ARGS
|
||||||
|
"${options}"
|
||||||
|
"${one_value_args}"
|
||||||
|
"${multi_value_args}"
|
||||||
|
${ARGN}
|
||||||
|
)
|
||||||
|
|
||||||
|
# Check if all targets are found.
|
||||||
|
if(NOT _ARGS_TARGETS)
|
||||||
|
message(FATAL_ERROR "mujoco::FindOrFetch: TARGETS must be specified.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(targets_found TRUE)
|
||||||
|
message(CHECK_START
|
||||||
|
"mujoco::FindOrFetch: checking for targets in package `${_ARGS_PACKAGE_NAME}`"
|
||||||
|
)
|
||||||
|
foreach(target ${_ARGS_TARGETS})
|
||||||
|
if(NOT TARGET ${target})
|
||||||
|
message(CHECK_FAIL "target `${target}` not defined.")
|
||||||
|
set(targets_found FALSE)
|
||||||
|
break()
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
# If targets are not found, use `find_package` or `FetchContent...` to get it.
|
||||||
|
if(NOT targets_found)
|
||||||
|
if(${_ARGS_USE_SYSTEM_PACKAGE})
|
||||||
|
message(CHECK_START
|
||||||
|
"mujoco::FindOrFetch: finding `${_ARGS_PACKAGE_NAME}` in system packages..."
|
||||||
|
)
|
||||||
|
find_package(${_ARGS_PACKAGE_NAME} REQUIRED)
|
||||||
|
message(CHECK_PASS "found")
|
||||||
|
else()
|
||||||
|
message(CHECK_START
|
||||||
|
"mujoco::FindOrFetch: Using FetchContent to retrieve `${_ARGS_LIBRARY_NAME}`"
|
||||||
|
)
|
||||||
|
FetchContent_Declare(
|
||||||
|
${_ARGS_LIBRARY_NAME}
|
||||||
|
GIT_REPOSITORY ${_ARGS_GIT_REPO}
|
||||||
|
GIT_TAG ${_ARGS_GIT_TAG}
|
||||||
|
GIT_SHALLOW FALSE
|
||||||
|
PATCH_COMMAND ${_ARGS_PATCH_COMMAND}
|
||||||
|
UPDATE_DISCONNECTED TRUE
|
||||||
|
)
|
||||||
|
if(${_ARGS_EXCLUDE_FROM_ALL})
|
||||||
|
FetchContent_GetProperties(${_ARGS_LIBRARY_NAME})
|
||||||
|
if(NOT ${${_ARGS_LIBRARY_NAME}_POPULATED})
|
||||||
|
FetchContent_Populate(${_ARGS_LIBRARY_NAME})
|
||||||
|
add_subdirectory(
|
||||||
|
${${_ARGS_LIBRARY_NAME}_SOURCE_DIR} ${${_ARGS_LIBRARY_NAME}_BINARY_DIR}
|
||||||
|
EXCLUDE_FROM_ALL
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
FetchContent_MakeAvailable(${_ARGS_LIBRARY_NAME})
|
||||||
|
endif()
|
||||||
|
message(CHECK_PASS "Done")
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
message(CHECK_PASS "found")
|
||||||
|
endif()
|
||||||
|
endmacro()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
macro(FindOrFetch)
|
|
||||||
if(NOT FetchContent)
|
|
||||||
include(FetchContent)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Parse arguments.
|
#.rst:
|
||||||
set(options EXCLUDE_FROM_ALL)
|
# FetchPackage
|
||||||
set(one_value_args
|
# ----------------------
|
||||||
USE_SYSTEM_PACKAGE
|
#
|
||||||
PACKAGE_NAME
|
# Fetches a package from a Git repository in order to satisfy dependencies.
|
||||||
LIBRARY_NAME
|
#
|
||||||
GIT_REPO
|
# FetchPackage([PACKAGE_NAME [name]]
|
||||||
GIT_TAG
|
# [GIT_REPO [repo]]
|
||||||
)
|
# [GIT_TAG [tag]]
|
||||||
set(multi_value_args PATCH_COMMAND TARGETS)
|
# [PATCH_COMMAND [cmd] [args]]
|
||||||
cmake_parse_arguments(
|
# )
|
||||||
_ARGS
|
#
|
||||||
"${options}"
|
# The command has the following parameters:
|
||||||
"${one_value_args}"
|
#
|
||||||
"${multi_value_args}"
|
# Arguments:
|
||||||
${ARGN}
|
# - ``PACKAGE_NAME`` name of the package.
|
||||||
)
|
# - ``GIT_REPO`` git repository to fetch the library from.
|
||||||
|
# - ``GIT_TAG`` tag reference when fetching the library from the git repo.
|
||||||
# Check if all targets are found.
|
# - ``PATCH_COMMAND`` Specifies a custom command to patch the sources after an
|
||||||
if(NOT _ARGS_TARGETS)
|
# update. See https://cmake.org/cmake/help/latest/module/ExternalProject.html#command:externalproject_add
|
||||||
message(FATAL_ERROR "mujoco::FindOrFetch: TARGETS must be specified.")
|
# for details on the parameter.
|
||||||
endif()
|
# - ``TARGETS`` (optional) list of targets to be satisfied. If any of these
|
||||||
|
# targets are not currently defined, this macro will attempt to fetch the
|
||||||
set(targets_found TRUE)
|
# package. If not specified, the package name will be used as the target.
|
||||||
message(CHECK_START
|
#
|
||||||
"mujoco::FindOrFetch: checking for targets in package `${_ARGS_PACKAGE_NAME}`"
|
# Note: This is a wrapper around FindOrFetch that sets EXCLUDE_FROM_ALL and
|
||||||
)
|
# USE_SYSTEM_PACKAGE to OFF.
|
||||||
foreach(target ${_ARGS_TARGETS})
|
if(NOT COMMAND FetchPackage)
|
||||||
if(NOT TARGET ${target})
|
function(FetchPackage)
|
||||||
message(CHECK_FAIL "target `${target}` not defined.")
|
cmake_parse_arguments(
|
||||||
set(targets_found FALSE)
|
_ARGS
|
||||||
break()
|
"EXCLUDE_FROM_ALL"
|
||||||
|
"PACKAGE_NAME;GIT_REPO;GIT_TAG"
|
||||||
|
"PATCH_COMMAND;TARGETS"
|
||||||
|
${ARGN}
|
||||||
|
)
|
||||||
|
if(NOT _ARGS_TARGETS)
|
||||||
|
set(_ARGS_TARGETS ${_ARGS_PACKAGE_NAME})
|
||||||
endif()
|
endif()
|
||||||
endforeach()
|
|
||||||
|
|
||||||
# If targets are not found, use `find_package` or `FetchContent...` to get it.
|
FindOrFetch(
|
||||||
if(NOT targets_found)
|
PACKAGE_NAME ${_ARGS_PACKAGE_NAME}
|
||||||
if(${_ARGS_USE_SYSTEM_PACKAGE})
|
LIBRARY_NAME ${_ARGS_PACKAGE_NAME}
|
||||||
message(CHECK_START
|
GIT_REPO ${_ARGS_GIT_REPO}
|
||||||
"mujoco::FindOrFetch: finding `${_ARGS_PACKAGE_NAME}` in system packages..."
|
GIT_TAG ${_ARGS_GIT_TAG}
|
||||||
)
|
PATCH_COMMAND ${_ARGS_PATCH_COMMAND}
|
||||||
find_package(${_ARGS_PACKAGE_NAME} REQUIRED)
|
TARGETS ${_ARGS_TARGETS}
|
||||||
message(CHECK_PASS "found")
|
USE_SYSTEM_PACKAGE OFF
|
||||||
else()
|
EXCLUDE_FROM_ALL
|
||||||
message(CHECK_START
|
)
|
||||||
"mujoco::FindOrFetch: Using FetchContent to retrieve `${_ARGS_LIBRARY_NAME}`"
|
endfunction()
|
||||||
)
|
endif()
|
||||||
FetchContent_Declare(
|
|
||||||
${_ARGS_LIBRARY_NAME}
|
|
||||||
GIT_REPOSITORY ${_ARGS_GIT_REPO}
|
|
||||||
GIT_TAG ${_ARGS_GIT_TAG}
|
|
||||||
GIT_SHALLOW FALSE
|
|
||||||
PATCH_COMMAND ${_ARGS_PATCH_COMMAND}
|
|
||||||
UPDATE_DISCONNECTED TRUE
|
|
||||||
)
|
|
||||||
if(${_ARGS_EXCLUDE_FROM_ALL})
|
|
||||||
FetchContent_GetProperties(${_ARGS_LIBRARY_NAME})
|
|
||||||
if(NOT ${${_ARGS_LIBRARY_NAME}_POPULATED})
|
|
||||||
FetchContent_Populate(${_ARGS_LIBRARY_NAME})
|
|
||||||
add_subdirectory(
|
|
||||||
${${_ARGS_LIBRARY_NAME}_SOURCE_DIR} ${${_ARGS_LIBRARY_NAME}_BINARY_DIR}
|
|
||||||
EXCLUDE_FROM_ALL
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
else()
|
|
||||||
FetchContent_MakeAvailable(${_ARGS_LIBRARY_NAME})
|
|
||||||
endif()
|
|
||||||
message(CHECK_PASS "Done")
|
|
||||||
endif()
|
|
||||||
else()
|
|
||||||
message(CHECK_PASS "found")
|
|
||||||
endif()
|
|
||||||
endmacro()
|
|
||||||
|
|||||||
Reference in New Issue
Block a user