Browse Source

add dartpy support (#5712)

Inari0 9 months ago
parent
commit
3bdee46dea

+ 68 - 0
packages/d/dartsim/patches/6.14.5/dartpy.patch

@@ -0,0 +1,68 @@
+diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt
+index 37cadf4..bd29874 100644
+--- a/python/CMakeLists.txt
++++ b/python/CMakeLists.txt
+@@ -6,13 +6,7 @@ if(NOT DART_BUILD_DARTPY)
+ endif()
+ 
+ # Set up pybind11
+-include(FetchContent)
+-FetchContent_Declare(
+-  pybind11
+-  GIT_REPOSITORY https://github.com/pybind/pybind11
+-  GIT_TAG v2.12.0
+-)
+-FetchContent_MakeAvailable(pybind11)
++find_package(pybind11 CONFIG)
+ 
+ if(NOT pybind11_FOUND)
+   message(WARNING "Disabling [dartpy] due to missing pybind11 >= 2.2.0.")
+@@ -22,9 +16,6 @@ endif()
+ set(DART_DARTPY_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/dartpy")
+ 
+ add_subdirectory(dartpy)
+-add_subdirectory(tests)
+-add_subdirectory(examples)
+-add_subdirectory(tutorials)
+ 
+ message(STATUS "")
+ message(STATUS "[ dartpy ]")
+diff --git a/python/dartpy/CMakeLists.txt b/python/dartpy/CMakeLists.txt
+index b316e86..d33c16f 100644
+--- a/python/dartpy/CMakeLists.txt
++++ b/python/dartpy/CMakeLists.txt
+@@ -6,12 +6,7 @@
+ #
+ # This file is provided under the "BSD-style" License
+ 
+-execute_process(COMMAND ${Python3_EXECUTABLE} -c
+-  "from distutils.sysconfig import get_python_lib;\
+-  print(get_python_lib(plat_specific=True))"
+-  OUTPUT_VARIABLE PYTHON_SITE_PACKAGES
+-  OUTPUT_STRIP_TRAILING_WHITESPACE
+-)
++set(PYTHON_SITE_PACKAGES "lib/site-packages")
+ if(NOT IS_ABSOLUTE ${PYTHON_SITE_PACKAGES})
+   set(PYTHON_SITE_PACKAGES "${CMAKE_INSTALL_PREFIX}/${PYTHON_SITE_PACKAGES}")
+ endif()
+@@ -29,7 +24,6 @@ set(pybind_module dartpy)
+ #
+ pybind11_add_module(${pybind_module}
+   MODULE
+-  EXCLUDE_FROM_ALL
+   ${dartpy_headers}
+   ${dartpy_sources}
+ )
+@@ -91,9 +85,9 @@ endif()
+ 
+ # TODO: Fix installing dartpy to site-packages directory
+ # Install the pybind module to site-packages directory
+-# install(TARGETS ${pybind_module}
+-#   LIBRARY DESTINATION "${PYTHON_SITE_PACKAGES}"
+-# )
++install(TARGETS ${pybind_module}
++  LIBRARY DESTINATION "${PYTHON_SITE_PACKAGES}"
++)
+ 
+ list(REMOVE_ITEM dartpy_headers
+   ${CMAKE_CURRENT_LIST_DIR}/eigen_geometry_pybind.h

+ 71 - 9
packages/d/dartsim/xmake.lua

@@ -12,9 +12,11 @@ package("dartsim")
     add_versions("v6.13.0", "4da3ff8cee056252a558b05625a5ff29b21e71f2995e6d7f789abbf6261895f7")
     add_versions("v6.13.0", "4da3ff8cee056252a558b05625a5ff29b21e71f2995e6d7f789abbf6261895f7")
     add_versions("v6.14.2", "6bbaf452f8182b97bf22adeab6cc7f3dc1cd2733358543131fa130e07c0860fc")
     add_versions("v6.14.2", "6bbaf452f8182b97bf22adeab6cc7f3dc1cd2733358543131fa130e07c0860fc")
 
 
+    add_patches("6.x", "patches/6.14.5/dartpy.patch", "c8f989317ac8e20259a91e76d28b986b3d4bda01a8e4d0fc13704f6e4f0e144b")
+
     add_configs("dartpy", {description = "Build dartpy interface.", default = false, type = "boolean"})
     add_configs("dartpy", {description = "Build dartpy interface.", default = false, type = "boolean"})
+    add_configs("gui",   {description = "Build GLUT GUI.", default = false, type = "boolean"})
     local configdeps = {bullet3 = "Bullet",
     local configdeps = {bullet3 = "Bullet",
-                        freeglut = "GLUT",
                         nlopt = "NLOPT",
                         nlopt = "NLOPT",
                         ode = "ODE",
                         ode = "ODE",
                         openscenegraph = "OpenSceneGraph",
                         openscenegraph = "OpenSceneGraph",
@@ -32,6 +34,8 @@ package("dartsim")
         set_policy("package.cmake_generator.ninja", false)
         set_policy("package.cmake_generator.ninja", false)
     end
     end
 
 
+    set_policy("platform.longpaths", true)
+
     add_deps("cmake")
     add_deps("cmake")
     add_deps("assimp", "libccd", "eigen", "fcl", "octomap", "fmt")
     add_deps("assimp", "libccd", "eigen", "fcl", "octomap", "fmt")
     on_load("windows|x64", "linux", "macosx", function (package)
     on_load("windows|x64", "linux", "macosx", function (package)
@@ -40,24 +44,42 @@ package("dartsim")
                 package:add("deps", config)
                 package:add("deps", config)
             end
             end
         end
         end
+        if package:config("gui") or package:config("dartpy") then
+            package:add("deps", "glut")
+        end
         if package:config("dartpy") then
         if package:config("dartpy") then
+            package:add("deps", "tinyxml2")
+            package:add("deps", "urdfdom")
+            package:add("deps", "openscenegraph")
+            package:add("deps", "imgui", {configs = {opengl2 = true}})
             package:add("deps", "python 3.x")
             package:add("deps", "python 3.x")
+            package:add("deps", "pybind11")
         end
         end
         if package:config("openscenegraph") then
         if package:config("openscenegraph") then
-            package:add("deps", "imgui")
+            package:add("deps", "imgui", {configs = {opengl2 = true}})
         end
         end
     end)
     end)
 
 
     on_install("windows|x64", "linux", "macosx", function (package)
     on_install("windows|x64", "linux", "macosx", function (package)
+        import("detect.tools.find_python3")
+
+        -- remove after xmake 2.9.7
+        io.insert("CMakeLists.txt", 1, "set(CMAKE_MODULE_LINKER_FLAGS \"${CMAKE_SHARED_LINKER_FLAGS}\")\n")
         io.replace("CMakeLists.txt", "/GL", "", {plain = true})
         io.replace("CMakeLists.txt", "/GL", "", {plain = true})
         io.replace("CMakeLists.txt", "if(TARGET dart)", "if(FALSE)", {plain = true})
         io.replace("CMakeLists.txt", "if(TARGET dart)", "if(FALSE)", {plain = true})
+        io.replace("CMakeLists.txt", "-D_CRT_SECURE_NO_WARNINGS", "-DWIN32 -D_CRT_SECURE_NO_WARNINGS", {plain = true})
+        io.replace("CMakeLists.txt", "CMAKE_SHARED_LINKER_FLAGS \"-Wl,--no-undefined\"", "CMAKE_SHARED_LINKER_FLAGS \"${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined\"", {plain = true})
         io.replace("dart/CMakeLists.txt", "/LTCG", "", {plain = true})
         io.replace("dart/CMakeLists.txt", "/LTCG", "", {plain = true})
-        io.replace("python/CMakeLists.txt", "add_subdirectory(tests)", "", {plain = true})
-        io.replace("python/CMakeLists.txt", "add_subdirectory(examples)", "", {plain = true})
-        io.replace("python/CMakeLists.txt", "add_subdirectory(tutorials)", "", {plain = true})
         io.replace("cmake/DARTFindDependencies.cmake", "dart_check_required_package(assimp \"assimp\")", "dart_check_required_package(assimp \"assimp\")\nfind_package(ZLIB)\ntarget_link_libraries(assimp INTERFACE ZLIB::ZLIB)", {plain = true})
         io.replace("cmake/DARTFindDependencies.cmake", "dart_check_required_package(assimp \"assimp\")", "dart_check_required_package(assimp \"assimp\")\nfind_package(ZLIB)\ntarget_link_libraries(assimp INTERFACE ZLIB::ZLIB)", {plain = true})
         io.replace("cmake/DARTFindDependencies.cmake", "dart_check_required_package(fcl \"fcl\")", "dart_check_required_package(fcl \"fcl\")\ntarget_link_libraries(fcl INTERFACE ccd)", {plain = true})
         io.replace("cmake/DARTFindDependencies.cmake", "dart_check_required_package(fcl \"fcl\")", "dart_check_required_package(fcl \"fcl\")\ntarget_link_libraries(fcl INTERFACE ccd)", {plain = true})
         io.replace("cmake/DARTFindDependencies.cmake", "check_cxx_source_compiles%(.-\".-\".-(ASSIMP.-DEFINED)%)", "set(%1 1)")
         io.replace("cmake/DARTFindDependencies.cmake", "check_cxx_source_compiles%(.-\".-\".-(ASSIMP.-DEFINED)%)", "set(%1 1)")
+        io.replace("cmake/DARTFindOpenSceneGraph.cmake", "osg osgViewer osgManipulator osgGA osgDB osgShadow osgUtil", "osgManipulator osgShadow osgViewer osgGA osgDB osgUtil osg", {plain = true})
+        io.replace("cmake/DARTFindOpenSceneGraph.cmake", "target_link_libraries(osg::osg", "target_compile_definitions(osg::osg INTERFACE OSG_LIBRARY_STATIC)\ntarget_link_libraries(osg::osg", {plain = true})
+        local glut_extra = "find_package(GLUT QUIET MODULE)\ntarget_compile_definitions(GLUT::GLUT INTERFACE FREEGLUT_STATIC)"
+        if package:is_plat("linux") then
+            glut_extra = glut_extra .. "\ntarget_link_libraries(GLUT::GLUT INTERFACE Xrandr Xrender Xxf86vm X11)"
+        end
+        io.replace("cmake/DARTFindGLUT.cmake", "find_package(GLUT QUIET MODULE)", glut_extra, {plain = true})
         local configs = {
         local configs = {
             "-DDART_USE_SYSTEM_IMGUI=ON",
             "-DDART_USE_SYSTEM_IMGUI=ON",
             "-DDART_SKIP_lz4=ON",
             "-DDART_SKIP_lz4=ON",
@@ -66,22 +88,58 @@ package("dartsim")
             "-DDART_SKIP_pagmo=ON",
             "-DDART_SKIP_pagmo=ON",
             "-DDART_SKIP_DOXYGEN=ON",
             "-DDART_SKIP_DOXYGEN=ON",
             "-DDART_TREAT_WARNINGS_AS_ERRORS=OFF",
             "-DDART_TREAT_WARNINGS_AS_ERRORS=OFF",
+            "-DDART_VERBOSE=ON"
         }
         }
         table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
         table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
         table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
         table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
         for config, dep in pairs(configdeps) do
         for config, dep in pairs(configdeps) do
-            table.insert(configs, "-DDART_SKIP_" .. dep .. "=" .. (package:config(config) and "OFF" or "ON"))
+            table.insert(configs, "-DDART_SKIP_" .. dep .. "=" .. (package:dep(config) and "OFF" or "ON"))
         end
         end
         if package:is_plat("windows") then
         if package:is_plat("windows") then
-            table.insert(configs, "-DDART_RUNTIME_LIBRARY=" .. (package:config("vs_runtime"):startswith("MT") and "/MT" or "/MD"))
+            table.insert(configs, "-DDART_RUNTIME_LIBRARY=" .. (package:has_runtime("MT", "MTd") and "/MT" or "/MD"))
         end
         end
         table.insert(configs, "-DDART_BUILD_DARTPY=" .. (package:config("dartpy") and "ON" or "OFF"))
         table.insert(configs, "-DDART_BUILD_DARTPY=" .. (package:config("dartpy") and "ON" or "OFF"))
-        table.insert(configs, "-DDART_BUILD_GUI_OSG=" .. (package:config("openscenegraph") and "ON" or "OFF"))
-        import("package.tools.cmake").install(package, configs)
+        table.insert(configs, "-DDART_SKIP_GLUT=" .. ((package:config("gui") or package:config("dartpy")) and "OFF" or "ON"))
+        table.insert(configs, "-DDART_BUILD_GUI_OSG=" .. (package:dep("openscenegraph") and "ON" or "OFF"))
+        if package:config("dartpy") then
+            local python = find_python3()
+            local pythondir = path.directory(python)
+            if pythondir and path.is_absolute(pythondir) then
+                table.insert(configs, "-DPython_ROOT_DIR=" .. pythondir)
+                table.insert(configs, "-DPython3_ROOT_DIR=" .. pythondir)
+            end
+        end
+        local deps = {"imgui"}
+        if package:is_plat("linux") then
+            table.insert(deps, "freeglut")
+        end
+        import("package.tools.cmake").install(package, configs, {packagedeps = deps})
         local suffix = package:is_debug() and "d" or ""
         local suffix = package:is_debug() and "d" or ""
         for _, lib in ipairs({"dart-collision-bullet", "dart-collision-ode", "dart-gui-osg", "dart-gui", "dart-optimizer-ipopt", "dart-optimizer-nlopt", "dart-optimizer-pagmo", "dart-utils-urdf", "dart-utils", "dart", "dart-external-odelcpsolver", "dart-external-lodepng"}) do
         for _, lib in ipairs({"dart-collision-bullet", "dart-collision-ode", "dart-gui-osg", "dart-gui", "dart-optimizer-ipopt", "dart-optimizer-nlopt", "dart-optimizer-pagmo", "dart-utils-urdf", "dart-utils", "dart", "dart-external-odelcpsolver", "dart-external-lodepng"}) do
             package:add("links", lib .. suffix)
             package:add("links", lib .. suffix)
         end
         end
+        if package:config("dartpy") then
+            os.vrunv("python", {"-m", "pip", "install", "numpy"})
+            local pythonpath = path.join(package:installdir("lib"), "site-packages")
+            package:addenv("PYTHONPATH", pythonpath)
+            if package:is_plat("windows") then
+                -- after python3.8 dll can not be loaded from PATH
+                for _, lib in ipairs(package:librarydeps()) do
+                    if lib:name() ~= "python" then
+                        local fetchinfo = lib:fetch()
+                        local libfiles = fetchinfo and fetchinfo.libfiles or {}
+                        for _, file in ipairs(libfiles) do
+                            if file:endswith(".dll") then
+                                os.trycp(file, pythonpath)
+                            end
+                        end
+                    end
+                end
+                if package:config("shared") then
+                    os.trycp(path.join(package:installdir("bin"), "*.dll"), pythonpath)
+                end
+            end
+        end
     end)
     end)
 
 
     on_test(function (package)
     on_test(function (package)
@@ -91,4 +149,8 @@ package("dartsim")
                 dart::simulation::WorldPtr world = dart::simulation::World::create();
                 dart::simulation::WorldPtr world = dart::simulation::World::create();
             }
             }
         ]]}, {configs = {languages = "c++17"}}))
         ]]}, {configs = {languages = "c++17"}}))
