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 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
#!/usr/bin/env ruby
# Simple script to generate simple cmake modules for finding
# libraries (packages)
#
# usage: generate_findpackage_file
# then you will be prompted to enter the required parameters
#
#####################################################################
#
# SPDX-FileCopyrightText: 2006 Alexander Neundorf <neundorf@kde.org>
# SPDX-FileCopyrightText: 2006 Andreas Schneider <asn@cryptomilk.org>
# SPDX-License-Identifier: GPL-2.0-or-later
#
require 'readline'
package=Readline.readline("Name of package: ")
name=Readline.readline("\nYour Name (for copyright): ")
email=Readline.readline("\nYour mail (for copyright): ")
pkgconfig=Readline.readline("\npkgconfig package name (e.g. \"libxml-2.0\", leave empty to skip pkgconfig): ")
header=Readline.readline("\nLook for header (e.g. \"jpeglib.h\" or \"libxml/xpath.h\"): ")
incSubDir=Readline.readline("\nLook for header subdir (e.g. \"libxml2\", empty to skip ): ")
libs=Readline.readline("\nLook for library (e.g. \"xml2\" or \"avcodec avutil\"): ")
t = Time.now
cmakeIncDirName=package.upcase+"_INCLUDE_DIR"
cmakeIncDirNames=package.upcase+"_INCLUDE_DIRS"
cmakeLibNames=package.upcase+"_LIBRARIES"
cmakeDefsName=package.upcase+"_DEFINITIONS"
cmakeFoundName=package.upcase+"_FOUND"
cmakeQuietName=package+"_FIND_QUIETLY"
cmakeRequiredName=package+"_FIND_REQUIRED"
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("# #{cmakeIncDirNames} - the #{package} include directory\n")
file.printf("# #{cmakeLibNames} - Link these to use #{package}\n")
file.printf("# #{cmakeDefsName} - Compiler switches required for using #{package}\n")
file.printf("#\n")
file.printf("# Copyright (c) #{t.year} #{name} <#{email}>\n")
file.printf("#\n")
file.printf("# Redistribution and use is allowed according to the terms of the New\n")
file.printf("# BSD license.\n")
file.printf("# For details see the accompanying COPYING-CMAKE-SCRIPTS file.\n")
file.printf("#\n")
file.printf("\n")
file.printf("\n")
file.printf("if (#{cmakeLibNames} AND #{cmakeIncDirNames})\n")
file.printf(" # in cache already\n")
file.printf(" set(#{cmakeFoundName} TRUE)\n")
file.printf("else (#{cmakeLibNames} AND #{cmakeIncDirNames})\n")
if not pkgconfig.empty?
file.printf(" find_package(PkgConfig)\n")
file.printf(" if (PKG_CONFIG_FOUND)\n")
file.printf(" pkg_check_modules(_#{package.upcase} #{pkgconfig})\n")
file.printf(" endif (PKG_CONFIG_FOUND)\n")
end
file.printf("\n")
file.printf(" find_path(#{cmakeIncDirName}\n")
file.printf(" NAMES\n")
file.printf(" #{header}\n")
file.printf(" PATHS\n")
if not pkgconfig.empty?
file.printf(" ${_#{package.upcase}_INCLUDEDIR}\n")
end
file.printf(" /usr/include\n")
file.printf(" /usr/local/include\n")
file.printf(" /opt/local/include\n")
file.printf(" /sw/include\n")
if not incSubDir.empty?
file.printf(" PATH_SUFFIXES\n")
file.printf(" #{incSubDir}\n")
end
file.printf(" )\n")
file.printf("\n")
libs.split(" ").each do |lib|
file.printf(" find_library(#{lib.upcase}_LIBRARY\n")
file.printf(" NAMES\n")
file.printf(" #{lib}\n")
file.printf(" PATHS\n")
if not pkgconfig.empty?
file.printf(" ${_#{package.upcase}_LIBDIR}\n")
end
file.printf(" /usr/lib\n")
file.printf(" /usr/local/lib\n")
file.printf(" /opt/local/lib\n")
file.printf(" /sw/lib\n")
file.printf(" )\n")
file.printf("\n")
end
file.printf(" set(#{cmakeIncDirNames}\n")
file.printf(" ${#{cmakeIncDirName}}\n")
file.printf(" )\n")
file.printf("\n")
libs.split(" ").each do |lib|
file.printf(" if (#{lib.upcase}_LIBRARY)\n")
file.printf(" set(#{cmakeLibNames}\n")
file.printf(" ${#{cmakeLibNames}}\n")
file.printf(" ${#{lib.upcase}_LIBRARY}\n")
file.printf(" )\n")
file.printf(" endif (#{lib.upcase}_LIBRARY)\n")
file.printf("\n")
end
file.printf(" include(FindPackageHandleStandardArgs)\n")
file.printf(" find_package_handle_standard_args(#{package} DEFAULT_MSG #{cmakeLibNames} #{cmakeIncDirNames})\n")
file.printf("\n")
file.printf(" # show the #{cmakeIncDirNames} and #{cmakeLibNames} variables only in the advanced view\n")
file.printf(" mark_as_advanced(#{cmakeIncDirNames} #{cmakeLibNames})\n\n")
file.printf("endif (#{cmakeLibNames} AND #{cmakeIncDirNames})\n\n")
printf("Done, generated Find#{package}.cmake\n")
|