init.lua 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. local library_base_folders = "extern/"
  2. local function extern_path(local_path)
  3. if local_path:sub(1,1) == '/' then
  4. -- TODO : Windows absolute path check
  5. print(([[[WARN] "%s" is not a local path.]]):format(local_path))
  6. local_path = local_path:sub(2)
  7. end
  8. return library_base_folders .. local_path
  9. end
  10. --- Common function I use to structure projects according to the three-stage
  11. -- project pattern I usually see : Debug, optimized Debug and Release.
  12. -- Sometimes I see also a Final version, but it almost is a copy of the Release
  13. -- stage.
  14. local function base_project_settings()
  15. -- I commonly use modern C++ nowadays.
  16. language "C++"
  17. configuration "Debug"
  18. defines {"DEBUG"}
  19. symbols "On"
  20. warnings "Extra"
  21. configuration "DebugOpt"
  22. defines {"DEBUG"}
  23. symbols "On"
  24. optimize "Debug"
  25. warnings "Extra"
  26. configuration "Release"
  27. defines {"NDEBUG"}
  28. optimize "On"
  29. warnings "Extra"
  30. end
  31. local function link_against_modules(modules)
  32. for _, mod in pairs(modules) do
  33. links(mod.name)
  34. end
  35. for _, mod in pairs(modules) do
  36. includedirs(mod.public_includes)
  37. end
  38. -- TODO system filters
  39. end
  40. --- An attempt at making a common ground for multiple libraries I'd use
  41. -- in various projects.
  42. local function library_module(lib_name, folder)
  43. local mod = {
  44. name = lib_name,
  45. folder = folder or lib_name,
  46. links = {},
  47. win_links = {},
  48. linux_links = {},
  49. files = {},
  50. win_files = {},
  51. linux_files = {},
  52. defines = {},
  53. win_defines = {},
  54. linux_defines = {},
  55. -- Separating private/public includes helps
  56. -- to reuse the public when needed.
  57. private_includes = {},
  58. win_private_includes = {},
  59. linux_private_includes = {},
  60. public_includes = {},
  61. module_dependencies = {}
  62. }
  63. function mod:_convert_and_store_path(destination, paths)
  64. local path_prefix = library_base_folders .. self.folder .. "/"
  65. for k, path in pairs(paths) do
  66. table.insert(destination, path_prefix .. path)
  67. end
  68. end
  69. function mod:use_private_includes(local_private_paths)
  70. self:_convert_and_store_path(self.private_includes, local_private_paths)
  71. return self
  72. end
  73. function mod:use_win_private_includes(local_win_private_paths)
  74. self:_convert_and_store_path(self.win_private_includes, local_win_private_paths)
  75. return self
  76. end
  77. function mod:use_linux_private_includes(local_linux_private_paths)
  78. self:_convert_and_store_path(self.linux_private_includes, local_linux_private_paths)
  79. return self
  80. end
  81. function mod:use_public_includes(local_public_paths)
  82. self:_convert_and_store_path(self.public_includes, local_public_paths)
  83. return self
  84. end
  85. function mod:use_files(local_file_paths)
  86. self:_convert_and_store_path(self.files, local_file_paths)
  87. return self
  88. end
  89. function mod:use_win_files(local_file_paths)
  90. self:_convert_and_store_path(self.win_files, local_file_paths)
  91. return self
  92. end
  93. function mod:use_linux_files(local_file_paths)
  94. self:_convert_and_store_path(self.linux_files, local_file_paths)
  95. return self
  96. end
  97. function mod:use_defines(defines)
  98. self.defines = defines
  99. return self
  100. end
  101. function mod:use_win_defines(defines)
  102. self.win_defines = defines
  103. return self
  104. end
  105. function mod:use_linux_defines(defines)
  106. self.linux_defines = defines
  107. return self
  108. end
  109. function mod:require_module(module)
  110. self.module_dependencies:insert(module)
  111. end
  112. function mod:use_links(links)
  113. self.links = links
  114. return self
  115. end
  116. function mod:use_win_links(links)
  117. self.win_links = links
  118. return self
  119. end
  120. function mod:use_linux_links(links)
  121. self.linux_links = links
  122. return self
  123. end
  124. --- Calls premake's code to add the module's project to the current
  125. -- workspace.
  126. function mod:use(use_kind)
  127. project(self.name)
  128. kind(use_kind)
  129. -- TODO : kind
  130. defines(self.defines)
  131. files(self.files)
  132. includedirs(self.public_includes)
  133. includedirs(self.private_includes)
  134. links(self.links)
  135. base_project_settings()
  136. filter "system:windows"
  137. defines(self.win_defines)
  138. files(self.win_files)
  139. includedirs(self.win_private_includes)
  140. links(self.win_links)
  141. filter "system:linux"
  142. defines(self.linux_defines)
  143. files(self.linux_files)
  144. includedirs(self.linux_private_includes)
  145. links(self.linux_links)
  146. end
  147. return mod
  148. end
  149. return {
  150. _VERSION = "0.0.1",
  151. base_project_settings = base_project_settings,
  152. library_module = library_module,
  153. link_against_modules = link_against_modules
  154. }