+        if package:config("dartpy") then
+            local python = package:is_plat("windows") and "python" or "python3"
+            os.vrunv(python, {"-c", "import dartpy"})
+        end
     end)
     end)

+ 6 - 2
packages/f/freeglut/xmake.lua

@@ -31,7 +31,7 @@ package("freeglut")
 
 
     on_load("windows", "mingw", function (package)
     on_load("windows", "mingw", function (package)
         if not package:config("shared") then
         if not package:config("shared") then
-            package:add("defines", "FREEGLUT_STATIC=1")
+            package:add("defines", "FREEGLUT_STATIC")
         end
         end
         package:add("defines", "FREEGLUT_LIB_PRAGMAS=0")
         package:add("defines", "FREEGLUT_LIB_PRAGMAS=0")
         package:add("syslinks", "gdi32", "winmm", "user32", "advapi32")
         package:add("syslinks", "gdi32", "winmm", "user32", "advapi32")
@@ -61,7 +61,7 @@ package("freeglut")
                 table.insert(opt.cxflags, "-DFREEGLUT_LIB_PRAGMAS=0")
                 table.insert(opt.cxflags, "-DFREEGLUT_LIB_PRAGMAS=0")
             else
             else
                 table.insert(opt.cxflags, "-DFREEGLUT_LIB_PRAGMAS=0")
                 table.insert(opt.cxflags, "-DFREEGLUT_LIB_PRAGMAS=0")
-                table.insert(opt.cxflags, "-DFREEGLUT_STATIC=1")
+                table.insert(opt.cxflags, "-DFREEGLUT_STATIC")
             end
             end
             if package:is_arch("arm64") then
             if package:is_arch("arm64") then
                 local vs = package:toolchain("msvc"):config("vs")
                 local vs = package:toolchain("msvc"):config("vs")
@@ -78,6 +78,10 @@ package("freeglut")
 
 
         import("package.tools.cmake").install(package, configs, opt)
         import("package.tools.cmake").install(package, configs, opt)
         os.trycp(path.join("include", "GL", "glut.h"), package:installdir("include", "GL"))
         os.trycp(path.join("include", "GL", "glut.h"), package:installdir("include", "GL"))
+        if package:is_plat("windows") and not package:config("shared") then
+            os.trycp(path.join(package:installdir("lib"), "freeglut_static.lib"), path.join(package:installdir("lib"), "freeglut.lib"))
+            package:add("links", "freeglut")
+        end
     end)
     end)
 
 
     on_test(function (package)
     on_test(function (package)

+ 5 - 6
packages/g/glut/xmake.lua

@@ -1,5 +1,5 @@
 package("glut")
 package("glut")
-
+    set_kind("library", {headeronly = true})
     set_homepage("https://www.opengl.org/resources/libraries/glut/")
     set_homepage("https://www.opengl.org/resources/libraries/glut/")
     set_description("OpenGL utility toolkit")
     set_description("OpenGL utility toolkit")
 
 
@@ -12,10 +12,9 @@ package("glut")
             if package:is_plat("macosx") then
             if package:is_plat("macosx") then
                 return {frameworks = {"GLUT", "OpenGL"}, defines = "GL_SILENCE_DEPRECATION"}
                 return {frameworks = {"GLUT", "OpenGL"}, defines = "GL_SILENCE_DEPRECATION"}
             end
             end
-        else
-            local freeglut = package:dep("freeglut")
-            if freeglut then
-                return freeglut:fetch(opt)
-            end
         end
         end
     end)
     end)
