xmake.lua 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  1. package("opencascade")
  2. set_homepage("https://dev.opencascade.org/")
  3. set_description("Open CASCADE Technology (OCCT) is an open-source software development platform for 3D CAD, CAM, CAE.")
  4. set_license("LGPL-2.1")
  5. add_urls("https://github.com/Open-Cascade-SAS/OCCT/archive/refs/tags/V$(version).tar.gz",
  6. {version = function (version) return version:gsub("%.", "_") end})
  7. --[[ note: to add new versions, opencascade.modules.components.<version>.json must be provided.
  8. it can be generated by parsing the OCCT source's MODULES and EXTERNLIB files from a GitHub
  9. release archive to extract and categorize module/component dependencies.
  10. for more info: https://gist.github.com/ecoezen/9ac2babb0abca3151c637df635f02207
  11. ]]
  12. add_versions("7.9.1", "de442298cd8860f5580b01007f67f0ecd0b8900cfa4da467fa3c823c2d1a45df")
  13. add_deps("cmake")
  14. -- Core OCCT modules
  15. add_configs("foundation_classes", {description = "Build Foundation Classes module.", default = true, type = "boolean", readonly = true})
  16. add_configs("modeling_data", {description = "Build Modeling Data module.", default = true, type = "boolean"})
  17. add_configs("modeling_algorithms", {description = "Build Modeling Algorithms module.", default = true, type = "boolean"})
  18. add_configs("visualization", {description = "Build Visualization module.", default = true, type = "boolean"})
  19. add_configs("application_framework", {description = "Build Application Framework module.", default = true, type = "boolean"})
  20. add_configs("data_exchange", {description = "Build Data Exchange module.", default = true, type = "boolean"})
  21. add_configs("de_tools", {description = "Build Data Exchange Tools module.", default = true, type = "boolean"})
  22. -- currently not supported.
  23. add_configs("draw", {description = "Build DRAW Test Harness and related modules.", default = false, type = "boolean", readonly = true})
  24. add_configs("draco", {description = "Build with Draco support.", default = false, type = "boolean"})
  25. add_configs("d3d9", {description = "Build with D3D9 support.", default = false, type = "boolean"})
  26. add_configs("extended_debug_messages", {description = "Enable extended debug messages in Debug builds.", default = false, type = "boolean"})
  27. add_configs("ffmpeg", {description = "Build with FFMPEG support.", default = false, type = "boolean"})
  28. add_configs("freeimage", {description = "Build with FreeImage support.", default = false, type = "boolean"})
  29. add_configs("freetype", {description = "Build with FreeType support.", default = false, type = "boolean"})
  30. add_configs("gles2", {description = "Build with OpenGL ES support.", default = false, type = "boolean"})
  31. add_configs("opengl", {description = "Build with OpenGL support.", default = false, type = "boolean"})
  32. add_configs("openvr", {description = "Build with OpenVR support.", default = false, type = "boolean"})
  33. add_configs("rapidjson", {description = "Build with RapidJSON support.", default = false, type = "boolean"})
  34. add_configs("tbb", {description = "Build with TBB support.", default = false, type = "boolean"})
  35. add_configs("tk", {description = "Build with TK support for DRAW.", default = false, type = "boolean"})
  36. add_configs("vtk", {description = "Build with VTK support.", default = false, type = "boolean"})
  37. add_configs("cxx_standard", {description = "Select c++ standard to build.", default = "11", type = "string", values = {"11", "14", "17", "20", "23"}})
  38. on_load(function (package)
  39. import("core.base.json")
  40. local function config_override_all(configs, value, reason)
  41. assert(type(configs) == "table", "Expected a table for config keys")
  42. local overridden = {}
  43. for _, name in ipairs(configs) do
  44. if package:config(name) ~= value then
  45. package:config_set(name, value)
  46. table.insert(overridden, name)
  47. end
  48. end
  49. if #overridden > 0 and reason then
  50. cprint("${yellow}warning: configs [%s] were overridden to %s. Reason: %s",
  51. table.concat(overridden, ", "), tostring(value), reason)
  52. end
  53. end
  54. local function enable_dependent_config(_config, config_depends)
  55. if package:config(_config) then
  56. if not package:config(config_depends) then
  57. cprint("${yellow}warning: '%s' depends on '%s', which was disabled. Enabling it automatically.",
  58. _config, config_depends)
  59. package:config_set(config_depends, true)
  60. end
  61. end
  62. end
  63. -- unsupported/disabled configs
  64. config_override_all({
  65. "draw", -- currently not supported. TODO
  66. "gles2", -- currently not supported/tested
  67. "ffmpeg" -- build failures
  68. }, false, "Disabled due to current lack of support or known build failures.")
  69. -- Fallthrough BEGIN
  70. enable_dependent_config("draw", "data_exchange")
  71. enable_dependent_config("data_exchange", "application_framework")
  72. enable_dependent_config("application_framework", "visualization")
  73. enable_dependent_config("visualization", "modeling_algorithms")
  74. enable_dependent_config("modeling_algorithms", "modeling_data")
  75. -- Fallthrough END
  76. if package:version():lt("7.7.2") or package:version():gt("7.9.1") then
  77. config_override_all({"de_tools"}, false,
  78. "de_tools module is not relevant to this version of opencascade.")
  79. end
  80. if not package:config("visualization") then
  81. -- seems like compatible with upcoming version 8.0.0 [TODO]
  82. config_override_all({
  83. "opengl",
  84. "gles2",
  85. "openvr",
  86. "freetype",
  87. "freeimage",
  88. "ffmpeg",
  89. "d3d9",
  90. "vtk"
  91. }, false, "Given configs only relevant to opencascade visualization module, which is is disabled.")
  92. else
  93. config_override_all({
  94. "opengl"
  95. -- ,"gles2" TODO
  96. }, true, "Given configs are required to build opencascade visualization module, which is is enabled.")
  97. if package:version():lt("7.6.0") then
  98. config_override_all({
  99. "freeimage"
  100. }, true, "freeimage is required opencascade visualization module in this version.")
  101. end
  102. if not package:is_targetos("windows", "mingw") then
  103. config_override_all({
  104. "d3d9"
  105. }, false, "Direct3D9 support is a windows-only configuration.")
  106. end
  107. end
  108. if not package:config("data_exchange") then
  109. config_override_all({
  110. "draco",
  111. "rapidjson"
  112. }, false,"Given configs only relevant to opencascade data exchange module, which is is disabled.")
  113. end
  114. if not package:config("draw") then
  115. config_override_all({
  116. "tk",
  117. "tcl"
  118. }, false, "Given configs only relevant to opencascade draw module, which is is disabled and currently not supported.")
  119. end
  120. if not package:is_debug() then
  121. config_override_all({"extended_debug_messages"}, false, "Supported only on debug mode.")
  122. end
  123. local occt_cmake_to_xmake_deps = {
  124. ["CSF_FREETYPE"] = package:config("freetype") and { deps = {"freetype"} } or nil,
  125. ["CSF_TclLibs"] = package:config("tcl") and { deps = {"tcl"} } or nil,
  126. ["CSF_fontconfig"] = package:is_plat("linux") and { deps = {"fontconfig"} } or nil,
  127. ["CSF_XwLibs"] = package:is_plat("linux") and { deps = {"libx11"} } or nil, -- ? not sure
  128. -- optional deps
  129. ["CSF_OpenGlLibs"] = package:config("opengl") and { deps = {"opengl"} } or nil,
  130. -- missing opengles. TODO
  131. ["CSF_TclTkLibs"] = package:config("tk") and { deps = {"tk"} } or nil,
  132. ["CSF_FFmpeg"] = package:config("ffmpeg") and { deps = {"ffmpeg"} } or nil,
  133. ["CSF_FreeImagePlus"] = package:config("freeimage") and { deps = {"freeimage"} } or nil,
  134. ["CSF_OpenVR"] = package:config("openvr") and { deps = {"openvr"} } or nil,
  135. ["CSF_RapidJSON"] = package:config("rapidjson") and { deps = {"rapidjson"} } or nil,
  136. ["CSF_Draco"] = package:config("draco") and { deps = {"draco"} } or nil,
  137. ["CSF_TBB"] = package:config("tbb") and { deps = {"tbb"} } or nil,
  138. ["CSF_VTK"] = package:config("vtk") and { deps = {"vtk"} } or nil,
  139. ["CSF_MMGR"] = nil,
  140. -- system libs
  141. ["CSF_androidlog"] = package:is_plat("android") and { syslinks = {"log"} } or nil,
  142. ["CSF_ThreadLibs"] = package:is_plat("linux") and { syslinks = {"pthread", "rt"} } or nil,
  143. ["CSF_dl"] = package:is_plat("linux") and { syslinks = {"dl"} } or nil,
  144. ["CSF_dpsLibs"] = nil,
  145. ["CSF_XmuLibs"] = nil,
  146. ["CSF_advapi32"] = package:is_plat("windows") and { syslinks = {"advapi32"} } or nil,
  147. ["CSF_gdi32"] = package:is_plat("windows") and { syslinks = {"gdi32"} } or nil,
  148. ["CSF_psapi"] = package:is_plat("windows") and { syslinks = {"psapi"} } or nil,
  149. ["CSF_shell32"] = package:is_plat("windows") and { syslinks = {"shell32"} } or nil,
  150. ["CSF_user32"] = package:is_plat("windows") and { syslinks = {"user32"} } or nil,
  151. ["CSF_winmm"] = package:is_plat("windows") and { syslinks = {"winmm"} } or nil,
  152. ["CSF_wsock32"] = package:is_plat("windows") and { syslinks = {"wsock32"} } or nil,
  153. ["CSF_d3d9"] = package:config("d3d9") and { syslinks = {"d3d9"} } or nil,
  154. -- macOS / iOS frameworks
  155. ["CSF_Appkit"] = package:is_plat("iphoneos") and { frameworks = {"UIKit"} }
  156. or (package:is_plat("macosx") and { frameworks = {"AppKit"} } or nil),
  157. ["CSF_IOKit"] = package:is_plat("macosx") and { frameworks = {"IOKit"} } or nil,
  158. ["CSF_objc"] = package:is_plat("macosx", "iphoneos") and { syslinks = {"objc"} } or nil,
  159. }
  160. local function add_mapped_deps(dep_kind)
  161. for cmake_dep, xmake_dep in pairs(occt_cmake_to_xmake_deps) do
  162. if xmake_dep then
  163. local deps = xmake_dep[dep_kind]
  164. if deps then
  165. for _, syslib in ipairs(deps) do
  166. package:add(dep_kind, syslib)
  167. end
  168. end
  169. end
  170. end
  171. end
  172. -- Fallthrough BEGIN
  173. add_mapped_deps("syslinks")
  174. add_mapped_deps("frameworks")
  175. add_mapped_deps("deps")
  176. -- Fallthrough END
  177. local occt_component_map = {}
  178. local json_file_name = "opencascade.modules.components." .. package:version() .. ".json"
  179. local json_file_path = path.join(os.scriptdir(), json_file_name)
  180. if os.isfile(json_file_path) then
  181. local json_str = io.readfile(json_file_path)
  182. occt_component_map = json.decode(json_str)
  183. else
  184. raise("Missing OpenCascade component map: %s\nEnsure the file exists for version %s.", json_file_name, version)
  185. end
  186. -- based on version 7.9.1. if any version adds new module, please add.
  187. -- do not remove modules even if the version removes one.
  188. -- DETools module introduced with v7.7 and removed in upcoming v8
  189. local occt_module_to_component_name = {
  190. FoundationClasses = "foundation-classes",
  191. ModelingData = "modeling-data",
  192. ModelingAlgorithms = "modeling-algorithms",
  193. Visualization = "visualization",
  194. ApplicationFramework = "application-framework",
  195. DataExchange = "data-exchange",
  196. DETools = "de-tools",
  197. Draw = "draw"
  198. }
  199. local conditional_modules = {
  200. FoundationClasses = package:config("foundation_classes"),
  201. ModelingData = package:config("modeling_data"),
  202. ModelingAlgorithms = package:config("modeling_algorithms"),
  203. Visualization = package:config("visualization"),
  204. ApplicationFramework = package:config("application_framework"),
  205. DataExchange = package:config("data_exchange"),
  206. DETools = package:config("de_tools"),
  207. Draw = package:config("draw")
  208. }
  209. local conditional_toolkits = {
  210. TKD3DHost = package:config("d3d9") and package:config("visualization"),
  211. TKD3DHostTest = package:config("d3d9") and package:config("draw"),
  212. TKIVtk = package:config("vtk") and package:config("visualization"),
  213. TKIVtkDraw = package:config("vtk") and package:config("draw"),
  214. TKOpenGles = package:config("gles2") and package:config("visualization"),
  215. TKOpenGlesTest = package:config("gles2") and package:config("draw"),
  216. TKOpenGl = package:config("opengl") and package:config("visualization"),
  217. TKOpenGlTest = package:config("opengl") and package:config("draw"),
  218. -- executables that are excluded from components (is there any way to use them as components properly?)
  219. ExpToCasExe = false
  220. }
  221. -- first, only add components : programmatic add_components
  222. for occt_module, condition in pairs(conditional_modules) do
  223. if condition then
  224. local module_info = occt_component_map[occt_module]
  225. if module_info then
  226. local module_comp_name = occt_module_to_component_name[occt_module]
  227. package:add("components", module_comp_name)
  228. for toolkit, toolkit_info in pairs(module_info) do
  229. if conditional_toolkits[toolkit] ~= false then
  230. package:add("components", toolkit:lower())
  231. end
  232. end
  233. end
  234. end
  235. end
  236. -- second, handle component deps, links.. : programmatic on_component
  237. for occt_module, condition in pairs(conditional_modules) do
  238. if condition then
  239. local module_info = occt_component_map[occt_module]
  240. if module_info then
  241. local module_comp_name = occt_module_to_component_name[occt_module]
  242. local module_component = package:component(module_comp_name)
  243. for toolkit, toolkit_info in pairs(module_info) do
  244. if conditional_toolkits[toolkit] ~= false then
  245. local toolkit_component = package:component(toolkit:lower())
  246. -- should we remove this from components?
  247. if toolkit_info.syslinks then
  248. for _, cmake_syslib in ipairs(toolkit_info.syslinks) do
  249. local dep_info = occt_cmake_to_xmake_deps[cmake_syslib]
  250. if dep_info and dep_info.syslinks then
  251. for _, syslib in ipairs(dep_info.syslinks) do
  252. toolkit_component:add("syslinks", syslib)
  253. module_component:add("syslinks", syslib)
  254. end
  255. end
  256. end
  257. end
  258. -- should we remove this from components?
  259. if toolkit_info.frameworks then
  260. for _, cmake_syslib in ipairs(toolkit_info.frameworks) do
  261. local dep_info = occt_cmake_to_xmake_deps[cmake_syslib]
  262. if dep_info and dep_info.frameworks then
  263. for _, framework in ipairs(dep_info.frameworks) do
  264. toolkit_component:add("frameworks", framework)
  265. module_component:add("frameworks", framework)
  266. end
  267. end
  268. end
  269. end
  270. -- seems like component does not recognizes packages as deps
  271. -- as it raise warning like unknown component (tbb)
  272. -- skipping here as syslinks and deps are still globally
  273. -- available maybe it is best to remove above syslinks
  274. -- per component and rely on package scope.
  275. if toolkit_info.links then
  276. for _, internal in ipairs(toolkit_info.links) do
  277. toolkit_component:add("links", internal)
  278. end
  279. end
  280. -- add toolkit itself as links
  281. toolkit_component:add("links", toolkit)
  282. -- add links to the module component as well
  283. module_component:add("links", toolkit)
  284. end
  285. end
  286. end
  287. end
  288. end
  289. -- TODO add linkorders
  290. end)
  291. on_install("windows", "macosx", "linux", function (package)
  292. local configs = {}
  293. table.insert(configs, "-DCMAKE_POLICY_DEFAULT_CMP0042=NEW")
  294. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  295. table.insert(configs, "-DBUILD_LIBRARY_TYPE=" .. (package:config("shared") and "Shared" or "Static"))
  296. if package:version():ge("7.8.0") then
  297. table.insert(configs, "-DBUILD_CPP_STANDARD=C++" .. package:config("cxx_standard"))
  298. end
  299. if package:is_debug() then
  300. table.insert(configs, "-DBUILD_WITH_DEBUG=" .. (package:config("extended_debug_messages") and "ON" or "OFF"))
  301. end
  302. if package:is_plat("windows", "mingw") then
  303. table.insert(configs, "-DBUILD_SAMPLES_MFC=OFF")
  304. table.insert(configs, "-DUSE_D3D=" .. (package:config("d3d9") and "ON" or "OFF"))
  305. end
  306. if package:is_plat("macosx") then
  307. table.insert(configs, "-DUSE_GLX=OFF")
  308. end
  309. table.insert(configs, "-DINSTALL_SAMPLES=OFF")
  310. table.insert(configs, "-DINSTALL_TEST_CASES=OFF")
  311. table.insert(configs, "-DINSTALL_DIR_LAYOUT=Unix")
  312. table.insert(configs, "-DINSTALL_DIR_BIN=bin")
  313. table.insert(configs, "-DINSTALL_DIR_LIB=lib")
  314. table.insert(configs, "-DINSTALL_DIR_INCLUDE=include")
  315. table.insert(configs, "-DINSTALL_DIR_RESOURCE=res/resource")
  316. table.insert(configs, "-DINSTALL_DIR_DATA=res/data")
  317. table.insert(configs, "-DINSTALL_DIR_SAMPLES=res/samples")
  318. table.insert(configs, "-DINSTALL_DIR_DOC=res/doc")
  319. table.insert(configs, "-DBUILD_RESOURCES=OFF")
  320. table.insert(configs, "-DBUILD_USE_PCH=OFF")
  321. table.insert(configs, "-DBUILD_USE_VCPKG=OFF")
  322. table.insert(configs, "-DBUILD_YACCLEX=OFF")
  323. table.insert(configs, "-DBUILD_Inspector=OFF")
  324. table.insert(configs, "-DBUILD_ENABLE_FPE_SIGNAL_HANDLER=OFF")
  325. table.insert(configs, "-DBUILD_DOC_Overview=OFF")
  326. table.insert(configs, "-DBUILD_SAMPLES_QT=OFF")
  327. table.insert(configs, "-DBUILD_RELEASE_DISABLE_EXCEPTIONS=ON")
  328. -- enable/disable occt modules
  329. table.insert(configs, "-DBUILD_MODULE_FoundationClasses=" .. (package:config("foundation_classes") and "ON" or "OFF"))
  330. table.insert(configs, "-DBUILD_MODULE_ModelingData=" .. (package:config("modeling_data") and "ON" or "OFF"))
  331. table.insert(configs, "-DBUILD_MODULE_ModelingAlgorithms=" .. (package:config("modeling_algorithms") and "ON" or "OFF"))
  332. table.insert(configs, "-DBUILD_MODULE_Visualization=" .. (package:config("visualization") and "ON" or "OFF"))
  333. table.insert(configs, "-DBUILD_MODULE_ApplicationFramework=" .. (package:config("application_framework") and "ON" or "OFF"))
  334. table.insert(configs, "-DBUILD_MODULE_DataExchange=" .. (package:config("data_exchange") and "ON" or "OFF"))
  335. -- currently not supported
  336. table.insert(configs, "-DBUILD_MODULE_Draw=" .. (package:config("draw") and "ON" or "OFF"))
  337. if package:version():ge("7.7.2") or package:version():le("7.9.1") then
  338. table.insert(configs, "-DBUILD_MODULE_DETools=" .. (package:config("de_tools") and "ON" or "OFF"))
  339. end
  340. table.insert(configs, "-DUSE_TBB=" .. (package:config("tbb") and "ON" or "OFF"))
  341. table.insert(configs, "-DUSE_FREEIMAGE=" .. (package:config("freeimage") and "ON" or "OFF"))
  342. table.insert(configs, "-DUSE_FFMPEG=" .. (package:config("ffmpeg") and "ON" or "OFF"))
  343. table.insert(configs, "-DUSE_VTK=" .. (package:config("vtk") and "ON" or "OFF"))
  344. table.insert(configs, "-DUSE_OPENGL=" .. (package:config("opengl") and "ON" or "OFF"))
  345. table.insert(configs, "-DUSE_OPENVR=" .. (package:config("openvr") and "ON" or "OFF"))
  346. table.insert(configs, "-DUSE_GLES2=" .. (package:config("gles2") and "ON" or "OFF"))
  347. table.insert(configs, "-DUSE_DRACO=" .. (package:config("draco") and "ON" or "OFF"))
  348. table.insert(configs, "-DUSE_TK=" .. (package:config("tk") and "ON" or "OFF"))
  349. if package:version():ge("7.6.0") then
  350. table.insert(configs, "-DUSE_FREETYPE=" .. (package:config("freetype") and "ON" or "OFF"))
  351. end
  352. local cmakelists = "CMakeLists.txt"
  353. local occt_csf_cmake_file = "adm/cmake/occt_csf.cmake"
  354. if package:config("tbb") then
  355. local dep_tbb = package:dep("tbb")
  356. table.insert(configs, "-D3RDPARTY_TBB_DIR=" .. path.unix(dep_tbb:installdir()))
  357. local tbb_libs = table.concat(dep_tbb:get("links") or {"tbb", "tbbmalloc", "tbbmalloc_proxy"}, " ")
  358. io.replace(
  359. occt_csf_cmake_file,
  360. "set (CSF_TBB \"tbb tbbmalloc\")",
  361. "set (CSF_TBB \"".. tbb_libs .. "\")",
  362. {plain = true}
  363. )
  364. end
  365. if package:config("freetype") then
  366. local dep_freetype = package:dep("freetype")
  367. table.insert(configs, "-D3RDPARTY_FREETYPE_DIR=" .. path.unix(dep_freetype:installdir()))
  368. local freetype_libs = table.concat(dep_freetype:get("links") or {"freetype"}, " ")
  369. io.replace(
  370. occt_csf_cmake_file,
  371. "set (CSF_FREETYPE \"freetype\")",
  372. "set (CSF_FREETYPE \"".. freetype_libs .. "\")",
  373. {plain = true}
  374. )
  375. end
  376. if package:config("freeimage") then
  377. local dep_freeimage = package:dep("freeimage")
  378. table.insert(configs, "-D3RDPARTY_FREEIMAGE_DIR=" .. path.unix(dep_freeimage:installdir()))
  379. -- freeimage get links somehow fails
  380. local freeimage_libs = table.concat(dep_freeimage:get("links") or {"freeimage"}, " ")
  381. io.replace(
  382. occt_csf_cmake_file,
  383. "set (CSF_FreeImagePlus \"freeimage\")",
  384. "set (CSF_FreeImagePlus \"".. freeimage_libs .. "\")",
  385. {plain = true}
  386. )
  387. end
  388. if package:config("ffmpeg") then
  389. local dep_ffmpeg = package:dep("ffmpeg")
  390. table.insert(configs, "-D3RDPARTY_FFMPEG_DIR=" .. path.unix(dep_ffmpeg:installdir()))
  391. local ffmpeg_libs = dep_ffmpeg:get("links")
  392. io.replace(
  393. occt_csf_cmake_file,
  394. "set (CSF_FFmpeg \"avcodec avformat swscale avutil\")",
  395. "set (CSF_FFmpeg \"" .. table.concat(ffmpeg_libs, " ") .. "\")",
  396. {plain = true}
  397. )
  398. end
  399. if package:config("openvr") then
  400. local dep_openvr = package:dep("openvr")
  401. table.insert(configs, "-D3RDPARTY_OPENVR_DIR=" .. path.unix(dep_openvr:installdir()))
  402. -- occt expects openvr.h as #include <openvr.h>
  403. local openvr_inc_dir = path.join(path.unix(dep_openvr:installdir("include")), "openvr")
  404. table.insert(configs, "-D3RDPARTY_OPENVR_INCLUDE_DIR=" .. openvr_inc_dir)
  405. -- Handle openvr links. get links fails here as well..
  406. local openvr_libs = dep_openvr:get("links")
  407. if not openvr_libs then
  408. if package:is_targetos("windows", "mingw") and package:is_targetarch("x64", "x86_64", "amd64") then
  409. openvr_libs = {"openvr_api64"}
  410. else
  411. openvr_libs = {"openvr_api"}
  412. end
  413. end
  414. io.replace(
  415. occt_csf_cmake_file,
  416. "set (CSF_OpenVR \"openvr_api\")",
  417. "set (CSF_OpenVR \"" .. table.concat(openvr_libs, " ") .. "\")", {plain = true})
  418. end
  419. if package:config("rapidjson") then
  420. local dep_rapidjson = package:dep("rapidjson")
  421. table.insert(configs, "-D3RDPARTY_RAPIDJSON_DIR=" .. path.unix(dep_rapidjson:installdir()))
  422. end
  423. if package:config("vtk") then
  424. local dep_vtk = package:dep("vtk")
  425. table.insert(configs, "-D3RDPARTY_VTK_DIR=" .. path.unix(dep_vtk:installdir()))
  426. end
  427. if package:config("draco") then
  428. local dep_draco = package:dep("draco")
  429. table.insert(configs, "-D3RDPARTY_DRACO_DIR=" .. path.unix(dep_draco:installdir()))
  430. -- draco get links fails as well
  431. local draco_libs = table.concat(dep_draco:get("links") or {"draco"}, " ")
  432. io.replace(
  433. occt_csf_cmake_file,
  434. "set (CSF_Draco \"draco\")",
  435. "set (CSF_Draco \"" .. draco_libs .. "\")",
  436. {plain = true}
  437. )
  438. end
  439. -- remove defs/flags that would be injected from xmake.
  440. local occt_defs_cmake = "adm/cmake/occt_defs_flags.cmake"
  441. io.replace(occt_defs_cmake, "-fPIC", "", {plain = true})
  442. io.replace(occt_defs_cmake, "-stdlib=libc++", "", {plain = true})
  443. io.replace(
  444. occt_csf_cmake_file,
  445. "set (CSF_ThreadLibs \"pthread rt stdc++\")",
  446. "set (CSF_ThreadLibs \"pthread rt\")",
  447. {plain = true})
  448. if package:version():lt("7.9.0") then
  449. io.replace(occt_defs_cmake, "-std=c++0x", "", {plain = true})
  450. io.replace(occt_defs_cmake, "-std=gnu++0x", "", {plain = true})
  451. end
  452. -- remove install dir postfix [TODO: check for previos versions compability]
  453. io.replace(
  454. "adm/cmake/occt_macros.cmake",
  455. 'set (OCCT_INSTALL_BIN_LETTER \\"d\\")',
  456. 'set (OCCT_INSTALL_BIN_LETTER \\"\\")', {plain = true})
  457. -- fix patch for disabling pdb installs.
  458. io.replace(
  459. "adm/cmake/occt_toolkit.cmake",
  460. "install (FILES ${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/bin\\${OCCT_INSTALL_BIN_LETTER}/${PROJECT_NAME}.pdb",
  461. "set(no_op_install_fix", {plain = true})
  462. io.replace(
  463. "adm/cmake/occt_toolkit.cmake",
  464. "install (FILES ${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/lib\\${OCCT_INSTALL_BIN_LETTER}/${PROJECT_NAME}.pdb",
  465. "set(no_op_install_fix", {plain = true})
  466. io.replace(
  467. "src/Image/Image_AlienPixMap.cxx",
  468. "#pragma comment(lib, \"FreeImage.lib\")", "", {plain = true})
  469. -- remove pragma links on source files on version 7.6
  470. if package:version():lt("7.6.0") then
  471. io.replace(
  472. "src/Font/Font_FontMgr.cxx",
  473. "#pragma comment (lib, \"freetype.lib\")", "", {plain = true})
  474. io.replace(
  475. "src/Draw/Draw.cxx",
  476. [[#pragma comment (lib, "tcl" STRINGIZE2(TCL_MAJOR_VERSION) STRINGIZE2(TCL_MINOR_VERSION) ".lib")
  477. #pragma comment (lib, "tk" STRINGIZE2(TCL_MAJOR_VERSION) STRINGIZE2(TCL_MINOR_VERSION) ".lib")]],
  478. "", {plain = true})
  479. end
  480. import("package.tools.cmake").install(package, configs)
  481. end)
  482. on_test(function (package)
  483. if package:config("foundation_classes") then
  484. assert(package:check_cxxsnippets({test = [[
  485. #include <Standard_Type.hxx> // foundation tkernel
  486. #include <gp_Pnt.hxx> // foundation tmath
  487. int main() {
  488. Standard_Integer a = 42;
  489. gp_Pnt p(1.0, 2.0, 3.0);
  490. return (a == 42 && p.X() == 1.0) ? 0 : 1;
  491. }
  492. ]]}, {configs = {languages = "c++17"}}))
  493. elseif package:config("modeling_algorithms") then
  494. assert(package:check_cxxsnippets({test = [[
  495. #include <BRepBuilderAPI_MakeEdge.hxx>
  496. #include <TopoDS_Edge.hxx>
  497. #include <GC_MakeCircle.hxx>
  498. #include <gce_MakeCirc.hxx>
  499. #include <gp_Circ.hxx>
  500. #include <iostream>
  501. int main() {
  502. gp_Pnt pc(0, 0, 0);
  503. gp_Circ cir = gce_MakeCirc(pc, gp::DZ(), 5);
  504. auto geometry = GC_MakeCircle(cir).Value();
  505. TopoDS_Edge edge = BRepBuilderAPI_MakeEdge(geometry);
  506. }
  507. ]]}, {configs = {languages = "c++17"}}))
  508. else
  509. print("TODO add more tests to cover all components...")
  510. end
  511. end)