xmake.lua 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. set_project("SuiteSparse")
  2. set_xmakever("2.5.6")
  3. set_languages("cxx14")
  4. add_rules("mode.debug", "mode.release")
  5. -- initialize options
  6. option("with_cuda", {default = false, showmenu = true, description = "Build with CUDA support."})
  7. option("with_blas", {default = "mkl", showmenu = true, description = "Choose BLAS vendor.", values={"mkl", "openblas"}})
  8. option("complex", {default = false, showmenu = true, description = "Build with complex number support."})
  9. option("graphblas", {default = false, showmenu = true, description = "Build GraphBLAS module."})
  10. option("graphblas_static", {default = false, showmenu = true, description = "Build static GraphBLAS module."})
  11. -- set dependencies
  12. add_requires("metis")
  13. add_requires(get_config("with_blas"))
  14. if has_config("with_cuda") then
  15. add_requires("cuda", {system = true, configs = {utils = {"cublas"}}})
  16. add_defines("GPU_BLAS")
  17. end
  18. if not has_config("complex") then
  19. add_defines("NCOMPLEX")
  20. end
  21. -- export config files for cmake
  22. add_rules("utils.install.cmake_importfiles")
  23. -- export symbols for windows
  24. if is_plat("windows") and is_kind("shared") then
  25. add_rules("utils.symbols.export_all")
  26. end
  27. -- rule for compiling source files with multiple definitions
  28. rule("c.def_gen")
  29. set_extensions(".c")
  30. on_buildcmd_file(function (target, batchcmds, sourcefile, opt)
  31. local prod_defs = {"none"}
  32. -- get defines from sourcefile
  33. local fileconfig = target:fileconfig(sourcefile)
  34. if fileconfig then
  35. prod_defs = fileconfig.prod_defs
  36. end
  37. local objectfile
  38. for _, res in ipairs(prod_defs) do
  39. local rootdir = path.join(target:autogendir(), "rules", "def_gen")
  40. local filename = table.concat(table.join({path.basename(sourcefile)}, res), "_") .. ".c"
  41. local sourcefile_cx = target:autogenfile(sourcefile, {rootdir = rootdir, filename = filename})
  42. -- add objectfile
  43. objectfile = target:objectfile(sourcefile_cx)
  44. table.insert(target:objectfiles(), objectfile)
  45. -- add commands
  46. if res ~= "none" then
  47. batchcmds:show_progress(opt.progress, "${color.build.object}compiling.%s %s with define %s", get_config("mode"), sourcefile, res)
  48. batchcmds:compile(sourcefile, objectfile, {configs = {defines = res}})
  49. else
  50. batchcmds:show_progress(opt.progress, "${color.build.object}compiling.%s %s with no defines", get_config("mode"), sourcefile)
  51. batchcmds:compile(sourcefile, objectfile)
  52. end
  53. end
  54. -- add deps
  55. batchcmds:add_depfiles(sourcefile)
  56. batchcmds:set_depmtime(os.mtime(objectfile))
  57. batchcmds:set_depcache(target:dependfile(objectfile))
  58. end)
  59. rule_end()
  60. add_rules("c.def_gen", {override = true})
  61. target("suitesparseconfig")
  62. set_kind("$(kind)")
  63. add_files("SuiteSparse_config/SuiteSparse_config.c")
  64. add_headerfiles("SuiteSparse_config/SuiteSparse_config.h")
  65. add_includedirs("SuiteSparse_config", {public = true})
  66. target_end()
  67. for _, libname in ipairs({"AMD", "BTF", "CAMD", "CCOLAMD", "COLAMD"}) do
  68. target(libname)
  69. set_kind("$(kind)")
  70. add_deps("suitesparseconfig")
  71. add_files(libname .. "/Source/*.c", {prod_defs = {"none", "DLONG"}})
  72. add_includedirs(libname .. "/Include", {public = true})
  73. add_headerfiles(libname .. "/Include/*.h")
  74. target_end()
  75. end
  76. target("CHOLMOD")
  77. set_kind("$(kind)")
  78. add_deps("suitesparseconfig")
  79. add_deps("AMD", "CAMD", "COLAMD", "CCOLAMD")
  80. for _, module in ipairs({"Core", "Check", "Cholesky", "MatrixOps", "Partition", "Modify", "Supernodal"}) do
  81. add_files("CHOLMOD/" .. module .. "/cholmod*.c", {prod_defs = {"none", "DLONG"}})
  82. end
  83. add_includedirs("CHOLMOD/Include", {public = true})
  84. add_headerfiles("CHOLMOD/Include/*.h")
  85. add_packages("metis")
  86. add_packages(get_config("with_blas"))
  87. if has_config("with_cuda") then
  88. add_files("CHOLMOD/GPU/cholmod*.cu")
  89. add_files("CHOLMOD/GPU/cholmod*.c", {prod_defs = {"none", "DLONG"}})
  90. add_packages("cuda", {public = true})
  91. end
  92. target_end()
  93. target("CXSparse")
  94. set_kind("$(kind)")
  95. add_deps("suitesparseconfig")
  96. add_files("CXSparse/Source/*.c|cs_convert.c", {prod_defs = {"none", "CS_LONG"}})
  97. add_includedirs("CXSparse/Include", {public = true})
  98. add_headerfiles("CXSparse/Include/*.h")
  99. target_end()
  100. target("KLU")
  101. set_kind("$(kind)")
  102. add_deps("suitesparseconfig")
  103. add_deps("AMD", "COLAMD", "BTF")
  104. add_files("KLU/Source/*.c", {prod_defs = {"none", "DLONG"}})
  105. add_includedirs("KLU/Include", {public = true})
  106. add_headerfiles("KLU/Include/*.h")
  107. target_end()
  108. target("LDL")
  109. set_kind("$(kind)")
  110. add_deps("suitesparseconfig")
  111. add_files("LDL/Source/*.c", {prod_defs = {"none", "LDL_LONG"}})
  112. add_includedirs("LDL/Include", {public = true})
  113. add_headerfiles("LDL/Include/*.h")
  114. target_end()
  115. target("UMFPACK")
  116. set_kind("$(kind)")
  117. add_deps("suitesparseconfig")
  118. add_deps("AMD", "CHOLMOD")
  119. add_files("UMFPACK/Source/umfpack_timer.c", "UMFPACK/Source/umfpack_tictoc.c")
  120. local doubledefs = {"umf_analyze.c", "umf_apply_order.c", "umf_cholmod.c", "umf_colamd.c", "umf_free.c", "umf_fsize.c", "umf_is_permutation.c", "umf_malloc.c", "umf_realloc.c", "umf_report_perm.c", "umf_singletons.c"}
  121. for _, file in ipairs(doubledefs) do
  122. add_files("UMFPACK/Source/" .. file, {prod_defs = {"DINT", "DLONG"}})
  123. end
  124. add_files("UMFPACK/Source/*.c|umfpack_timer.c|umfpack_tictoc.c|" .. table.concat(doubledefs, "|"), {prod_defs = {"DINT", "DLONG", "ZINT", "ZLONG"}})
  125. add_includedirs("UMFPACK/Include", {public = true})
  126. add_headerfiles("UMFPACK/Include/*.h")
  127. add_packages(get_config("with_blas"), "metis")
  128. target_end()
  129. target("SPQR")
  130. set_kind("$(kind)")
  131. add_deps("suitesparseconfig")
  132. add_deps("CHOLMOD")
  133. add_files("SPQR/Source/*.cpp")
  134. add_includedirs("SPQR/Include", {public = true})
  135. add_headerfiles("SPQR/Include/*.h", "SPQR/Include/*.hpp")
  136. add_packages(get_config("with_blas"), "metis")
  137. if has_config("with_cuda") then
  138. add_deps("GPUQREngine")
  139. add_packages("cuda")
  140. add_files("SPQR/SPQRGPU/*.cpp")
  141. end
  142. target_end()
  143. if has_config("graphblas") then
  144. if has_config("graphblas_static") then
  145. target("GraphBLAS")
  146. set_kind("static")
  147. add_files("GraphBLAS/Source/*.c", "GraphBLAS/Source/Generated/*.c")
  148. add_includedirs("GraphBLAS/Include", "GraphBLAS/Source", "GraphBLAS/Source/Template", "GraphBLAS/Source/Generated")
  149. add_headerfiles("GraphBLAS/Include/*.h")
  150. target_end()
  151. else
  152. target("GraphBLAS")
  153. set_kind("shared")
  154. add_files("GraphBLAS/Source/*.c", "GraphBLAS/Source/Generated/*.c")
  155. add_includedirs("GraphBLAS/Include", "GraphBLAS/Source", "GraphBLAS/Source/Template", "GraphBLAS/Source/Generated")
  156. add_headerfiles("GraphBLAS/Include/*.h")
  157. target_end()
  158. end
  159. end
  160. if has_config("with_cuda") then
  161. target("SuiteSparse_GPURuntime")
  162. set_kind("$(kind)")
  163. add_deps("suitesparseconfig")
  164. add_packages("cuda")
  165. add_files("SuiteSparse_GPURuntime/Source/*.cpp")
  166. add_includedirs("SuiteSparse_GPURuntime/Include", {public = true})
  167. add_headerfiles("SuiteSparse_GPURuntime/Include/*.hpp")
  168. target_end()
  169. target("GPUQREngine")
  170. set_kind("$(kind)")
  171. add_deps("suitesparseconfig", "SuiteSparse_GPURuntime")
  172. add_files("GPUQREngine/Source/**.cpp", "GPUQREngine/Source/*.cu")
  173. add_includedirs("GPUQREngine/Include", {public = true})
  174. add_headerfiles("GPUQREngine/Include/(**.hpp)", "GPUQREngine/Include/(**.cu)")
  175. target_end()
  176. end