Changed: x86 targets have been switched to SSE2 code by default
[ode.git] / build / premake4.lua
blob9e8dcd3c41ff3bd136661cbb1cb9c05965178fa0
1 ----------------------------------------------------------------------
2 -- Premake4 configuration script for OpenDE
3 -- Contributed by Jason Perkins (starkos@industriousone.com)
4 -- For more information on Premake: http://industriousone.com/premake
5 ----------------------------------------------------------------------
7 ode_version = "0.16"
9 ----------------------------------------------------------------------
10 -- Demo list: add/remove demos from here and the rest of the build
11 -- should just work.
12 ----------------------------------------------------------------------
14 local demos = {
15 "boxstack",
16 "buggy",
17 "cards",
18 "chain1",
19 "chain2",
20 "collision",
21 "convex",
22 "crash",
23 "cylvssphere",
24 "dball",
25 "dhinge",
26 "feedback",
27 "friction",
28 "gyroscopic",
29 "gyro2",
30 "heightfield",
31 "hinge",
32 "I",
33 "jointPR",
34 "jointPU",
35 "joints",
36 "kinematic",
37 "motion",
38 "motor",
39 "ode",
40 "piston",
41 "plane2d",
42 "rfriction",
43 "slider",
44 "space",
45 "space_stress",
46 "step",
47 "transmission"
50 local trimesh_demos = {
51 "basket",
52 "cyl",
53 "moving_convex",
54 "moving_trimesh",
55 "tracks",
56 "trimesh"
59 if not _OPTIONS["no-trimesh"] then
60 demos = table.join(demos, trimesh_demos)
61 end
65 ----------------------------------------------------------------------
66 -- Configuration options
67 ----------------------------------------------------------------------
69 newoption {
70 trigger = "with-demos",
71 description = "Builds the demo applications and DrawStuff library"
74 newoption {
75 trigger = "with-tests",
76 description = "Builds the unit test application"
79 newoption {
80 trigger = "with-gimpact",
81 description = "Use GIMPACT for trimesh collisions (experimental)"
84 newoption {
85 trigger = "all-collis-libs",
86 description = "Include sources of all collision libraries into the project"
89 newoption {
90 trigger = "with-libccd",
91 description = "Uses libccd for handling some collision tests absent in ODE."
94 newoption {
95 trigger = "no-dif",
96 description = "Exclude DIF (Dynamics Interchange Format) exports"
99 newoption {
100 trigger = "no-trimesh",
101 description = "Exclude trimesh collision geometry"
104 newoption {
105 trigger = "with-ou",
106 description = "Use TLS for global caches (allows threaded collision checks for separated spaces)"
109 newoption {
110 trigger = "no-builtin-threading-impl",
111 description = "Disable built-in multithreaded threading implementation"
114 newoption {
115 trigger = "no-threading-intf",
116 description = "Disable threading interface support (external implementations cannot be assigned)"
119 newoption {
120 trigger = "16bit-indices",
121 description = "Use 16-bit indices for trimeshes (default is 32-bit)"
124 newoption {
125 trigger = "old-trimesh",
126 description = "Use old OPCODE trimesh-trimesh collider"
129 newoption {
130 trigger = "to",
131 value = "path",
132 description = "Set the output location for the generated project files"
135 newoption {
136 trigger = "only-shared",
137 description = "Only build shared (DLL) version of the library"
140 newoption {
141 trigger = "only-static",
142 description = "Only build static versions of the library"
145 newoption {
146 trigger = "only-single",
147 description = "Only use single-precision math"
150 newoption {
151 trigger = "only-double",
152 description = "Only use double-precision math"
155 newoption {
156 trigger = "no-sse2",
157 description = "Disable SSE2 use for x86 targets in favor to FPU"
160 -- always clean all of the optional components and toolsets
161 if _ACTION == "clean" then
162 _OPTIONS["with-demos"] = ""
163 _OPTIONS["with-tests"] = ""
164 for action in premake.action.each() do
165 os.rmdir(action.trigger)
167 os.remove("../ode/src/config.h")
168 os.remove("../include/ode/version.h")
169 os.remove("../include/ode/precision.h")
170 os.remove("../libccd/src/ccd/precision.h")
173 -- special validation for Xcode
174 if _ACTION == "xcode3" and (not _OPTIONS["only-static"] and not _OPTIONS["only-shared"]) then
175 error(
176 "Xcode does not support different library types in a single project.\n" ..
177 "Please use one of the flags: --only-static or --only-shared", 0)
180 -- build the list of configurations, based on the flags. Ends up
181 -- with configurations like "Debug", "DebugSingle" or "DebugSingleShared"
182 local configs = { "Debug", "Release" }
184 local function addconfigs(...)
185 local newconfigs = { }
186 for _, root in ipairs(configs) do
187 for _, suffix in ipairs(arg) do
188 table.insert(newconfigs, root .. suffix)
191 configs = newconfigs
195 if not _OPTIONS["only-single"] and not _OPTIONS["only-double"] then
196 addconfigs("Single", "Double")
199 if not _OPTIONS["only-shared"] and not _OPTIONS["only-static"] then
200 addconfigs("DLL", "Lib")
204 ----------------------------------------------------------------------
205 -- The solution, and solution-wide settings
206 ----------------------------------------------------------------------
208 solution "ode"
210 language "C++"
211 uuid "4DA77C12-15E5-497B-B1BB-5100D5161E15"
212 location ( _OPTIONS["to"] or _ACTION )
214 includedirs {
215 "../include",
216 "../ode/src"
219 defines { "_MT" }
221 -- apply the configuration list built above
222 configurations (configs)
224 configuration { "Debug*" }
225 defines { "_DEBUG" }
226 flags { "Symbols" }
228 configuration { "Release*" }
229 defines { "NDEBUG", "dNODEBUG" }
230 flags { "OptimizeSpeed", "NoFramePointer" }
232 if not _OPTIONS["no-sse2"] then
233 flags { "EnableSSE2" }
236 configuration { "*Single*" }
237 defines { "dIDESINGLE", "CCD_IDESINGLE" }
239 configuration { "*Double*" }
240 defines { "dIDEDOUBLE", "CCD_IDEDOUBLE" }
242 configuration { "Windows" }
243 defines { "WIN32" }
245 configuration { "MacOSX" }
246 linkoptions { "-framework Carbon" }
248 -- give each configuration a unique output directory
249 for _, name in ipairs(configurations()) do
250 configuration { name }
251 targetdir ( "../lib/" .. name )
254 -- disable Visual Studio security warnings
255 configuration { "vs*" }
256 defines { "_CRT_SECURE_NO_DEPRECATE", "_SCL_SECURE_NO_WARNINGS" }
258 -- enable M_* macros from math.h
259 configuration { "vs*" }
260 defines { "_USE_MATH_DEFINES" }
262 -- don't remember why we had to do this
263 configuration { "vs2002 or vs2003", "*Lib" }
264 flags { "StaticRuntime" }
268 ----------------------------------------------------------------------
269 -- The demo projects, automated from list above. These go first so
270 -- they will be selected as the active project automatically in IDEs
271 ----------------------------------------------------------------------
273 if _OPTIONS["with-demos"] then
274 for _, name in ipairs(demos) do
276 project ( "demo_" .. name )
278 if name ~= "ode" then
279 kind "WindowedApp"
280 else
281 kind "ConsoleApp"
284 location ( _OPTIONS["to"] or _ACTION )
285 files { "../ode/demo/demo_" .. name .. ".*" }
286 links { "ode", "drawstuff" }
288 configuration { "Windows" }
289 files { "../drawstuff/src/resources.rc" }
290 links { "user32", "winmm", "gdi32", "opengl32", "glu32" }
292 configuration { "MacOSX" }
293 linkoptions { "-framework Carbon -framework OpenGL -framework AGL" }
295 configuration { "not Windows", "not MacOSX" }
296 links { "GL", "GLU" }
303 ----------------------------------------------------------------------
304 -- The ODE library project
305 ----------------------------------------------------------------------
307 project "ode"
309 -- kind "StaticLib"
310 location ( _OPTIONS["to"] or _ACTION )
312 includedirs {
313 "../ode/src/joints",
314 "../OPCODE",
315 "../GIMPACT/include",
316 "../libccd/src/custom",
317 "../libccd/src"
320 files {
321 "../include/ode/*.h",
322 "../ode/src/joints/*.h",
323 "../ode/src/joints/*.cpp",
324 "../ode/src/*.h",
325 "../ode/src/*.c",
326 "../ode/src/*.cpp",
329 excludes {
330 "../ode/src/collision_std.cpp",
333 includedirs { "../ou/include" }
334 files { "../ou/include/**.h", "../ou/src/**.h", "../ou/src/**.cpp" }
335 defines { "_OU_NAMESPACE=odeou" }
337 if _OPTIONS["with-ou"] then
338 defines { "_OU_FEATURE_SET=_OU_FEATURE_SET_TLS" }
339 elseif not _OPTIONS["no-threading-intf"] then
340 defines { "_OU_FEATURE_SET=_OU_FEATURE_SET_ATOMICS" }
341 else
342 defines { "_OU_FEATURE_SET=_OU_FEATURE_SET_BASICS" }
345 if _OPTIONS["with-ou"] or not _OPTIONS["no-threading-intf"] then
346 if _ACTION == "gmake" then
347 if os.get() == "windows" then
348 buildoptions { "-mthreads" }
349 linkoptions { "-mthreads" }
350 else
351 buildoptions { "-pthread" }
352 linkoptions { "-pthread" }
358 configuration { "no-dif" }
359 excludes { "../ode/src/export-dif.cpp" }
361 configuration { "no-trimesh" }
362 excludes {
363 "../ode/src/collision_trimesh_colliders.h",
364 "../ode/src/gimpact_contact_export_helper.cpp",
365 "../ode/src/gimpact_contact_export_helper.h",
366 "../ode/src/gimpact_gim_contact_accessor.h",
367 "../ode/src/gimpact_plane_contact_accessor.h",
368 "../ode/src/collision_trimesh_internal.cpp",
369 "../ode/src/collision_trimesh_opcode.cpp",
370 "../ode/src/collision_trimesh_gimpact.cpp",
371 "../ode/src/collision_trimesh_box.cpp",
372 "../ode/src/collision_trimesh_ccylinder.cpp",
373 "../ode/src/collision_cylinder_trimesh.cpp",
374 "../ode/src/collision_trimesh_ray.cpp",
375 "../ode/src/collision_trimesh_sphere.cpp",
376 "../ode/src/collision_trimesh_trimesh.cpp",
377 "../ode/src/collision_trimesh_trimesh_old.cpp",
378 "../ode/src/collision_trimesh_plane.cpp",
379 "../ode/src/collision_convex_trimesh.cpp"
382 configuration { "not no-trimesh", "with-gimpact or all-collis-libs" }
383 files { "../GIMPACT/**.h", "../GIMPACT/**.cpp" }
385 configuration { "not no-trimesh", "not with-gimpact" }
386 files { "../OPCODE/**.h", "../OPCODE/**.cpp" }
388 configuration { "not no-trimesh", "not all-collis-libs", "with-gimpact" }
389 excludes {
390 "../ode/src/collision_trimesh_opcode.cpp"
393 configuration { "not no-trimesh", "not all-collis-libs", "not with-gimpact" }
394 excludes {
395 "../ode/src/gimpact_contact_export_helper.cpp",
396 "../ode/src/gimpact_contact_export_helper.h",
397 "../ode/src/gimpact_gim_contact_accessor.h",
398 "../ode/src/gimpact_plane_contact_accessor.h",
399 "../ode/src/collision_trimesh_gimpact.cpp"
402 configuration { "with-libccd" }
403 files { "../libccd/src/custom/ccdcustom/*.h", "../libccd/src/ccd/*.h", "../libccd/src/*.c" }
404 defines { "dLIBCCD_ENABLED", "dLIBCCD_INTERNAL",
405 "dLIBCCD_BOX_CYL", "dLIBCCD_CYL_CYL", "dLIBCCD_CAP_CYL", "dLIBCCD_CONVEX_BOX",
406 "dLIBCCD_CONVEX_CAP", "dLIBCCD_CONVEX_CYL", "dLIBCCD_CONVEX_SPHERE", "dLIBCCD_CONVEX_CONVEX" }
408 configuration { "not with-libccd" }
409 excludes { "../ode/src/collision_libccd.cpp", "../ode/src/collision_libccd.h" }
411 configuration { "windows" }
412 links { "user32" }
414 configuration { "only-static or *Lib" }
415 kind "StaticLib"
416 defines "ODE_LIB"
418 configuration { "only-shared or *DLL" }
419 kind "SharedLib"
420 defines "ODE_DLL"
422 configuration { "*DLL" }
423 defines "_DLL"
425 configuration { "Debug" }
426 targetname "oded"
428 configuration { "Release" }
429 targetname "ode"
431 configuration { "DebugSingle*" }
432 targetname "ode_singled"
434 configuration { "ReleaseSingle*" }
435 targetname "ode_single"
437 configuration { "DebugDouble*" }
438 targetname "ode_doubled"
440 configuration { "ReleaseDouble*" }
441 targetname "ode_double"
444 ----------------------------------------------------------------------
445 -- Write a custom <config.h> to build, based on the supplied flags
446 ----------------------------------------------------------------------
448 if _ACTION and _ACTION ~= "clean" then
449 local infile = io.open("config-default.h", "r")
450 local text = infile:read("*a")
452 if _OPTIONS["no-trimesh"] then
453 text = string.gsub(text, "#define dTRIMESH_ENABLED 1", "/* #define dTRIMESH_ENABLED 1 */")
454 text = string.gsub(text, "#define dTRIMESH_OPCODE 1", "/* #define dTRIMESH_OPCODE 1 */")
455 elseif (_OPTIONS["with-gimpact"]) then
456 text = string.gsub(text, "#define dTRIMESH_OPCODE 1", "#define dTRIMESH_GIMPACT 1")
459 text = string.gsub(text, "/%* #define dOU_ENABLED 1 %*/", "#define dOU_ENABLED 1")
460 if _OPTIONS["with-ou"] or not _OPTIONS["no-threading-intf"] then
461 text = string.gsub(text, "/%* #define dATOMICS_ENABLED 1 %*/", "#define dATOMICS_ENABLED 1")
464 if _OPTIONS["with-ou"] then
465 text = string.gsub(text, "/%* #define dTLS_ENABLED 1 %*/", "#define dTLS_ENABLED 1")
468 if _OPTIONS["no-threading-intf"] then
469 text = string.gsub(text, "/%* #define dTHREADING_INTF_DISABLED 1 %*/", "#define dTHREADING_INTF_DISABLED 1")
470 elseif not _OPTIONS["no-builtin-threading-impl"] then
471 text = string.gsub(text, "/%* #define dBUILTIN_THREADING_IMPL_ENABLED 1 %*/", "#define dBUILTIN_THREADING_IMPL_ENABLED 1")
474 if _OPTIONS["16bit-indices"] then
475 text = string.gsub(text, "#define dTRIMESH_16BIT_INDICES 0", "#define dTRIMESH_16BIT_INDICES 1")
478 if _OPTIONS["old-trimesh"] then
479 text = string.gsub(text, "#define dTRIMESH_OPCODE_USE_OLD_TRIMESH_TRIMESH_COLLIDER 0", "#define dTRIMESH_OPCODE_USE_OLD_TRIMESH_TRIMESH_COLLIDER 1")
482 local outfile = io.open("../ode/src/config.h", "w")
483 outfile:write(text)
484 outfile:close()
487 ----------------------------
488 -- Write precision headers
489 ----------------------------
490 if _ACTION and _ACTION ~= "clean" then
491 function generateheader(headerfile, placeholder, precstr)
492 local outfile = io.open(headerfile, "w")
493 for i in io.lines(headerfile .. ".in")
495 local j,_ = string.gsub(i, placeholder, precstr)
496 --print("writing " .. j .. " into " .. headerfile)
497 outfile:write(j .. "\n")
499 outfile:close()
502 function generate(precstr)
503 generateheader("../include/ode/precision.h", "@ODE_PRECISION@", "d" .. precstr)
504 generateheader("../libccd/src/ccd/precision.h", "@CCD_PRECISION@", "CCD_" .. precstr)
507 if _OPTIONS["only-single"] then
508 generate("SINGLE")
509 elseif _OPTIONS["only-double"] then
510 generate("DOUBLE")
511 else
512 generate("UNDEFINEDPRECISION")
515 generateheader("../include/ode/version.h", "@ODE_VERSION@", ode_version)
520 ----------------------------------------------------------------------
521 -- The DrawStuff library project
522 ----------------------------------------------------------------------
524 if _OPTIONS["with-demos"] then
526 project "drawstuff"
528 location ( _OPTIONS["to"] or _ACTION )
530 files {
531 "../include/drawstuff/*.h",
532 "../drawstuff/src/internal.h",
533 "../drawstuff/src/drawstuff.cpp"
536 configuration { "Debug*" }
537 targetname "drawstuffd"
539 configuration { "only-static or *Lib" }
540 kind "StaticLib"
541 defines { "DS_LIB" }
543 configuration { "only-shared or *DLL" }
544 kind "SharedLib"
545 defines { "DS_DLL", "USRDLL" }
547 configuration { "Windows" }
548 files { "../drawstuff/src/resource.h", "../drawstuff/src/resources.rc", "../drawstuff/src/windows.cpp" }
549 links { "user32", "opengl32", "glu32", "winmm", "gdi32" }
551 configuration { "MacOSX" }
552 defines { "HAVE_APPLE_OPENGL_FRAMEWORK" }
553 files { "../drawstuff/src/osx.cpp" }
554 linkoptions { "-framework Carbon -framework OpenGL -framework AGL" }
556 configuration { "not Windows", "not MacOSX" }
557 files { "../drawstuff/src/x11.cpp" }
558 links { "X11", "GL", "GLU" }
563 ----------------------------------------------------------------------
564 -- The automated test application
565 ----------------------------------------------------------------------
568 if _OPTIONS["with-tests"] then
570 project "tests"
572 kind "ConsoleApp"
573 location ( _OPTIONS["to"] or _ACTION )
575 includedirs {
576 "../tests/UnitTest++/src"
579 files {
580 "../tests/*.cpp",
581 "../tests/joints/*.cpp",
582 "../tests/UnitTest++/src/*"
585 links { "ode" }
587 configuration { "Windows" }
588 files { "../tests/UnitTest++/src/Win32/*" }
590 configuration { "not Windows" }
591 files { "../tests/UnitTest++/src/Posix/*" }
593 -- add post-build step to automatically run test executable
594 local path_to_lib = path.getrelative(location(), "../lib")
595 local command = path.translate(path.join(path_to_lib, "%s/tests"))
597 for _, name in ipairs(configurations()) do
598 configuration { name }
599 postbuildcommands { command:format(name) }