+
+    on_install("windows", "mingw", "macosx", "linux", function (package)
+        -- do nothing, only to keep dep available
+    end)

+ 1 - 1
packages/o/openscenegraph/xmake.lua

@@ -71,7 +71,7 @@ package("openscenegraph")
         end
         end
         import("package.tools.cmake").install(package, configs)
         import("package.tools.cmake").install(package, configs)
         local suffix = package:is_debug() and "d" or ""
         local suffix = package:is_debug() and "d" or ""
-        for _, lib in ipairs({"osg", "osgGA", "osgUtil", "osgDB", "osgText", "osgWidget", "osgTerrain", "osgFX", "osgViewer", "osgVolume", "osgManipulator", "osgAnimation", "osgParticle", "osgShadow", "osgPresentation", "osgSim", "OpenThreads"}) do
+        for _, lib in ipairs({"osgPresentation", "osgSim", "osgShadow", "osgParticle", "osgAnimation", "osgManipulator", "osgTerrain", "osgVolume", "osgWidget", "osgUI", "osgViewer", "osgText", "osgFX", "osgGA", "osgDB", "osgUtil", "osg", "OpenThreads"}) do
             package:add("links", lib .. suffix)
             package:add("links", lib .. suffix)
         end
         end
     end)
     end)

+ 9 - 1
packages/p/pybind11/xmake.lua

