premake4.lua 16 KB

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