test_gmake_cpp.lua 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. --
  2. -- tests/test_gmake_cpp.lua
  3. -- Automated test suite for GNU Make C/C++ project generation.
  4. -- Copyright (c) 2009 Jason Perkins and the Premake project
  5. --
  6. T.gmake_cpp = { }
  7. --
  8. -- Configure a solution for testing
  9. --
  10. local sln, prj
  11. function T.gmake_cpp.setup()
  12. _ACTION = "gmake"
  13. _OPTIONS.os = "linux"
  14. sln = solution "MySolution"
  15. configurations { "Debug", "Release" }
  16. platforms { "native" }
  17. prj = project "MyProject"
  18. language "C++"
  19. kind "ConsoleApp"
  20. end
  21. local function prepare()
  22. premake.bake.buildconfigs()
  23. end
  24. --
  25. -- Test the header
  26. --
  27. function T.gmake_cpp.BasicHeader()
  28. prepare()
  29. premake.gmake_cpp_header(prj, premake.gcc, sln.platforms)
  30. test.capture [[
  31. # GNU Make project makefile autogenerated by Premake
  32. ifndef config
  33. config=debug
  34. endif
  35. ifndef verbose
  36. SILENT = @
  37. endif
  38. CC = gcc
  39. CXX = g++
  40. AR = ar
  41. ifndef RESCOMP
  42. ifdef WINDRES
  43. RESCOMP = $(WINDRES)
  44. else
  45. RESCOMP = windres
  46. endif
  47. endif
  48. ]]
  49. end
  50. --
  51. -- Test configuration blocks
  52. --
  53. function T.gmake_cpp.BasicCfgBlock()
  54. prepare()
  55. local cfg = premake.getconfig(prj, "Debug")
  56. premake.gmake_cpp_config(cfg, premake.gcc)
  57. test.capture [[
  58. ifeq ($(config),debug)
  59. OBJDIR = obj/Debug
  60. TARGETDIR = .
  61. TARGET = $(TARGETDIR)/MyProject
  62. DEFINES +=
  63. INCLUDES +=
  64. ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES)
  65. ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH)
  66. ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS)
  67. ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)
  68. ALL_LDFLAGS += $(LDFLAGS) -s
  69. LDDEPS +=
  70. LIBS += $(LDDEPS)
  71. LINKCMD = $(CXX) -o $(TARGET) $(OBJECTS) $(RESOURCES) $(ARCH) $(ALL_LDFLAGS) $(LIBS)
  72. define PREBUILDCMDS
  73. endef
  74. define PRELINKCMDS
  75. endef
  76. define POSTBUILDCMDS
  77. endef
  78. endif
  79. ]]
  80. end
  81. function T.gmake_cpp.BasicCfgBlockWithPlatformCc()
  82. platforms { "ps3" }
  83. prepare()
  84. local cfg = premake.getconfig(prj, "Debug", "PS3")
  85. premake.gmake_cpp_config(cfg, premake.gcc)
  86. test.capture [[
  87. ifeq ($(config),debugps3)
  88. CC = ppu-lv2-g++
  89. CXX = ppu-lv2-g++
  90. AR = ppu-lv2-ar
  91. OBJDIR = obj/PS3/Debug
  92. TARGETDIR = .
  93. TARGET = $(TARGETDIR)/MyProject.elf
  94. DEFINES +=
  95. INCLUDES +=
  96. ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES)
  97. ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH)
  98. ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS)
  99. ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)
  100. ALL_LDFLAGS += $(LDFLAGS) -s
  101. LDDEPS +=
  102. LIBS += $(LDDEPS)
  103. LINKCMD = $(CXX) -o $(TARGET) $(OBJECTS) $(RESOURCES) $(ARCH) $(ALL_LDFLAGS) $(LIBS)
  104. define PREBUILDCMDS
  105. endef
  106. define PRELINKCMDS
  107. endef
  108. define POSTBUILDCMDS
  109. endef
  110. endif
  111. ]]
  112. end
  113. function T.gmake_cpp.PlatformSpecificBlock()
  114. platforms { "x64" }
  115. prepare()
  116. local cfg = premake.getconfig(prj, "Debug", "x64")
  117. premake.gmake_cpp_config(cfg, premake.gcc)
  118. test.capture [[
  119. ifeq ($(config),debug64)
  120. OBJDIR = obj/x64/Debug
  121. TARGETDIR = .
  122. TARGET = $(TARGETDIR)/MyProject
  123. DEFINES +=
  124. INCLUDES +=
  125. ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES)
  126. ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -m64
  127. ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS)
  128. ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)
  129. ALL_LDFLAGS += $(LDFLAGS) -s -m64 -L/usr/lib64
  130. LDDEPS +=
  131. LIBS += $(LDDEPS)
  132. LINKCMD = $(CXX) -o $(TARGET) $(OBJECTS) $(RESOURCES) $(ARCH) $(ALL_LDFLAGS) $(LIBS)
  133. define PREBUILDCMDS
  134. endef
  135. define PRELINKCMDS
  136. endef
  137. define POSTBUILDCMDS
  138. endef
  139. endif
  140. ]]
  141. end
  142. function T.gmake_cpp.UniversalStaticLibBlock()
  143. kind "StaticLib"
  144. platforms { "universal32" }
  145. prepare()
  146. local cfg = premake.getconfig(prj, "Debug", "Universal32")
  147. premake.gmake_cpp_config(cfg, premake.gcc)
  148. test.capture [[
  149. ifeq ($(config),debuguniv32)
  150. OBJDIR = obj/Universal32/Debug
  151. TARGETDIR = .
  152. TARGET = $(TARGETDIR)/libMyProject.a
  153. DEFINES +=
  154. INCLUDES +=
  155. ALL_CPPFLAGS += $(CPPFLAGS) $(DEFINES) $(INCLUDES)
  156. ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -arch i386 -arch ppc
  157. ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS)
  158. ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)
  159. ALL_LDFLAGS += $(LDFLAGS) -s -arch i386 -arch ppc
  160. LDDEPS +=
  161. LIBS += $(LDDEPS)
  162. LINKCMD = libtool -o $(TARGET) $(OBJECTS)
  163. define PREBUILDCMDS
  164. endef
  165. define PRELINKCMDS
  166. endef
  167. define POSTBUILDCMDS
  168. endef
  169. endif
  170. ]]
  171. end