Changed: HAVE_PTHREAD_ATTR_SETINHERITSCHED and HAVE_PTHREAD_ATTR_SETSTACKLAZY defines...
[ode.git] / build / premake4.lua
blob8ee3e9c61b32c4e14ab011236b850c36fb495bb3
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 defines { "HAVE_PTHREAD_ATTR_SETINHERITSCHED=1", "HAVE_PTHREAD_ATTR_SETSTACKLAZY=1" }
351 else
352 buildoptions { "-pthread" }
353 linkoptions { "-pthread" }
359 configuration { "no-dif" }
360 excludes { "../ode/src/export-dif.cpp" }
362 configuration { "no-trimesh" }
363 excludes {
364 "../ode/src/collision_trimesh_colliders.h",
365 "../ode/src/gimpact_contact_export_helper.cpp",
366 "../ode/src/gimpact_contact_export_helper.h",
367 "../ode/src/gimpact_gim_contact_accessor.h",
368 "../ode/src/gimpact_plane_contact_accessor.h",
369 "../ode/src/collision_trimesh_internal.cpp",
370 "../ode/src/collision_trimesh_opcode.cpp",
371 "../ode/src/collision_trimesh_gimpact.cpp",
372 "../ode/src/collision_trimesh_box.cpp",
373 "../ode/src/collision_trimesh_ccylinder.cpp",
374 "../ode/src/collision_cylinder_trimesh.cpp",
375 "../ode/src/collision_trimesh_ray.cpp",
376 "../ode/src/collision_trimesh_sphere.cpp",
377 "../ode/src/collision_trimesh_trimesh.cpp",
378 "../ode/src/collision_trimesh_trimesh_old.cpp",
379 "../ode/src/collision_trimesh_plane.cpp",
380 "../ode/src/collision_convex_trimesh.cpp"
383 configuration { "not no-trimesh", "with-gimpact or all-collis-libs" }
384 files { "../GIMPACT/**.h", "../GIMPACT/**.cpp" }
386 configuration { "not no-trimesh", "not with-gimpact" }
387 files { "../OPCODE/**.h", "../OPCODE/**.cpp" }
389 configuration { "not no-trimesh", "not all-collis-libs", "with-gimpact" }
390 excludes {
391 "../ode/src/collision_trimesh_opcode.cpp"
394 configuration { "not no-trimesh", "not all-collis-libs", "not with-gimpact" }
395 excludes {
396 "../ode/src/gimpact_contact_export_helper.cpp",
397 "../ode/src/gimpact_contact_export_helper.h",
398 "../ode/src/gimpact_gim_contact_accessor.h",
399 "../ode/src/gimpact_plane_contact_accessor.h",
400 "../ode/src/collision_trimesh_gimpact.cpp"
403 configuration { "with-libccd" }
404 files { "../libccd/src/custom/ccdcustom/*.h", "../libccd/src/ccd/*.h", "../libccd/src/*.c" }
405 defines { "dLIBCCD_ENABLED", "dLIBCCD_INTERNAL",
406 "dLIBCCD_BOX_CYL", "dLIBCCD_CYL_CYL", "dLIBCCD_CAP_CYL", "dLIBCCD_CONVEX_BOX",
407 "dLIBCCD_CONVEX_CAP", "dLIBCCD_CONVEX_CYL", "dLIBCCD_CONVEX_SPHERE", "dLIBCCD_CONVEX_CONVEX" }
409 configuration { "not with-libccd" }
410 excludes { "../ode/src/collision_libccd.cpp", "../ode/src/collision_libccd.h" }
412 configuration { "windows" }
413 links { "user32" }
415 configuration { "only-static or *Lib" }
416 kind "StaticLib"
417 defines "ODE_LIB"
419 configuration { "only-shared or *DLL" }
420 kind "SharedLib"
421 defines "ODE_DLL"
423 configuration { "*DLL" }
424 defines "_DLL"
426 configuration { "Debug" }
427 targetname "oded"
429 configuration { "Release" }
430 targetname "ode"
432 configuration { "DebugSingle*" }
433 targetname "ode_singled"
435 configuration { "ReleaseSingle*" }
436 targetname "ode_single"
438 configuration { "DebugDouble*" }
439 targetname "ode_doubled"
441 configuration { "ReleaseDouble*" }
442 targetname "ode_double"
445 ----------------------------------------------------------------------
446 -- Write a custom <config.h> to build, based on the supplied flags
447 ----------------------------------------------------------------------
449 if _ACTION and _ACTION ~= "clean" then
450 local infile = io.open("config-default.h", "r")
451 local text = infile:read("*a")
453 if _OPTIONS["no-trimesh"] then
454 text = string.gsub(text, "#define dTRIMESH_ENABLED 1", "/* #define dTRIMESH_ENABLED 1 */")
455 text = string.gsub(text, "#define dTRIMESH_OPCODE 1", "/* #define dTRIMESH_OPCODE 1 */")
456 elseif (_OPTIONS["with-gimpact"]) then
457 text = string.gsub(text, "#define dTRIMESH_OPCODE 1", "#define dTRIMESH_GIMPACT 1")
460 text = string.gsub(text, "/%* #define dOU_ENABLED 1 %*/", "#define dOU_ENABLED 1")
461 if _OPTIONS["with-ou"] or not _OPTIONS["no-threading-intf"] then
462 text = string.gsub(text, "/%* #define dATOMICS_ENABLED 1 %*/", "#define dATOMICS_ENABLED 1")
465 if _OPTIONS["with-ou"] then
466 text = string.gsub(text, "/%* #define dTLS_ENABLED 1 %*/", "#define dTLS_ENABLED 1")
469 if _OPTIONS["no-threading-intf"] then
470 text = string.gsub(text, "/%* #define dTHREADING_INTF_DISABLED 1 %*/", "#define dTHREADING_INTF_DISABLED 1")
471 elseif not _OPTIONS["no-builtin-threading-impl"] then
472 text = string.gsub(text, "/%* #define dBUILTIN_THREADING_IMPL_ENABLED 1 %*/", "#define dBUILTIN_THREADING_IMPL_ENABLED 1")
475 if _OPTIONS["16bit-indices"] then
476 text = string.gsub(text, "#define dTRIMESH_16BIT_INDICES 0", "#define dTRIMESH_16BIT_INDICES 1")
479 if _OPTIONS["old-trimesh"] then
480 text = string.gsub(text, "#define dTRIMESH_OPCODE_USE_OLD_TRIMESH_TRIMESH_COLLIDER 0", "#define dTRIMESH_OPCODE_USE_OLD_TRIMESH_TRIMESH_COLLIDER 1")
483 local outfile = io.open("../ode/src/config.h", "w")
484 outfile:write(text)
485 outfile:close()
488 ----------------------------
489 -- Write precision headers
490 ----------------------------
491 if _ACTION and _ACTION ~= "clean" then
492 function generateheader(headerfile, placeholder, precstr)
493 local outfile = io.open(headerfile, "w")
494 for i in io.lines(headerfile .. ".in")
496 local j,_ = string.gsub(i, placeholder, precstr)
497 --print("writing " .. j .. " into " .. headerfile)
498 outfile:write(j .. "\n")
500 outfile:close()
503 function generate(precstr)
504 generateheader("../include/ode/precision.h", "@ODE_PRECISION@", "d" .. precstr)
505 generateheader("../libccd/src/ccd/precision.h", "@CCD_PRECISION@", "CCD_" .. precstr)
508 if _OPTIONS["only-single"] then
509 generate("SINGLE")
510 elseif _OPTIONS["only-double"] then
511 generate("DOUBLE")
512 else
513 generate("UNDEFINEDPRECISION")
516 generateheader("../include/ode/version.h", "@ODE_VERSION@", ode_version)
521 ----------------------------------------------------------------------
522 -- The DrawStuff library project
523 ----------------------------------------------------------------------
525 if _OPTIONS["with-demos"] then
527 project "drawstuff"
529 location ( _OPTIONS["to"] or _ACTION )
531 files {
532 "../include/drawstuff/*.h",
533 "../drawstuff/src/internal.h",
534 "../drawstuff/src/drawstuff.cpp"
537 configuration { "Debug*" }
538 targetname "drawstuffd"
540 configuration { "only-static or *Lib" }
541 kind "StaticLib"
542 defines { "DS_LIB" }
544 configuration { "only-shared or *DLL" }
545 kind "SharedLib"
546 defines { "DS_DLL", "USRDLL" }
548 configuration { "Windows" }
549 files { "../drawstuff/src/resource.h", "../drawstuff/src/resources.rc", "../drawstuff/src/windows.cpp" }
550 links { "user32", "opengl32", "glu32", "winmm", "gdi32" }
552 configuration { "MacOSX" }
553 defines { "HAVE_APPLE_OPENGL_FRAMEWORK" }
554 files { "../drawstuff/src/osx.cpp" }
555 linkoptions { "-framework Carbon -framework OpenGL -framework AGL" }
557 configuration { "not Windows", "not MacOSX" }
558 files { "../drawstuff/src/x11.cpp" }
559 links { "X11", "GL", "GLU" }
564 ----------------------------------------------------------------------
565 -- The automated test application
566 ----------------------------------------------------------------------
569 if _OPTIONS["with-tests"] then
571 project "tests"
573 kind "ConsoleApp"
574 location ( _OPTIONS["to"] or _ACTION )
576 includedirs {
577 "../ou/include",
578 "../tests/UnitTest++/src"
581 files {
582 "../tests/*.cpp",
583 "../tests/joints/*.cpp",
584 "../tests/UnitTest++/src/*"
587 links { "ode" }
589 configuration { "Windows" }
590 files { "../tests/UnitTest++/src/Win32/*" }
592 configuration { "not Windows" }
593 files { "../tests/UnitTest++/src/Posix/*" }
595 -- add post-build step to automatically run test executable
596 local path_to_lib = path.getrelative(location(), "../lib")
597 local command = path.translate(path.join(path_to_lib, "%s/tests"))
599 for _, name in ipairs(configurations()) do
600 configuration { name }
601 postbuildcommands { command:format(name) }