premake4.lua 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. ----------------------------------------------------------------------
  2. -- Premake4 configuration script for OpenDE
  3. -- Contributed by Jason Perkins ([email protected])
  4. -- For more information on Premake: http://industriousone.com/premake
  5. ----------------------------------------------------------------------
  6. ode_version = "0.16"
  7. ----------------------------------------------------------------------
  8. -- Demo list: add/remove demos from here and the rest of the build
  9. -- should just work.
  10. ----------------------------------------------------------------------
  11. local demos = {
  12. "boxstack",
  13. "buggy",
  14. "cards",
  15. "chain1",
  16. "chain2",
  17. "collision",
  18. "convex",
  19. "crash",
  20. "cylvssphere",
  21. "dball",
  22. "dhinge",
  23. "feedback",
  24. "friction",
  25. "gyroscopic",
  26. "gyro2",
  27. "heightfield",
  28. "hinge",
  29. "I",
  30. "jointPR",
  31. "jointPU",
  32. "joints",
  33. "kinematic",
  34. "motion",
  35. "motor",
  36. "ode",
  37. "piston",
  38. "plane2d",
  39. "rfriction",
  40. "slider",
  41. "space",
  42. "space_stress",
  43. "step",
  44. "transmission"
  45. }
  46. local trimesh_demos = {
  47. "basket",
  48. "cyl",
  49. "moving_convex",
  50. "moving_trimesh",
  51. "tracks",
  52. "trimesh"
  53. }
  54. if not _OPTIONS["no-trimesh"] then
  55. demos = table.join(demos, trimesh_demos)
  56. end
  57. ----------------------------------------------------------------------
  58. -- Configuration options
  59. ----------------------------------------------------------------------
  60. newoption {
  61. trigger = "with-demos",
  62. description = "Builds the demo applications and DrawStuff library"
  63. }
  64. newoption {
  65. trigger = "with-tests",
  66. description = "Builds the unit test application"
  67. }
  68. newoption {
  69. trigger = "with-gimpact",
  70. description = "Use GIMPACT for trimesh collisions (experimental)"
  71. }
  72. newoption {
  73. trigger = "all-collis-libs",
  74. description = "Include sources of all collision libraries into the project"
  75. }
  76. newoption {
  77. trigger = "with-libccd",
  78. description = "Uses libccd for handling some collision tests absent in ODE."
  79. }
  80. newoption {
  81. trigger = "no-dif",
  82. description = "Exclude DIF (Dynamics Interchange Format) exports"
  83. }
  84. newoption {
  85. trigger = "no-trimesh",
  86. description = "Exclude trimesh collision geometry"
  87. }
  88. newoption {
  89. trigger = "with-ou",
  90. description = "Use TLS for global caches (allows threaded collision checks for separated spaces)"
  91. }
  92. newoption {
  93. trigger = "no-builtin-threading-impl",
  94. description = "Disable built-in multithreaded threading implementation"
  95. }
  96. newoption {
  97. trigger = "no-threading-intf",
  98. description = "Disable threading interface support (external implementations cannot be assigned)"
  99. }
  100. newoption {
  101. trigger = "16bit-indices",
  102. description = "Use 16-bit indices for trimeshes (default is 32-bit)"
  103. }
  104. newoption {
  105. trigger = "old-trimesh",
  106. description = "Use old OPCODE trimesh-trimesh collider"
  107. }
  108. newoption {
  109. trigger = "to",
  110. value = "path",
  111. description = "Set the output location for the generated project files"
  112. }
  113. newoption {
  114. trigger = "only-shared",
  115. description = "Only build shared (DLL) version of the library"
  116. }
  117. newoption {
  118. trigger = "only-static",
  119. description = "Only build static versions of the library"
  120. }
  121. newoption {
  122. trigger = "only-single",
  123. description = "Only use single-precision math"
  124. }
  125. newoption {
  126. trigger = "only-double",
  127. description = "Only use double-precision math"
  128. }
  129. newoption {
  130. trigger = "no-sse2",
  131. description = "Disable SSE2 use for x86 targets in favor to FPU"
  132. }
  133. -- always clean all of the optional components and toolsets
  134. if _ACTION == "clean" then
  135. _OPTIONS["with-demos"] = ""
  136. _OPTIONS["with-tests"] = ""
  137. for action in premake.action.each() do
  138. os.rmdir(action.trigger)
  139. end
  140. os.remove("../ode/src/config.h")
  141. os.remove("../include/ode/version.h")
  142. os.remove("../include/ode/precision.h")
  143. os.remove("../libccd/src/ccd/precision.h")
  144. end
  145. -- special validation for Xcode
  146. if _ACTION == "xcode3" and (not _OPTIONS["only-static"] and not _OPTIONS["only-shared"]) then
  147. error(
  148. "Xcode does not support different library types in a single project.\n" ..
  149. "Please use one of the flags: --only-static or --only-shared", 0)
  150. end
  151. -- build the list of configurations, based on the flags. Ends up
  152. -- with configurations like "Debug", "DebugSingle" or "DebugSingleShared"
  153. local configs = { "Debug", "Release" }
  154. local function addconfigs(...)
  155. local newconfigs = { }
  156. for _, root in ipairs(configs) do
  157. for _, suffix in ipairs(arg) do
  158. table.insert(newconfigs, root .. suffix)
  159. end
  160. end
  161. configs = newconfigs
  162. end
  163. if not _OPTIONS["only-single"] and not _OPTIONS["only-double"] then
  164. addconfigs("Single", "Double")
  165. end
  166. if not _OPTIONS["only-shared"] and not _OPTIONS["only-static"] then
  167. addconfigs("DLL", "Lib")
  168. end
  169. ----------------------------------------------------------------------
  170. -- The solution, and solution-wide settings
  171. ----------------------------------------------------------------------
  172. solution "ode"
  173. language "C++"
  174. uuid "4DA77C12-15E5-497B-B1BB-5100D5161E15"
  175. location ( _OPTIONS["to"] or _ACTION )
  176. includedirs {
  177. "../include",
  178. "../ode/src"
  179. }
  180. defines { "_MT" }
  181. -- apply the configuration list built above
  182. configurations (configs)
  183. configuration { "Debug*" }
  184. defines { "_DEBUG" }
  185. flags { "Symbols" }
  186. configuration { "Release*" }
  187. defines { "NDEBUG", "dNODEBUG" }
  188. flags { "OptimizeSpeed", "NoFramePointer" }
  189. if not _OPTIONS["no-sse2"] then
  190. flags { "EnableSSE2" }
  191. end
  192. configuration { "*Single*" }
  193. defines { "dIDESINGLE", "CCD_IDESINGLE" }
  194. configuration { "*Double*" }
  195. defines { "dIDEDOUBLE", "CCD_IDEDOUBLE" }
  196. configuration { "Windows" }
  197. defines { "WIN32" }
  198. configuration { "MacOSX" }
  199. linkoptions { "-framework Carbon" }
  200. -- give each configuration a unique output directory
  201. for _, name in ipairs(configurations()) do
  202. configuration { name }
  203. targetdir ( "../lib/" .. name )
  204. end
  205. -- disable Visual Studio security warnings
  206. configuration { "vs*" }
  207. defines { "_CRT_SECURE_NO_DEPRECATE", "_SCL_SECURE_NO_WARNINGS" }
  208. -- enable M_* macros from math.h
  209. configuration { "vs*" }
  210. defines { "_USE_MATH_DEFINES" }
  211. -- don't remember why we had to do this
  212. configuration { "vs2002 or vs2003", "*Lib" }
  213. flags { "StaticRuntime" }
  214. ----------------------------------------------------------------------
  215. -- The demo projects, automated from list above. These go first so
  216. -- they will be selected as the active project automatically in IDEs
  217. ----------------------------------------------------------------------
  218. if _OPTIONS["with-demos"] then
  219. for _, name in ipairs(demos) do
  220. project ( "demo_" .. name )
  221. if name ~= "ode" then
  222. kind "WindowedApp"
  223. else
  224. kind "ConsoleApp"
  225. end
  226. location ( _OPTIONS["to"] or _ACTION )
  227. files { "../ode/demo/demo_" .. name .. ".*" }
  228. links { "ode", "drawstuff" }
  229. configuration { "Windows" }
  230. files { "../drawstuff/src/resources.rc" }
  231. links { "user32", "winmm", "gdi32", "opengl32", "glu32" }
  232. configuration { "MacOSX" }
  233. linkoptions { "-framework Carbon -framework OpenGL -framework AGL" }
  234. configuration { "not Windows", "not MacOSX" }
  235. links { "GL", "GLU" }
  236. end
  237. end
  238. ----------------------------------------------------------------------
  239. -- The ODE library project
  240. ----------------------------------------------------------------------
  241. project "ode"
  242. -- kind "StaticLib"
  243. location ( _OPTIONS["to"] or _ACTION )
  244. includedirs {
  245. "../ode/src/joints",
  246. "../OPCODE",
  247. "../GIMPACT/include",
  248. "../libccd/src/custom",
  249. "../libccd/src"
  250. }
  251. files {
  252. "../include/ode/*.h",
  253. "../ode/src/joints/*.h",
  254. "../ode/src/joints/*.cpp",
  255. "../ode/src/*.h",
  256. "../ode/src/*.c",
  257. "../ode/src/*.cpp",
  258. }
  259. excludes {
  260. "../ode/src/collision_std.cpp",
  261. }
  262. includedirs { "../ou/include" }
  263. files { "../ou/include/**.h", "../ou/src/**.h", "../ou/src/**.cpp" }
  264. defines { "_OU_NAMESPACE=odeou" }
  265. if _OPTIONS["with-ou"] then
  266. defines { "_OU_FEATURE_SET=_OU_FEATURE_SET_TLS" }
  267. elseif not _OPTIONS["no-threading-intf"] then
  268. defines { "_OU_FEATURE_SET=_OU_FEATURE_SET_ATOMICS" }
  269. else
  270. defines { "_OU_FEATURE_SET=_OU_FEATURE_SET_BASICS" }
  271. end
  272. if _OPTIONS["with-ou"] or not _OPTIONS["no-threading-intf"] then
  273. if _ACTION == "gmake" then
  274. if os.get() == "windows" then
  275. buildoptions { "-mthreads" }
  276. linkoptions { "-mthreads" }
  277. defines { "HAVE_PTHREAD_ATTR_SETINHERITSCHED=1", "HAVE_PTHREAD_ATTR_SETSTACKLAZY=1" }
  278. else
  279. buildoptions { "-pthread" }
  280. linkoptions { "-pthread" }
  281. end
  282. end
  283. end
  284. configuration { "no-dif" }
  285. excludes { "../ode/src/export-dif.cpp" }
  286. configuration { "no-trimesh" }
  287. excludes {
  288. "../ode/src/collision_trimesh_colliders.h",
  289. "../ode/src/gimpact_contact_export_helper.cpp",
  290. "../ode/src/gimpact_contact_export_helper.h",
  291. "../ode/src/gimpact_gim_contact_accessor.h",
  292. "../ode/src/gimpact_plane_contact_accessor.h",
  293. "../ode/src/collision_trimesh_internal.cpp",
  294. "../ode/src/collision_trimesh_opcode.cpp",
  295. "../ode/src/collision_trimesh_gimpact.cpp",
  296. "../ode/src/collision_trimesh_box.cpp",
  297. "../ode/src/collision_trimesh_ccylinder.cpp",
  298. "../ode/src/collision_cylinder_trimesh.cpp",
  299. "../ode/src/collision_trimesh_ray.cpp",
  300. "../ode/src/collision_trimesh_sphere.cpp",
  301. "../ode/src/collision_trimesh_trimesh.cpp",
  302. "../ode/src/collision_trimesh_trimesh_old.cpp",
  303. "../ode/src/collision_trimesh_plane.cpp",
  304. "../ode/src/collision_convex_trimesh.cpp"
  305. }
  306. configuration { "not no-trimesh", "with-gimpact or all-collis-libs" }
  307. files { "../GIMPACT/**.h", "../GIMPACT/**.cpp" }
  308. configuration { "not no-trimesh", "not with-gimpact" }
  309. files { "../OPCODE/**.h", "../OPCODE/**.cpp" }
  310. configuration { "not no-trimesh", "not all-collis-libs", "with-gimpact" }
  311. excludes {
  312. "../ode/src/collision_trimesh_opcode.cpp"
  313. }
  314. configuration { "not no-trimesh", "not all-collis-libs", "not with-gimpact" }
  315. excludes {
  316. "../ode/src/gimpact_contact_export_helper.cpp",
  317. "../ode/src/gimpact_contact_export_helper.h",
  318. "../ode/src/gimpact_gim_contact_accessor.h",
  319. "../ode/src/gimpact_plane_contact_accessor.h",
  320. "../ode/src/collision_trimesh_gimpact.cpp"
  321. }
  322. configuration { "with-libccd" }
  323. files { "../libccd/src/custom/ccdcustom/*.h", "../libccd/src/ccd/*.h", "../libccd/src/*.c" }
  324. defines { "dLIBCCD_ENABLED", "dLIBCCD_INTERNAL",
  325. "dLIBCCD_BOX_CYL", "dLIBCCD_CYL_CYL", "dLIBCCD_CAP_CYL", "dLIBCCD_CONVEX_BOX",
  326. "dLIBCCD_CONVEX_CAP", "dLIBCCD_CONVEX_CYL", "dLIBCCD_CONVEX_SPHERE", "dLIBCCD_CONVEX_CONVEX" }
  327. configuration { "not with-libccd" }
  328. excludes { "../ode/src/collision_libccd.cpp", "../ode/src/collision_libccd.h" }
  329. configuration { "windows" }
  330. links { "user32" }
  331. configuration { "only-static or *Lib" }
  332. kind "StaticLib"
  333. defines "ODE_LIB"
  334. configuration { "only-shared or *DLL" }
  335. kind "SharedLib"
  336. defines "ODE_DLL"
  337. configuration { "*DLL" }
  338. defines "_DLL"
  339. configuration { "Debug" }
  340. targetname "oded"
  341. configuration { "Release" }
  342. targetname "ode"
  343. configuration { "DebugSingle*" }
  344. targetname "ode_singled"
  345. configuration { "ReleaseSingle*" }
  346. targetname "ode_single"
  347. configuration { "DebugDouble*" }
  348. targetname "ode_doubled"
  349. configuration { "ReleaseDouble*" }
  350. targetname "ode_double"
  351. ----------------------------------------------------------------------
  352. -- Write a custom <config.h> to build, based on the supplied flags
  353. ----------------------------------------------------------------------
  354. if _ACTION and _ACTION ~= "clean" then
  355. local infile = io.open("config-default.h", "r")
  356. local text = infile:read("*a")
  357. if _OPTIONS["no-trimesh"] then
  358. text = string.gsub(text, "#define dTRIMESH_ENABLED 1", "/* #define dTRIMESH_ENABLED 1 */")
  359. text = string.gsub(text, "#define dTRIMESH_OPCODE 1", "/* #define dTRIMESH_OPCODE 1 */")
  360. elseif (_OPTIONS["with-gimpact"]) then
  361. text = string.gsub(text, "#define dTRIMESH_OPCODE 1", "#define dTRIMESH_GIMPACT 1")
  362. end
  363. text = string.gsub(text, "/%* #define dOU_ENABLED 1 %*/", "#define dOU_ENABLED 1")
  364. if _OPTIONS["with-ou"] or not _OPTIONS["no-threading-intf"] then
  365. text = string.gsub(text, "/%* #define dATOMICS_ENABLED 1 %*/", "#define dATOMICS_ENABLED 1")
  366. end
  367. if _OPTIONS["with-ou"] then
  368. text = string.gsub(text, "/%* #define dTLS_ENABLED 1 %*/", "#define dTLS_ENABLED 1")
  369. end
  370. if _OPTIONS["no-threading-intf"] then
  371. text = string.gsub(text, "/%* #define dTHREADING_INTF_DISABLED 1 %*/", "#define dTHREADING_INTF_DISABLED 1")
  372. elseif not _OPTIONS["no-builtin-threading-impl"] then
  373. text = string.gsub(text, "/%* #define dBUILTIN_THREADING_IMPL_ENABLED 1 %*/", "#define dBUILTIN_THREADING_IMPL_ENABLED 1")
  374. end
  375. if _OPTIONS["16bit-indices"] then
  376. text = string.gsub(text, "#define dTRIMESH_16BIT_INDICES 0", "#define dTRIMESH_16BIT_INDICES 1")
  377. end
  378. if _OPTIONS["old-trimesh"] then
  379. text = string.gsub(text, "#define dTRIMESH_OPCODE_USE_OLD_TRIMESH_TRIMESH_COLLIDER 0", "#define dTRIMESH_OPCODE_USE_OLD_TRIMESH_TRIMESH_COLLIDER 1")
  380. end
  381. local outfile = io.open("../ode/src/config.h", "w")
  382. outfile:write(text)
  383. outfile:close()
  384. end
  385. ----------------------------
  386. -- Write precision headers
  387. ----------------------------
  388. if _ACTION and _ACTION ~= "clean" then
  389. function generateheader(headerfile, placeholder, precstr)
  390. local outfile = io.open(headerfile, "w")
  391. for i in io.lines(headerfile .. ".in")
  392. do
  393. local j,_ = string.gsub(i, placeholder, precstr)
  394. --print("writing " .. j .. " into " .. headerfile)
  395. outfile:write(j .. "\n")
  396. end
  397. outfile:close()
  398. end
  399. function generate(precstr)
  400. generateheader("../include/ode/precision.h", "@ODE_PRECISION@", "d" .. precstr)
  401. generateheader("../libccd/src/ccd/precision.h", "@CCD_PRECISION@", "CCD_" .. precstr)
  402. end
  403. if _OPTIONS["only-single"] then
  404. generate("SINGLE")
  405. elseif _OPTIONS["only-double"] then
  406. generate("DOUBLE")
  407. else
  408. generate("UNDEFINEDPRECISION")
  409. end
  410. generateheader("../include/ode/version.h", "@ODE_VERSION@", ode_version)
  411. end
  412. ----------------------------------------------------------------------
  413. -- The DrawStuff library project
  414. ----------------------------------------------------------------------
  415. if _OPTIONS["with-demos"] then
  416. project "drawstuff"
  417. location ( _OPTIONS["to"] or _ACTION )
  418. files {
  419. "../include/drawstuff/*.h",
  420. "../drawstuff/src/internal.h",
  421. "../drawstuff/src/drawstuff.cpp"
  422. }
  423. configuration { "Debug*" }
  424. targetname "drawstuffd"
  425. configuration { "only-static or *Lib" }
  426. kind "StaticLib"
  427. defines { "DS_LIB" }
  428. configuration { "only-shared or *DLL" }
  429. kind "SharedLib"
  430. defines { "DS_DLL", "USRDLL" }
  431. configuration { "Windows" }
  432. files { "../drawstuff/src/resource.h", "../drawstuff/src/resources.rc", "../drawstuff/src/windows.cpp" }
  433. links { "user32", "opengl32", "glu32", "winmm", "gdi32" }
  434. configuration { "MacOSX" }
  435. defines { "HAVE_APPLE_OPENGL_FRAMEWORK" }
  436. files { "../drawstuff/src/osx.cpp" }
  437. linkoptions { "-framework Carbon -framework OpenGL -framework AGL" }
  438. configuration { "not Windows", "not MacOSX" }
  439. files { "../drawstuff/src/x11.cpp" }
  440. links { "X11", "GL", "GLU" }
  441. end
  442. ----------------------------------------------------------------------
  443. -- The automated test application
  444. ----------------------------------------------------------------------
  445. if _OPTIONS["with-tests"] then
  446. project "tests"
  447. kind "ConsoleApp"
  448. location ( _OPTIONS["to"] or _ACTION )
  449. includedirs {
  450. "../ou/include",
  451. "../tests/UnitTest++/src"
  452. }
  453. files {
  454. "../tests/*.cpp",
  455. "../tests/joints/*.cpp",
  456. "../tests/UnitTest++/src/*"
  457. }
  458. links { "ode" }
  459. configuration { "Windows" }
  460. files { "../tests/UnitTest++/src/Win32/*" }
  461. configuration { "not Windows" }
  462. files { "../tests/UnitTest++/src/Posix/*" }
  463. -- add post-build step to automatically run test executable
  464. local path_to_lib = path.getrelative(location(), "../lib")
  465. local command = path.translate(path.join(path_to_lib, "%s/tests"))
  466. for _, name in ipairs(configurations()) do
  467. configuration { name }
  468. postbuildcommands { command:format(name) }
  469. end
  470. end