init.lua 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. -- configuration 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_workspace_settings()
  15. language "C++"
  16. configurations {"Debug", "DebugOpt", "Release"}
  17. location "build"
  18. architecture "x86_64"
  19. filter "configurations:Debug"
  20. defines {"DEBUG"}
  21. symbols "On"
  22. warnings "Extra"
  23. filter "configurations:DebugOpt"
  24. defines {"DEBUG"}
  25. symbols "On"
  26. optimize "Debug"
  27. warnings "Extra"
  28. filter "configurations:Release"
  29. defines {"NDEBUG"}
  30. optimize "On"
  31. warnings "Extra"
  32. filter {}
  33. end
  34. local function link_against_modules(modules)
  35. for _, mod in pairs(modules) do
  36. links(mod.name)
  37. end
  38. for _, mod in pairs(modules) do
  39. includedirs(mod.public_includes)
  40. end
  41. end
  42. --- An attempt at making a common ground for multiple libraries I'd use
  43. -- in various projects.
  44. local function library_module(lib_name, folder)
  45. local mod = {
  46. name = lib_name,
  47. folder = folder or lib_name,
  48. links = {},
  49. win_links = {},
  50. linux_links = {},
  51. files = {},
  52. win_files = {},
  53. linux_files = {},
  54. defines = {},
  55. win_defines = {},
  56. linux_defines = {},
  57. -- Separating private/public includes helps
  58. -- to reuse the public when needed.
  59. private_includes = {},
  60. win_private_includes = {},
  61. linux_private_includes = {},
  62. public_includes = {},
  63. module_dependencies = {}
  64. }
  65. function mod:_convert_and_store_path(destination, paths)
  66. local path_prefix = library_base_folders .. self.folder .. "/"
  67. for k, path in pairs(paths) do
  68. table.insert(destination, path_prefix .. path)
  69. end
  70. end
  71. function mod:use_private_includes(local_private_paths)
  72. self:_convert_and_store_path(self.private_includes, local_private_paths)
  73. return self
  74. end
  75. function mod:use_win_private_includes(local_win_private_paths)
  76. self:_convert_and_store_path(self.win_private_includes, local_win_private_paths)
  77. return self
  78. end
  79. function mod:use_linux_private_includes(local_linux_private_paths)
  80. self:_convert_and_store_path(self.linux_private_includes, local_linux_private_paths)
  81. return self
  82. end
  83. function mod:use_public_includes(local_public_paths)
  84. self:_convert_and_store_path(self.public_includes, local_public_paths)
  85. return self
  86. end
  87. function mod:use_files(local_file_paths)
  88. self:_convert_and_store_path(self.files, local_file_paths)
  89. return self
  90. end
  91. function mod:use_win_files(local_file_paths)
  92. self:_convert_and_store_path(self.win_files, local_file_paths)
  93. return self
  94. end
  95. function mod:use_linux_files(local_file_paths)
  96. self:_convert_and_store_path(self.linux_files, local_file_paths)
  97. return self
  98. end
  99. function mod:use_defines(defines)
  100. self.defines = defines
  101. return self
  102. end
  103. function mod:use_win_defines(defines)
  104. self.win_defines = defines
  105. return self
  106. end
  107. function mod:use_linux_defines(defines)
  108. self.linux_defines = defines
  109. return self
  110. end
  111. function mod:require_module(module)
  112. self.module_dependencies:insert(module)
  113. end
  114. function mod:use_links(links)
  115. self.links = links
  116. return self
  117. end
  118. function mod:use_win_links(links)
  119. self.win_links = links
  120. return self
  121. end
  122. function mod:use_linux_links(links)
  123. self.linux_links = links
  124. return self
  125. end
  126. --- Calls premake's code to add the module's project to the current
  127. -- workspace.
  128. function mod:use(use_kind)
  129. -- TODO: handle dependencies
  130. project(self.name)
  131. kind(use_kind)
  132. defines(self.defines)
  133. files(self.files)
  134. includedirs(self.public_includes)
  135. includedirs(self.private_includes)
  136. links(self.links)
  137. filter "system:windows"
  138. defines(self.win_defines)
  139. files(self.win_files)
  140. includedirs(self.win_private_includes)
  141. links(self.win_links)
  142. filter "system:linux"
  143. defines(self.linux_defines)
  144. files(self.linux_files)
  145. includedirs(self.linux_private_includes)
  146. links(self.linux_links)
  147. filter {}
  148. end
  149. return mod
  150. end
  151. return {
  152. _VERSION = "0.0.1",
  153. base_workspace_settings = base_workspace_settings,
  154. library_module = library_module,
  155. link_against_modules = link_against_modules
  156. }