premake4.lua 16 KB

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