@@ -21,7 +21,15 @@ package("pybind11")
 
 
     add_deps("cmake", "python 3.x")
     add_deps("cmake", "python 3.x")
     on_install("windows|native", "macosx", "linux", function (package)
     on_install("windows|native", "macosx", "linux", function (package)
-        import("package.tools.cmake").install(package, {"-DPYBIND11_TEST=OFF"})
+        import("detect.tools.find_python3")
+
+        local configs = {"-DPYBIND11_TEST=OFF"}
+        local python = find_python3()
+        local pythondir = path.directory(python)
+        if pythondir and path.is_absolute(pythondir) then
+            table.insert(configs, "-DPython_ROOT_DIR=" .. pythondir)
+        end
+        import("package.tools.cmake").install(package, configs)
     end)
     end)
 
 
     on_test(function (package)
     on_test(function (package)

+ 2 - 0
packages/u/urdfdom/xmake.lua

@@ -12,6 +12,8 @@ package("urdfdom")
 
 
     add_patches("1.0.4", path.join(os.scriptdir(), "patches", "1.0.4", "build.patch"), "1f51148afccef7b9bf079ef4137c12d578fb7a76f7aed6e282ca2ceaf4a188ba")
     add_patches("1.0.4", path.join(os.scriptdir(), "patches", "1.0.4", "build.patch"), "1f51148afccef7b9bf079ef4137c12d578fb7a76f7aed6e282ca2ceaf4a188ba")
 
 
+    add_configs("shared", {description = "Build shared library.", default = true, type = "boolean", readonly = true})
+
     add_deps("cmake")
     add_deps("cmake")
     add_deps("urdfdom-headers", "console-bridge")
     add_deps("urdfdom-headers", "console-bridge")
     on_load("windows", "linux", "macosx", function (package)
     on_load("windows", "linux", "macosx", function (package)