xmake.lua 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. package("dartsim")
  2. set_homepage("https://dartsim.github.io/")
  3. set_description("Dynamic Animation and Robotics Toolkit")
  4. set_license("BSD-2-Clause")
  5. add_urls("https://github.com/dartsim/dart/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/dartsim/dart.git")
  7. add_versions("v6.15.0", "bbf954e283f464f6d0a8a5ab43ce92fd49ced357ccdd986c7cb4c29152df8692")
  8. add_versions("v6.14.5", "eb89cc01f4f48c399b055d462d8ecd2a3f846f825a35ffc67f259186b362e136")
  9. add_versions("v6.14.4", "f5fc7f5cb1269cc127a1ff69be26247b9f3617ce04ff1c80c0f3f6abc7d9ab70")
  10. add_versions("v6.13.0", "4da3ff8cee056252a558b05625a5ff29b21e71f2995e6d7f789abbf6261895f7")
  11. add_versions("v6.14.2", "6bbaf452f8182b97bf22adeab6cc7f3dc1cd2733358543131fa130e07c0860fc")
  12. add_patches("6.x", "patches/6.14.5/dartpy.patch", "c8f989317ac8e20259a91e76d28b986b3d4bda01a8e4d0fc13704f6e4f0e144b")
  13. add_configs("dartpy", {description = "Build dartpy interface.", default = false, type = "boolean"})
  14. add_configs("gui", {description = "Build GLUT GUI.", default = false, type = "boolean"})
  15. local configdeps = {bullet3 = "Bullet",
  16. nlopt = "NLOPT",
  17. ode = "ODE",
  18. openscenegraph = "OpenSceneGraph",
  19. tinyxml2 = "tinyxml2",
  20. urdfdom = "urdfdom",
  21. spdlog = "spdlog"}
  22. for config, dep in pairs(configdeps) do
  23. add_configs(config, {description = "Enable " .. config .. " support.", default = false, type = "boolean"})
  24. end
  25. if is_plat("windows") then
  26. add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
  27. add_cxxflags("/permissive-")
  28. add_syslinks("user32")
  29. -- https://gitlab.kitware.com/cmake/cmake/-/issues/20222
  30. set_policy("package.cmake_generator.ninja", false)
  31. end
  32. set_policy("platform.longpaths", true)
  33. add_deps("cmake")
  34. add_deps("assimp", "libccd", "eigen", "fcl", "octomap", "fmt")
  35. on_load("windows|x64", "linux", "macosx", function (package)
  36. for config, dep in pairs(configdeps) do
  37. if package:config(config) then
  38. package:add("deps", config)
  39. end
  40. end
  41. if package:config("gui") or package:config("dartpy") then
  42. package:add("deps", "glut")
  43. end
  44. if package:config("dartpy") then
  45. package:add("deps", "tinyxml2")
  46. package:add("deps", "urdfdom")
  47. package:add("deps", "openscenegraph")
  48. package:add("deps", "imgui", {configs = {opengl2 = true}})
  49. package:add("deps", "python 3.x")
  50. package:add("deps", "pybind11")
  51. end
  52. if package:config("openscenegraph") then
  53. package:add("deps", "imgui", {configs = {opengl2 = true}})
  54. end
  55. end)
  56. on_install("windows|x64", "linux", "macosx", function (package)
  57. import("detect.tools.find_python3")
  58. -- remove after xmake 2.9.7
  59. io.insert("CMakeLists.txt", 1, "set(CMAKE_MODULE_LINKER_FLAGS \"${CMAKE_SHARED_LINKER_FLAGS}\")\n")
  60. io.replace("CMakeLists.txt", "/GL", "", {plain = true})
  61. io.replace("CMakeLists.txt", "if(TARGET dart)", "if(FALSE)", {plain = true})
  62. io.replace("CMakeLists.txt", "-D_CRT_SECURE_NO_WARNINGS", "-DWIN32 -D_CRT_SECURE_NO_WARNINGS", {plain = true})
  63. io.replace("CMakeLists.txt", "CMAKE_SHARED_LINKER_FLAGS \"-Wl,--no-undefined\"", "CMAKE_SHARED_LINKER_FLAGS \"${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined\"", {plain = true})
  64. io.replace("dart/CMakeLists.txt", "/LTCG", "", {plain = true})
  65. 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})
  66. 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})
  67. io.replace("cmake/DARTFindDependencies.cmake", "check_cxx_source_compiles%(.-\".-\".-(ASSIMP.-DEFINED)%)", "set(%1 1)")
  68. io.replace("cmake/DARTFindOpenSceneGraph.cmake", "osg osgViewer osgManipulator osgGA osgDB osgShadow osgUtil", "osgManipulator osgShadow osgViewer osgGA osgDB osgUtil osg", {plain = true})
  69. 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})
  70. local glut_extra = "find_package(GLUT QUIET MODULE)\ntarget_compile_definitions(GLUT::GLUT INTERFACE FREEGLUT_STATIC)"
  71. if package:is_plat("linux") then
  72. glut_extra = glut_extra .. "\ntarget_link_libraries(GLUT::GLUT INTERFACE Xrandr Xrender Xxf86vm X11)"
  73. end
  74. io.replace("cmake/DARTFindGLUT.cmake", "find_package(GLUT QUIET MODULE)", glut_extra, {plain = true})
  75. local configs = {
  76. "-DDART_USE_SYSTEM_IMGUI=ON",
  77. "-DDART_SKIP_lz4=ON",
  78. "-DDART_SKIP_flann=ON",
  79. "-DDART_SKIP_IPOPT=ON",
  80. "-DDART_SKIP_pagmo=ON",
  81. "-DDART_SKIP_DOXYGEN=ON",
  82. "-DDART_TREAT_WARNINGS_AS_ERRORS=OFF",
  83. "-DDART_VERBOSE=ON"
  84. }
  85. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
  86. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  87. for config, dep in pairs(configdeps) do
  88. table.insert(configs, "-DDART_SKIP_" .. dep .. "=" .. (package:dep(config) and "OFF" or "ON"))
  89. end
  90. if package:is_plat("windows") then
  91. table.insert(configs, "-DDART_RUNTIME_LIBRARY=" .. (package:has_runtime("MT", "MTd") and "/MT" or "/MD"))
  92. end
  93. table.insert(configs, "-DDART_BUILD_DARTPY=" .. (package:config("dartpy") and "ON" or "OFF"))
  94. table.insert(configs, "-DDART_SKIP_GLUT=" .. ((package:config("gui") or package:config("dartpy")) and "OFF" or "ON"))
  95. table.insert(configs, "-DDART_BUILD_GUI_OSG=" .. (package:dep("openscenegraph") and "ON" or "OFF"))
  96. if package:config("dartpy") then
  97. local python = find_python3()
  98. local pythondir = path.directory(python)
  99. if pythondir and path.is_absolute(pythondir) then
  100. table.insert(configs, "-DPython_ROOT_DIR=" .. pythondir)
  101. table.insert(configs, "-DPython3_ROOT_DIR=" .. pythondir)
  102. end
  103. end
  104. local deps = {"imgui"}
  105. if package:is_plat("linux") then
  106. table.insert(deps, "freeglut")
  107. end
  108. import("package.tools.cmake").install(package, configs, {packagedeps = deps})
  109. local suffix = package:is_debug() and "d" or ""
  110. 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
  111. package:add("links", lib .. suffix)
  112. end
  113. if package:config("dartpy") then
  114. os.vrunv("python", {"-m", "pip", "install", "numpy"})
  115. local pythonpath = path.join(package:installdir("lib"), "site-packages")
  116. package:addenv("PYTHONPATH", pythonpath)
  117. if package:is_plat("windows") then
  118. -- after python3.8 dll can not be loaded from PATH
  119. for _, lib in ipairs(package:librarydeps()) do
  120. if lib:name() ~= "python" then
  121. local fetchinfo = lib:fetch()
  122. local libfiles = fetchinfo and fetchinfo.libfiles or {}
  123. for _, file in ipairs(libfiles) do
  124. if file:endswith(".dll") then
  125. os.trycp(file, pythonpath)
  126. end
  127. end
  128. end
  129. end
  130. if package:config("shared") then
  131. os.trycp(path.join(package:installdir("bin"), "*.dll"), pythonpath)
  132. end
  133. end
  134. end
  135. end)
  136. on_test(function (package)
  137. assert(package:check_cxxsnippets({test = [[
  138. #include <dart/dart.hpp>
  139. void test() {
  140. dart::simulation::WorldPtr world = dart::simulation::World::create();
  141. }
  142. ]]}, {configs = {languages = "c++17"}}))
  143. if package:config("dartpy") then
  144. local python = package:is_plat("windows") and "python" or "python3"
  145. os.vrunv(python, {"-c", "import dartpy"})
  146. end
  147. end)