File: generate_lib_file

package info (click to toggle)
nextcloud-desktop 4.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 40,404 kB
  • sloc: cpp: 118,401; objc: 752; python: 606; sh: 395; ansic: 391; ruby: 174; makefile: 44; javascript: 32; xml: 6
file content (122 lines) | stat: -rw-r--r-- 3,197 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env ruby

# simple script to generate CMakeLists.txt for wengophone libs
#
# usage: generate_lib_file
# then you will be prompted to enter the required parameters
#
#####################################################################
#
# SPDX-FileCopyrightText: 2006 Andreas Schneider <asn@cryptomilk.org>
# SPDX-License-Identifier: GPL-2.0-or-later
#

print("Name of project: ")
project=gets.chomp

printf("\n")

print("Other projects to include (e.g. \"owutil tinyxml\", leave empty to skip): ")
otherprojects=gets.chomp

printf("\n")

print("Definitions (leave empty to skip): ")
definitions=gets.chomp

cmakePublicIncDirName = project.upcase+"_PUBLIC_INCLUDE_DIRS"
cmakePrivateIncDirName = project.upcase+"_PRIVATE_INCLUDE_DIRS"
cmakeLibName = project.upcase+"_LIBRARY"
cmakeLibNames = project.upcase+"_LINK_LIBRARIES"
cmakePublicDefsName = project.upcase+"_PUBLIC_DEFINITIONS"
cmakePrivateDefsName = project.upcase+"_PRIVATE_DEFINITIONS"

file=File.new("CMakeLists.txt", "w+")

file.printf("project(#{project})\n")
file.printf("\n")
file.printf("# needed include directories to build #{project}\n")
file.printf("# saves the variable in internal cache for later use\n")
file.printf("set(#{cmakePublicIncDirName}\n")
file.printf("  ${CMAKE_CURRENT_SOURCE_DIR}\n")
file.printf("  ${CMAKE_CURRENT_SOURCE_DIR}/include\n")
file.printf("  CACHE INTERNAL \"#{project} public include directories\"\n")
file.printf(")\n")

file.printf("\n")

file.printf("set(#{cmakePrivateIncDirName}\n")
otherprojects.split(" ").each do |otherproject|
	file.printf("  ${#{otherproject.upcase}_PUBLIC_INCLUDE_DIRS}\n")
end
file.printf("  ${CMAKE_CURRENT_BINARY_DIR}\n")
file.printf(")\n")

file.printf("\n")

file.printf("set(#{cmakeLibName}\n")
file.printf("  #{project}\n")
file.printf("  CACHE INTERNAL \"#{project} library\"\n")
file.printf(")\n")

file.printf("\n")

file.printf("# #{project} lib and dependencies\n")
file.printf("set(#{cmakeLibNames}\n")
file.printf("  #{cmakeLibName}\n")
otherprojects.split(" ").each do |otherproject|
	file.printf("  ${#{otherproject.upcase}_LIBRARIES}\n")
end
file.printf(")\n")

file.printf("\n")

if not definitions.empty?
	file.printf("set(#{cmakePublicDefsName}\n")
	file.printf("  #{definitions}\n")
	file.printf("  CACHE INTERNAL \"#{project} public definitions\"\n")
	file.printf(")\n")

	file.printf("\n")

	file.printf("set(#{cmakePrivateDefsName}\n")
	file.printf("  #{definitions}\n")
	file.printf(")\n")

	file.printf("\n")
end

file.printf("set(#{project}_SRCS\n")
file.printf("  files.c\n")
file.printf(")\n")

file.printf("\n")

file.printf("include_directories(\n")
file.printf("  ${#{cmakePublicIncDirName}}\n")
file.printf("  ${#{cmakePrivateIncDirName}}\n")
file.printf(")\n")

file.printf("\n")

if not definitions.empty?
	file.printf("add_definitions(\n")
	file.printf("  ${#{cmakePublicDefsName}}\n")
	file.printf("  ${#{cmakePrivateDefsName}}\n")
	file.printf(")\n")

	file.printf("\n")
end

file.printf("\n")

file.printf("add_library(${#{cmakeLibName}} STATIC ${#{project}_SRCS})\n")

file.printf("\n")

file.printf("target_link_libraries(${#{cmakeLibNames}})\n")

file.printf("\n")

printf("Generated CMakeLists.txt for #{project}\n")