generate_lib_file 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #!/usr/bin/env ruby
  2. # simple script to generate CMakeLists.txt for wengophone libs
  3. #
  4. # usage: generate_lib_file
  5. # then you will be prompted to enter the required parameters
  6. #
  7. #####################################################################
  8. #
  9. # Copyright (c) 2006 Andreas Schneider <asn@cryptomilk.org>
  10. # This program is free software; you can redistribute it and/or
  11. # modify it under the terms of the GNU General Public License
  12. # as published by the Free Software Foundation; either version 2
  13. # of the License, or (at your option) any later version.
  14. #
  15. # This program is distributed in the hope that it will be useful,
  16. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. # GNU General Public License for more details.
  19. #
  20. # You should have received a copy of the GNU General Public License
  21. # along with this program; if not, write to the Free Software
  22. # Foundation, Inc., 51 Franklin Street, Fifth Floor,
  23. # Boston, MA 02110-1301, USA.
  24. #
  25. print("Name of project: ")
  26. project=gets.chomp
  27. printf("\n")
  28. print("Other projects to include (e.g. \"owutil tinyxml\", leave emtpy to skip): ")
  29. otherprojects=gets.chomp
  30. printf("\n")
  31. print("Definitions (leave empty to skip): ")
  32. definitions=gets.chomp
  33. cmakePublicIncDirName = project.upcase+"_PUBLIC_INCLUDE_DIRS"
  34. cmakePrivateIncDirName = project.upcase+"_PRIVATE_INCLUDE_DIRS"
  35. cmakeLibName = project.upcase+"_LIBRARY"
  36. cmakeLibNames = project.upcase+"_LINK_LIBRARIES"
  37. cmakePublicDefsName = project.upcase+"_PUBLIC_DEFINITIONS"
  38. cmakePrivateDefsName = project.upcase+"_PRIVATE_DEFINITIONS"
  39. file=File.new("CMakeLists.txt", "w+")
  40. file.printf("project(#{project})\n")
  41. file.printf("\n")
  42. file.printf("# needed include directories to build #{project}\n")
  43. file.printf("# saves the variable in internal cache for later use\n")
  44. file.printf("set(#{cmakePublicIncDirName}\n")
  45. file.printf(" ${CMAKE_CURRENT_SOURCE_DIR}\n")
  46. file.printf(" ${CMAKE_CURRENT_SOURCE_DIR}/include\n")
  47. file.printf(" CACHE INTERNAL \"#{project} public include directories\"\n")
  48. file.printf(")\n")
  49. file.printf("\n")
  50. file.printf("set(#{cmakePrivateIncDirName}\n")
  51. otherprojects.split(" ").each do |otherproject|
  52. file.printf(" ${#{otherproject.upcase}_PUBLIC_INCLUDE_DIRS}\n")
  53. end
  54. file.printf(" ${CMAKE_CURRENT_BINARY_DIR}\n")
  55. file.printf(")\n")
  56. file.printf("\n")
  57. file.printf("set(#{cmakeLibName}\n")
  58. file.printf(" #{project}\n")
  59. file.printf(" CACHE INTERNAL \"#{project} library\"\n")
  60. file.printf(")\n")
  61. file.printf("\n")
  62. file.printf("# #{project} lib and dependencies\n")
  63. file.printf("set(#{cmakeLibNames}\n")
  64. file.printf(" #{cmakeLibName}\n")
  65. otherprojects.split(" ").each do |otherproject|
  66. file.printf(" ${#{otherproject.upcase}_LIBRARIES}\n")
  67. end
  68. file.printf(")\n")
  69. file.printf("\n")
  70. if not definitions.empty?
  71. file.printf("set(#{cmakePublicDefsName}\n")
  72. file.printf(" #{definitions}\n")
  73. file.printf(" CACHE INTERNAL \"#{project} public definitions\"\n")
  74. file.printf(")\n")
  75. file.printf("\n")
  76. file.printf("set(#{cmakePrivateDefsName}\n")
  77. file.printf(" #{definitions}\n")
  78. file.printf(")\n")
  79. file.printf("\n")
  80. end
  81. file.printf("set(#{project}_SRCS\n")
  82. file.printf(" files.c\n")
  83. file.printf(")\n")
  84. file.printf("\n")
  85. file.printf("include_directories(\n")
  86. file.printf(" ${#{cmakePublicIncDirName}}\n")
  87. file.printf(" ${#{cmakePrivateIncDirName}}\n")
  88. file.printf(")\n")
  89. file.printf("\n")
  90. if not definitions.empty?
  91. file.printf("add_definitions(\n")
  92. file.printf(" ${#{cmakePublicDefsName}}\n")
  93. file.printf(" ${#{cmakePrivateDefsName}}\n")
  94. file.printf(")\n")
  95. file.printf("\n")
  96. end
  97. file.printf("\n")
  98. file.printf("add_library(${#{cmakeLibName}} STATIC ${#{project}_SRCS})\n")
  99. file.printf("\n")
  100. file.printf("target_link_libraries(${#{cmakeLibNames}})\n")
  101. file.printf("\n")
  102. printf("Generated CMakeLists.txt for #{project}\n")