premake4.lua 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  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. ----------------------------------------------------------------------
  7. -- Demo list: add/remove demos from here and the rest of the build
  8. -- should just work.
  9. ----------------------------------------------------------------------
  10. local demos = {
  11. "boxstack",
  12. "buggy",
  13. "cards",
  14. "chain1",
  15. "chain2",
  16. "collision",
  17. "crash",
  18. "cylvssphere",
  19. "feedback",
  20. "friction",
  21. "gyroscopic",
  22. "heightfield",
  23. "hinge",
  24. "I",
  25. "jointPR",
  26. "jointPU",
  27. "joints",
  28. "kinematic",
  29. "motion",
  30. "motor",
  31. "ode",
  32. "piston",
  33. "plane2d",
  34. "slider",
  35. "space",
  36. "space_stress",
  37. "step",
  38. }
  39. local trimesh_demos = {
  40. "basket",
  41. "cyl",
  42. "moving_trimesh",
  43. "trimesh",
  44. "tracks"
  45. }
  46. if not _OPTIONS["no-trimesh"] then
  47. demos = table.join(demos, trimesh_demos)
  48. end
  49. ----------------------------------------------------------------------
  50. -- Configuration options
  51. ----------------------------------------------------------------------
  52. newoption {
  53. trigger = "with-demos",
  54. description = "Builds the demo applications and DrawStuff library"
  55. }
  56. newoption {
  57. trigger = "with-tests",
  58. description = "Builds the unit test application"
  59. }
  60. newoption {
  61. trigger = "with-gimpact",
  62. description = "Use GIMPACT for trimesh collisions (experimental)"
  63. }
  64. newoption {
  65. trigger = "all-collis-libs",
  66. description = "Include sources of all collision libraries into the project"
  67. }
  68. newoption {
  69. trigger = "with-libccd",
  70. description = "Uses libccd for handling some collision tests absent in ODE."
  71. }
  72. newoption {
  73. trigger = "no-dif",
  74. description = "Exclude DIF (Dynamics Interchange Format) exports"
  75. }
  76. newoption {
  77. trigger = "no-trimesh",
  78. description = "Exclude trimesh collision geometry"
  79. }
  80. newoption {
  81. trigger = "with-ou",
  82. description = "Use TLS for global caches (experimental)"
  83. }
  84. newoption {
  85. trigger = "16bit-indices",
  86. description = "Use 16-bit indices for trimeshes (default is 32-bit)"
  87. }
  88. newoption {
  89. trigger = "old-trimesh",
  90. description = "Use old OPCODE trimesh-trimesh collider"
  91. }
  92. newoption {
  93. trigger = "to",
  94. value = "path",
  95. description = "Set the output location for the generated project files"
  96. }
  97. newoption {
  98. trigger = "only-shared",
  99. description = "Only build shared (DLL) version of the library"
  100. }
  101. newoption {
  102. trigger = "only-static",
  103. description = "Only build static versions of the library"
  104. }
  105. newoption {
  106. trigger = "only-single",
  107. description = "Only use single-precision math"
  108. }
  109. newoption {
  110. trigger = "only-double",
  111. description = "Only use double-precision math"
  112. }
  113. -- always clean all of the optional components and toolsets
  114. if _ACTION == "clean" then
  115. _OPTIONS["with-demos"] = ""
  116. _OPTIONS["with-tests"] = ""
  117. for action in premake.action.each() do
  118. os.rmdir(action.trigger)
  119. end
  120. os.remove("../ode/src/config.h")
  121. end
  122. -- special validation for Xcode
  123. if _ACTION == "xcode3" and (not _OPTIONS["only-single"] and not _OPTIONS["only-double"]) then
  124. error(
  125. "Xcode does not support different library types in a single project.\n" ..
  126. "Please use one of the flags: --only-static or --only-shared", 0)
  127. end
  128. -- build the list of configurations, based on the flags. Ends up
  129. -- with configurations like "Debug", "DebugSingle" or "DebugSingleShared"
  130. local configs = { "Debug", "Release" }
  131. local function addconfigs(...)
  132. local newconfigs = { }
  133. for _, root in ipairs(configs) do
  134. for _, suffix in ipairs(arg) do
  135. table.insert(newconfigs, root .. suffix)
  136. end
  137. end
  138. configs = newconfigs
  139. end
  140. if not _OPTIONS["only-single"] and not _OPTIONS["only-double"] then
  141. addconfigs("Single", "Double")
  142. end
  143. if not _OPTIONS["only-shared"] and not _OPTIONS["only-static"] then
  144. addconfigs("DLL", "Lib")
  145. end
  146. ----------------------------------------------------------------------
  147. -- The solution, and solution-wide settings
  148. ----------------------------------------------------------------------
  149. solution "ode"
  150. language "C++"
  151. uuid "4DA77C12-15E5-497B-B1BB-5100D5161E15"
  152. location ( _OPTIONS["to"] or _ACTION )
  153. includedirs {
  154. "../include",
  155. "../ode/src"
  156. }
  157. -- apply the configuration list built above
  158. configurations (configs)
  159. configuration { "Debug*" }
  160. defines { "_DEBUG" }
  161. flags { "Symbols" }
  162. configuration { "Release*" }
  163. flags { "OptimizeSpeed", "NoFramePointer" }
  164. configuration { "only-single or *Single*" }
  165. defines { "dSINGLE", "CCD_SINGLE" }
  166. configuration { "only-double or *Double*" }
  167. defines { "dDOUBLE", "CCD_DOUBLE" }
  168. configuration { "Windows" }
  169. defines { "WIN32" }
  170. configuration { "MacOSX" }
  171. linkoptions { "-framework Carbon" }
  172. -- give each configuration a unique output directory
  173. for _, name in ipairs(configurations()) do
  174. configuration { name }
  175. targetdir ( "../lib/" .. name )
  176. end
  177. -- disable Visual Studio security warnings
  178. configuration { "vs*" }
  179. defines { "_CRT_SECURE_NO_DEPRECATE" }
  180. -- don't remember why we had to do this
  181. configuration { "vs2002 or vs2003", "*Lib" }
  182. flags { "StaticRuntime" }
  183. ----------------------------------------------------------------------
  184. -- The demo projects, automated from list above. These go first so
  185. -- they will be selected as the active project automatically in IDEs
  186. ----------------------------------------------------------------------
  187. if _OPTIONS["with-demos"] then
  188. for _, name in ipairs(demos) do
  189. project ( "demo_" .. name )
  190. kind "ConsoleApp"
  191. location ( _OPTIONS["to"] or _ACTION )
  192. files { "../ode/demo/demo_" .. name .. ".*" }
  193. links { "ode", "drawstuff" }
  194. configuration { "Windows" }
  195. files { "../drawstuff/src/resources.rc" }
  196. links { "user32", "winmm", "gdi32", "opengl32", "glu32" }
  197. configuration { "MacOSX" }
  198. linkoptions { "-framework Carbon -framework OpenGL -framework AGL" }
  199. configuration { "not Windows", "not MacOSX" }
  200. links { "GL", "GLU" }
  201. end
  202. end
  203. ----------------------------------------------------------------------
  204. -- The ODE library project
  205. ----------------------------------------------------------------------
  206. project "ode"
  207. -- kind "StaticLib"
  208. location ( _OPTIONS["to"] or _ACTION )
  209. includedirs {
  210. "../ode/src/joints",
  211. "../OPCODE",
  212. "../GIMPACT/include",
  213. "../ou/include",
  214. "../libccd/src"
  215. }
  216. files {
  217. "../include/ode/*.h",
  218. "../ode/src/joints/*.h",
  219. "../ode/src/joints/*.cpp",
  220. "../ode/src/*.h",
  221. "../ode/src/*.c",
  222. "../ode/src/*.cpp",
  223. }
  224. excludes {
  225. "../ode/src/collision_std.cpp",
  226. }
  227. configuration { "no-dif" }
  228. excludes { "../ode/src/export-dif.cpp" }
  229. configuration { "no-trimesh" }
  230. excludes {
  231. "../ode/src/collision_trimesh_colliders.h",
  232. "../ode/src/collision_trimesh_internal.h",
  233. "../ode/src/collision_trimesh_opcode.cpp",
  234. "../ode/src/collision_trimesh_gimpact.cpp",
  235. "../ode/src/collision_trimesh_box.cpp",
  236. "../ode/src/collision_trimesh_ccylinder.cpp",
  237. "../ode/src/collision_cylinder_trimesh.cpp",
  238. "../ode/src/collision_trimesh_distance.cpp",
  239. "../ode/src/collision_trimesh_ray.cpp",
  240. "../ode/src/collision_trimesh_sphere.cpp",
  241. "../ode/src/collision_trimesh_trimesh.cpp",
  242. "../ode/src/collision_trimesh_plane.cpp"
  243. }
  244. configuration { "not no-trimesh", "with-gimpact or all-collis-libs" }
  245. files { "../GIMPACT/**.h", "../GIMPACT/**.cpp" }
  246. configuration { "not no-trimesh", "not with-gimpact" }
  247. files { "../OPCODE/**.h", "../OPCODE/**.cpp" }
  248. configuration { "with-ou" }
  249. files { "../ou/**.h", "../ou/**.cpp" }
  250. defines { "_OU_NAMESPACE=odeou" }
  251. configuration { "with-libccd" }
  252. files { "../libccd/src/ccd/*.h", "../libccd/src/*.c" }
  253. defines { "dLIBCCD_ENABLED", "dLIBCCD_CYL_CYL" }
  254. configuration { "not with-libccd" }
  255. excludes { "../ode/src/collision_libccd.cpp", "../ode/src/collision_libccd.h" }
  256. configuration { "windows" }
  257. links { "user32" }
  258. configuration { "only-static or *Lib" }
  259. kind "StaticLib"
  260. defines "ODE_LIB"
  261. configuration { "only-shared or *DLL" }
  262. kind "SharedLib"
  263. defines "ODE_DLL"
  264. configuration { "Debug" }
  265. targetname "oded"
  266. configuration { "Release" }
  267. targetname "ode"
  268. configuration { "DebugSingle*" }
  269. targetname "ode_singled"
  270. configuration { "ReleaseSingle*" }
  271. targetname "ode_single"
  272. configuration { "DebugDouble*" }
  273. targetname "ode_doubled"
  274. configuration { "ReleaseDouble*" }
  275. targetname "ode_double"
  276. ----------------------------------------------------------------------
  277. -- Write a custom <config.h> to build, based on the supplied flags
  278. ----------------------------------------------------------------------
  279. if _ACTION and _ACTION ~= "clean" then
  280. io.input("config-default.h")
  281. local text = io.read("*a")
  282. if _OPTIONS["no-trimesh"] then
  283. text = string.gsub(text, "#define dTRIMESH_ENABLED 1", "/* #define dTRIMESH_ENABLED 1 */")
  284. text = string.gsub(text, "#define dTRIMESH_OPCODE 1", "/* #define dTRIMESH_OPCODE 1 */")
  285. elseif (_OPTIONS["with-gimpact"]) then
  286. text = string.gsub(text, "#define dTRIMESH_OPCODE 1", "#define dTRIMESH_GIMPACT 1")
  287. end
  288. if _OPTIONS["with-ou"] then
  289. text = string.gsub(text, "/%* #define dOU_ENABLED 1 %*/", "#define dOU_ENABLED 1")
  290. text = string.gsub(text, "/%* #define dATOMICS_ENABLED 1 %*/", "#define dATOMICS_ENABLED 1")
  291. text = string.gsub(text, "/%* #define dTLS_ENABLED 1 %*/", "#define dTLS_ENABLED 1")
  292. end
  293. if _OPTIONS["16bit-indices"] then
  294. text = string.gsub(text, "#define dTRIMESH_16BIT_INDICES 0", "#define dTRIMESH_16BIT_INDICES 1")
  295. end
  296. if _OPTIONS["old-trimesh"] then
  297. text = string.gsub(text, "#define dTRIMESH_OPCODE_USE_OLD_TRIMESH_TRIMESH_COLLIDER 0", "#define dTRIMESH_OPCODE_USE_OLD_TRIMESH_TRIMESH_COLLIDER 1")
  298. end
  299. io.output("../ode/src/config.h")
  300. io.write(text)
  301. io.close()
  302. end
  303. ----------------------------------------------------------------------
  304. -- The DrawStuff library project
  305. ----------------------------------------------------------------------
  306. if _OPTIONS["with-demos"] then
  307. project "drawstuff"
  308. location ( _OPTIONS["to"] or _ACTION )
  309. files {
  310. "../include/drawstuff/*.h",
  311. "../drawstuff/src/internal.h",
  312. "../drawstuff/src/drawstuff.cpp"
  313. }
  314. configuration { "Debug*" }
  315. targetname "drawstuffd"
  316. configuration { "only-static or *Lib" }
  317. kind "StaticLib"
  318. defines { "DS_LIB" }
  319. configuration { "only-shared or *DLL" }
  320. kind "SharedLib"
  321. defines { "DS_DLL", "USRDLL" }
  322. configuration { "Windows" }
  323. files { "../drawstuff/src/resource.h", "../drawstuff/src/resources.rc", "../drawstuff/src/windows.cpp" }
  324. links { "user32", "opengl32", "glu32", "winmm", "gdi32" }
  325. configuration { "MacOSX" }
  326. defines { "HAVE_APPLE_OPENGL_FRAMEWORK" }
  327. files { "../drawstuff/src/osx.cpp" }
  328. linkoptions { "-framework Carbon -framework OpenGL -framework AGL" }
  329. configuration { "not Windows", "not MacOSX" }
  330. files { "../drawstuff/src/x11.cpp" }
  331. links { "X11", "GL", "GLU" }
  332. end
  333. ----------------------------------------------------------------------
  334. -- The automated test application
  335. ----------------------------------------------------------------------
  336. if _OPTIONS["with-tests"] then
  337. project "tests"
  338. kind "ConsoleApp"
  339. location ( _OPTIONS["to"] or _ACTION )
  340. includedirs {
  341. "../tests/UnitTest++/src"
  342. }
  343. files {
  344. "../tests/*.cpp",
  345. "../tests/joints/*.cpp",
  346. "../tests/UnitTest++/src/*"
  347. }
  348. links { "ode" }
  349. configuration { "Windows" }
  350. files { "../tests/UnitTest++/src/Win32/*" }
  351. configuration { "not Windows" }
  352. files { "../tests/UnitTest++/src/Posix/*" }
  353. -- add post-build step to automatically run test executable
  354. local path_to_lib = path.getrelative(location(), "../lib")
  355. local command = path.translate(path.join(path_to_lib, "%s/tests"))
  356. for _, name in ipairs(configurations()) do
  357. configuration { name }
  358. postbuildcommands { command:format(name) }
  359. end
  360. end