From c6b587b515e30bc3f475628e6ec4c89aa8f1e501 Mon Sep 17 00:00:00 2001 From: Haroon Qureshi Date: Mon, 1 Dec 2025 03:36:36 -0800 Subject: [PATCH] Use cmake FILE(COPY) for deploying custom CMakeLists.txt. PiperOrigin-RevId: 838696575 Change-Id: I3c61bda9d1d89185f257797c2e0c0f4ef2c7cb95 --- cmake/FindOrFetch.cmake | 16 +++++++++++++++- cmake/third_party_deps/dear_imgui.cmake | 5 +---- cmake/third_party_deps/font_awesome.cmake | 5 +---- cmake/third_party_deps/implot.cmake | 5 +---- cmake/third_party_deps/opensans.cmake | 5 +---- sample/cmake/FindOrFetch.cmake | 16 +++++++++++++++- simulate/cmake/FindOrFetch.cmake | 16 +++++++++++++++- 7 files changed, 49 insertions(+), 19 deletions(-) diff --git a/cmake/FindOrFetch.cmake b/cmake/FindOrFetch.cmake index 3add8558..7fb3e873 100644 --- a/cmake/FindOrFetch.cmake +++ b/cmake/FindOrFetch.cmake @@ -23,6 +23,7 @@ # [LIBRARY_NAME [name]] # [GIT_REPO [repo]] # [GIT_TAG [tag]] +# [CUSTOM_CMAKE [path]] # [PATCH_COMMAND [cmd] [args]] # [TARGETS [targets]] # [EXCLUDE_FROM_ALL]) @@ -42,6 +43,9 @@ # ``USE_SYSTEM_PACKAGE`` is ``ON``. # - ``GIT_TAG`` tag reference when fetching the library from the git # repository. Ignored if ``USE_SYSTEM_PACKAGE`` is ``ON``. +# - ``CUSTOM_CMAKE`` path to a custom CMakeLists.txt file to be used when +# fetching the library from the git repository. Ignored if +# ``USE_SYSTEM_PACKAGE`` is ``ON``. # - ``PATCH_COMMAND`` Specifies a custom command to patch the sources after an # update. See https://cmake.org/cmake/help/latest/module/ExternalProject.html#command:externalproject_add # for details on the parameter. @@ -70,6 +74,7 @@ if(NOT COMMAND FindOrFetch) LIBRARY_NAME GIT_REPO GIT_TAG + CUSTOM_CMAKE ) set(multi_value_args PATCH_COMMAND TARGETS) cmake_parse_arguments( @@ -121,6 +126,12 @@ if(NOT COMMAND FindOrFetch) FetchContent_GetProperties(${_ARGS_LIBRARY_NAME}) if(NOT ${${_ARGS_LIBRARY_NAME}_POPULATED}) FetchContent_Populate(${_ARGS_LIBRARY_NAME}) + if(NOT "${_ARGS_CUSTOM_CMAKE}" STREQUAL "") + file(COPY + "${_ARGS_CUSTOM_CMAKE}" + DESTINATION "${${_ARGS_LIBRARY_NAME}_SOURCE_DIR}" + ) + endif() add_subdirectory( ${${_ARGS_LIBRARY_NAME}_SOURCE_DIR} ${${_ARGS_LIBRARY_NAME}_BINARY_DIR} EXCLUDE_FROM_ALL @@ -156,6 +167,8 @@ endif() # - ``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. +# - ``CUSTOM_CMAKE`` path to a custom CMakeLists.txt file to be used when +# fetching the library from the git repository. # - ``PATCH_COMMAND`` Specifies a custom command to patch the sources after an # update. See https://cmake.org/cmake/help/latest/module/ExternalProject.html#command:externalproject_add # for details on the parameter. @@ -170,7 +183,7 @@ if(NOT COMMAND FetchPackage) cmake_parse_arguments( _ARGS "EXCLUDE_FROM_ALL" - "PACKAGE_NAME;GIT_REPO;GIT_TAG" + "PACKAGE_NAME;GIT_REPO;GIT_TAG;CUSTOM_CMAKE" "PATCH_COMMAND;TARGETS" ${ARGN} ) @@ -183,6 +196,7 @@ if(NOT COMMAND FetchPackage) LIBRARY_NAME ${_ARGS_PACKAGE_NAME} GIT_REPO ${_ARGS_GIT_REPO} GIT_TAG ${_ARGS_GIT_TAG} + CUSTOM_CMAKE ${_ARGS_CUSTOM_CMAKE} PATCH_COMMAND ${_ARGS_PATCH_COMMAND} TARGETS ${_ARGS_TARGETS} USE_SYSTEM_PACKAGE OFF diff --git a/cmake/third_party_deps/dear_imgui.cmake b/cmake/third_party_deps/dear_imgui.cmake index 55582fae..c4e8bfcb 100644 --- a/cmake/third_party_deps/dear_imgui.cmake +++ b/cmake/third_party_deps/dear_imgui.cmake @@ -24,8 +24,5 @@ fetchpackage( PACKAGE_NAME dear_imgui GIT_REPO https://github.com/ocornut/imgui.git GIT_TAG ${MUJOCO_DEP_VERSION_dear_imgui} - PATCH_COMMAND - "cp" - "${CMAKE_SOURCE_DIR}/cmake/third_party_deps/dear_imgui/CMakeLists.txt" - "${FETCHCONTENT_BASE_DIR}/dear_imgui-src/CMakeLists.txt" + CUSTOM_CMAKE "${CMAKE_SOURCE_DIR}/cmake/third_party_deps/dear_imgui/CMakeLists.txt" ) diff --git a/cmake/third_party_deps/font_awesome.cmake b/cmake/third_party_deps/font_awesome.cmake index 9e705984..9a02aa3d 100644 --- a/cmake/third_party_deps/font_awesome.cmake +++ b/cmake/third_party_deps/font_awesome.cmake @@ -24,8 +24,5 @@ fetchpackage( PACKAGE_NAME font_awesome GIT_REPO https://github.com/FortAwesome/Font-Awesome.git GIT_TAG ${MUJOCO_DEP_VERSION_font_awesome} - PATCH_COMMAND - "cp" - "${CMAKE_SOURCE_DIR}/cmake/third_party_deps/font_awesome/CMakeLists.txt" - "${FETCHCONTENT_BASE_DIR}/font_awesome-src/CMakeLists.txt" + CUSTOM_CMAKE "${CMAKE_SOURCE_DIR}/cmake/third_party_deps/font_awesome/CMakeLists.txt" ) diff --git a/cmake/third_party_deps/implot.cmake b/cmake/third_party_deps/implot.cmake index 37d1d79b..6bd75fef 100644 --- a/cmake/third_party_deps/implot.cmake +++ b/cmake/third_party_deps/implot.cmake @@ -24,8 +24,5 @@ fetchpackage( PACKAGE_NAME implot GIT_REPO https://github.com/epezent/implot.git GIT_TAG ${MUJOCO_DEP_VERSION_implot} - PATCH_COMMAND - "cp" - "${CMAKE_SOURCE_DIR}/cmake/third_party_deps/implot/CMakeLists.txt" - "${FETCHCONTENT_BASE_DIR}/implot-src/CMakeLists.txt" + CUSTOM_CMAKE "${CMAKE_SOURCE_DIR}/cmake/third_party_deps/implot/CMakeLists.txt" ) diff --git a/cmake/third_party_deps/opensans.cmake b/cmake/third_party_deps/opensans.cmake index 08f9b8ce..1209edbe 100644 --- a/cmake/third_party_deps/opensans.cmake +++ b/cmake/third_party_deps/opensans.cmake @@ -24,8 +24,5 @@ fetchpackage( PACKAGE_NAME opensans GIT_REPO https://github.com/googlefonts/opensans.git GIT_TAG ${MUJOCO_DEP_VERSION_opensans} - PATCH_COMMAND - "cp" - "${CMAKE_SOURCE_DIR}/cmake/third_party_deps/opensans/CMakeLists.txt" - "${FETCHCONTENT_BASE_DIR}/opensans-src/CMakeLists.txt" + CUSTOM_CMAKE "${CMAKE_SOURCE_DIR}/cmake/third_party_deps/opensans/CMakeLists.txt" ) diff --git a/sample/cmake/FindOrFetch.cmake b/sample/cmake/FindOrFetch.cmake index 3add8558..7fb3e873 100644 --- a/sample/cmake/FindOrFetch.cmake +++ b/sample/cmake/FindOrFetch.cmake @@ -23,6 +23,7 @@ # [LIBRARY_NAME [name]] # [GIT_REPO [repo]] # [GIT_TAG [tag]] +# [CUSTOM_CMAKE [path]] # [PATCH_COMMAND [cmd] [args]] # [TARGETS [targets]] # [EXCLUDE_FROM_ALL]) @@ -42,6 +43,9 @@ # ``USE_SYSTEM_PACKAGE`` is ``ON``. # - ``GIT_TAG`` tag reference when fetching the library from the git # repository. Ignored if ``USE_SYSTEM_PACKAGE`` is ``ON``. +# - ``CUSTOM_CMAKE`` path to a custom CMakeLists.txt file to be used when +# fetching the library from the git repository. Ignored if +# ``USE_SYSTEM_PACKAGE`` is ``ON``. # - ``PATCH_COMMAND`` Specifies a custom command to patch the sources after an # update. See https://cmake.org/cmake/help/latest/module/ExternalProject.html#command:externalproject_add # for details on the parameter. @@ -70,6 +74,7 @@ if(NOT COMMAND FindOrFetch) LIBRARY_NAME GIT_REPO GIT_TAG + CUSTOM_CMAKE ) set(multi_value_args PATCH_COMMAND TARGETS) cmake_parse_arguments( @@ -121,6 +126,12 @@ if(NOT COMMAND FindOrFetch) FetchContent_GetProperties(${_ARGS_LIBRARY_NAME}) if(NOT ${${_ARGS_LIBRARY_NAME}_POPULATED}) FetchContent_Populate(${_ARGS_LIBRARY_NAME}) + if(NOT "${_ARGS_CUSTOM_CMAKE}" STREQUAL "") + file(COPY + "${_ARGS_CUSTOM_CMAKE}" + DESTINATION "${${_ARGS_LIBRARY_NAME}_SOURCE_DIR}" + ) + endif() add_subdirectory( ${${_ARGS_LIBRARY_NAME}_SOURCE_DIR} ${${_ARGS_LIBRARY_NAME}_BINARY_DIR} EXCLUDE_FROM_ALL @@ -156,6 +167,8 @@ endif() # - ``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. +# - ``CUSTOM_CMAKE`` path to a custom CMakeLists.txt file to be used when +# fetching the library from the git repository. # - ``PATCH_COMMAND`` Specifies a custom command to patch the sources after an # update. See https://cmake.org/cmake/help/latest/module/ExternalProject.html#command:externalproject_add # for details on the parameter. @@ -170,7 +183,7 @@ if(NOT COMMAND FetchPackage) cmake_parse_arguments( _ARGS "EXCLUDE_FROM_ALL" - "PACKAGE_NAME;GIT_REPO;GIT_TAG" + "PACKAGE_NAME;GIT_REPO;GIT_TAG;CUSTOM_CMAKE" "PATCH_COMMAND;TARGETS" ${ARGN} ) @@ -183,6 +196,7 @@ if(NOT COMMAND FetchPackage) LIBRARY_NAME ${_ARGS_PACKAGE_NAME} GIT_REPO ${_ARGS_GIT_REPO} GIT_TAG ${_ARGS_GIT_TAG} + CUSTOM_CMAKE ${_ARGS_CUSTOM_CMAKE} PATCH_COMMAND ${_ARGS_PATCH_COMMAND} TARGETS ${_ARGS_TARGETS} USE_SYSTEM_PACKAGE OFF diff --git a/simulate/cmake/FindOrFetch.cmake b/simulate/cmake/FindOrFetch.cmake index 3add8558..7fb3e873 100644 --- a/simulate/cmake/FindOrFetch.cmake +++ b/simulate/cmake/FindOrFetch.cmake @@ -23,6 +23,7 @@ # [LIBRARY_NAME [name]] # [GIT_REPO [repo]] # [GIT_TAG [tag]] +# [CUSTOM_CMAKE [path]] # [PATCH_COMMAND [cmd] [args]] # [TARGETS [targets]] # [EXCLUDE_FROM_ALL]) @@ -42,6 +43,9 @@ # ``USE_SYSTEM_PACKAGE`` is ``ON``. # - ``GIT_TAG`` tag reference when fetching the library from the git # repository. Ignored if ``USE_SYSTEM_PACKAGE`` is ``ON``. +# - ``CUSTOM_CMAKE`` path to a custom CMakeLists.txt file to be used when +# fetching the library from the git repository. Ignored if +# ``USE_SYSTEM_PACKAGE`` is ``ON``. # - ``PATCH_COMMAND`` Specifies a custom command to patch the sources after an # update. See https://cmake.org/cmake/help/latest/module/ExternalProject.html#command:externalproject_add # for details on the parameter. @@ -70,6 +74,7 @@ if(NOT COMMAND FindOrFetch) LIBRARY_NAME GIT_REPO GIT_TAG + CUSTOM_CMAKE ) set(multi_value_args PATCH_COMMAND TARGETS) cmake_parse_arguments( @@ -121,6 +126,12 @@ if(NOT COMMAND FindOrFetch) FetchContent_GetProperties(${_ARGS_LIBRARY_NAME}) if(NOT ${${_ARGS_LIBRARY_NAME}_POPULATED}) FetchContent_Populate(${_ARGS_LIBRARY_NAME}) + if(NOT "${_ARGS_CUSTOM_CMAKE}" STREQUAL "") + file(COPY + "${_ARGS_CUSTOM_CMAKE}" + DESTINATION "${${_ARGS_LIBRARY_NAME}_SOURCE_DIR}" + ) + endif() add_subdirectory( ${${_ARGS_LIBRARY_NAME}_SOURCE_DIR} ${${_ARGS_LIBRARY_NAME}_BINARY_DIR} EXCLUDE_FROM_ALL @@ -156,6 +167,8 @@ endif() # - ``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. +# - ``CUSTOM_CMAKE`` path to a custom CMakeLists.txt file to be used when +# fetching the library from the git repository. # - ``PATCH_COMMAND`` Specifies a custom command to patch the sources after an # update. See https://cmake.org/cmake/help/latest/module/ExternalProject.html#command:externalproject_add # for details on the parameter. @@ -170,7 +183,7 @@ if(NOT COMMAND FetchPackage) cmake_parse_arguments( _ARGS "EXCLUDE_FROM_ALL" - "PACKAGE_NAME;GIT_REPO;GIT_TAG" + "PACKAGE_NAME;GIT_REPO;GIT_TAG;CUSTOM_CMAKE" "PATCH_COMMAND;TARGETS" ${ARGN} ) @@ -183,6 +196,7 @@ if(NOT COMMAND FetchPackage) LIBRARY_NAME ${_ARGS_PACKAGE_NAME} GIT_REPO ${_ARGS_GIT_REPO} GIT_TAG ${_ARGS_GIT_TAG} + CUSTOM_CMAKE ${_ARGS_CUSTOM_CMAKE} PATCH_COMMAND ${_ARGS_PATCH_COMMAND} TARGETS ${_ARGS_TARGETS} USE_SYSTEM_PACKAGE OFF