File: generate_findpackage_file

package info (click to toggle)
kde-dev-scripts 4%3A20.12.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 3,476 kB
  • sloc: perl: 15,559; lisp: 5,627; sh: 4,315; python: 3,892; ruby: 1,386; makefile: 13; sed: 9
file content (92 lines) | stat: -rwxr-xr-x 3,360 bytes parent folder | download | duplicates (8)
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
#!/usr/bin/env ruby

# simple script to generate simple cmake modules for finding libraries (packages)
# Alexander Neundorf <neundorf@kde.org>, 2006
# Laurent Montel <montel@kde.org>, 2008 
# usage: generate_findpackage_file
# then you will be prompted to enter the required parameters

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

print("pkgconfig package name [e.g. \"libxml-2.0\", we can add check as \"glib-2.0>=2.10 gtk+-2.0\" leave empty to skip pkgconfig]: ")
pkgconfig=gets.chomp

print("Look for header (e.g. \"jpeglib.h\" or \"libxml/xpath.h\"): ")
header=gets.chomp

print("Include subdir (e.g. \"libxml2\", empty to skip ): ")
incSubDir=gets.chomp

print("Look for library (e.g. \"jpeg\" or \"xml2\"): ")
lib=gets.chomp

cmakeIncDirName=package.upcase+"_INCLUDE_DIR"
cmakeLibName=package.upcase+"_LIBRARIES"
cmakeDefsName=package.upcase+"_DEFINITIONS"
cmakeFoundName=package.upcase+"_FOUND"
cmakeQuietName=package+"_FIND_QUIETLY"
cmakeRequiredName=package+"_FIND_REQUIRED"
cmakeFlagsName=package.upcase+"_CFLAGS"
cmakeLibDirName=package.upcase+"_LIBRARY_DIRS"
cmakeIncludeDirName=package.upcase+"_INCLUDE_DIRS"

file=File.new("Find#{package}.cmake", "w+")


file.printf("# - Try to find #{package}\n")
file.printf("# Once done this will define\n")
file.printf("#\n")
file.printf("#  #{cmakeFoundName} - system has #{package}\n")
file.printf("#  #{cmakeIncDirName} - the #{package} include directory\n")
file.printf("#  #{cmakeLibName} - Link these to use #{package}\n")
file.printf("#  #{cmakeDefsName} - Compiler switches required for using #{package}\n")
file.printf("# Redistribution and use is allowed according to the terms of the BSD license.\n")
file.printf("# For details see the accompanying COPYING-CMAKE-SCRIPTS file.\n")
file.printf("#\n\n\n")

file.printf("if ( #{cmakeIncDirName} AND #{cmakeLibName} )\n")
file.printf("   # in cache already\n")
file.printf("   SET(#{package}_FIND_QUIETLY TRUE)\n")
file.printf("endif ( #{cmakeIncDirName} AND #{cmakeLibName} )\n\n")

if not pkgconfig.empty?
   file.printf("# use pkg-config to get the directories and then use these values\n")
   file.printf("# in the FIND_PATH() and FIND_LIBRARY() calls\n")
   file.printf("if( NOT WIN32 )\n")
   file.printf("  find_package(PkgConfig)\n\n")
   file.printf("  pkg_check_modules(#{package.upcase} #{pkgconfig})\n\n")
   file.printf("  set(#{cmakeDefsName} ${#{cmakeFlagsName}})\n")
   file.printf("endif( NOT WIN32 )\n\n")
end

if not header.empty?
  file.printf("FIND_PATH(#{cmakeIncDirName} NAMES #{header}\n")
  if not pkgconfig.empty?
     file.printf("  PATHS\n")
    file.printf("  ${#{cmakeIncludeDirName}}\n")
  end

  if not incSubDir.empty?
     file.printf("  PATH_SUFFIXES #{incSubDir}\n")
  end
  file.printf(")\n\n")
end

if not lib.empty?
  file.printf("FIND_LIBRARY(#{cmakeLibName} NAMES #{lib}\n")
  if not pkgconfig.empty?
     file.printf("  PATHS\n")
    file.printf("  ${#{cmakeLibDirName}}\n")
  end
  file.printf(")\n\n")
end

file.printf("include(FindPackageHandleStandardArgs)\n")
file.printf("FIND_PACKAGE_HANDLE_STANDARD_ARGS(#{package} DEFAULT_MSG #{cmakeIncDirName} #{cmakeLibName} )\n\n")

file.printf("# show the #{cmakeIncDirName} and #{cmakeLibName} variables only in the advanced view\n")
file.printf("MARK_AS_ADVANCED(#{cmakeIncDirName} #{cmakeLibName} )\n\n")


printf("Done, generated Find#{package}.cmake\n")