| 1 |
#!/usr/bin/python |
|---|
| 2 |
# |
|---|
| 3 |
# Copyright (c) 2009, Whispersoft s.r.l. |
|---|
| 4 |
# All rights reserved. |
|---|
| 5 |
# |
|---|
| 6 |
# Redistribution and use in source and binary forms, with or without |
|---|
| 7 |
# modification, are permitted provided that the following conditions are |
|---|
| 8 |
# met: |
|---|
| 9 |
# |
|---|
| 10 |
# * Redistributions of source code must retain the above copyright |
|---|
| 11 |
# notice, this list of conditions and the following disclaimer. |
|---|
| 12 |
# * Redistributions in binary form must reproduce the above |
|---|
| 13 |
# copyright notice, this list of conditions and the following disclaimer |
|---|
| 14 |
# in the documentation and/or other materials provided with the |
|---|
| 15 |
# distribution. |
|---|
| 16 |
# * Neither the name of Whispersoft s.r.l. nor the names of its |
|---|
| 17 |
# contributors may be used to endorse or promote products derived from |
|---|
| 18 |
# this software without specific prior written permission. |
|---|
| 19 |
# |
|---|
| 20 |
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|---|
| 21 |
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|---|
| 22 |
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|---|
| 23 |
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|---|
| 24 |
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|---|
| 25 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|---|
| 26 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|---|
| 27 |
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|---|
| 28 |
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|---|
| 29 |
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|---|
| 30 |
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|---|
| 31 |
# |
|---|
| 32 |
# |
|---|
| 33 |
# As we don't know too much cmake to make this smarter, we generate |
|---|
| 34 |
# FindXXX.cmake files out of input for standard libraries.. |
|---|
| 35 |
# |
|---|
| 36 |
|
|---|
| 37 |
import sys |
|---|
| 38 |
|
|---|
| 39 |
TEMPLATE = """ |
|---|
| 40 |
# Finds %(libname)s library |
|---|
| 41 |
# |
|---|
| 42 |
# %(libname)s_INCLUDE_DIR - where to find %(include)s, etc. |
|---|
| 43 |
# %(libname)s_LIBRARIES - List of libraries when using %(libname)s. |
|---|
| 44 |
# %(libname)s_FOUND - True if %(libname)s found. |
|---|
| 45 |
# |
|---|
| 46 |
|
|---|
| 47 |
if (%(libname)s_INCLUDE_DIR) |
|---|
| 48 |
# Already in cache, be silent |
|---|
| 49 |
set(%(libname)s_FIND_QUIETLY TRUE) |
|---|
| 50 |
endif (%(libname)s_INCLUDE_DIR) |
|---|
| 51 |
|
|---|
| 52 |
find_path(%(libname)s_INCLUDE_DIR %(include)s |
|---|
| 53 |
/opt/local/include |
|---|
| 54 |
/usr/local/include |
|---|
| 55 |
/usr/include |
|---|
| 56 |
/usr/include/%(libfile)s |
|---|
| 57 |
/usr/include/lib%(libfile)s |
|---|
| 58 |
) |
|---|
| 59 |
|
|---|
| 60 |
set(%(libname)s_NAMES %(libfile)s) |
|---|
| 61 |
find_library(%(libname)s_LIBRARY |
|---|
| 62 |
NAMES ${%(libname)s_NAMES} |
|---|
| 63 |
PATHS /usr/lib /usr/local/lib /opt/local/lib |
|---|
| 64 |
) |
|---|
| 65 |
|
|---|
| 66 |
if (%(libname)s_INCLUDE_DIR AND %(libname)s_LIBRARY) |
|---|
| 67 |
set(%(libname)s_FOUND TRUE) |
|---|
| 68 |
set( %(libname)s_LIBRARIES ${%(libname)s_LIBRARY} ) |
|---|
| 69 |
else (%(libname)s_INCLUDE_DIR AND %(libname)s_LIBRARY) |
|---|
| 70 |
set(%(libname)s_FOUND FALSE) |
|---|
| 71 |
set(%(libname)s_LIBRARIES) |
|---|
| 72 |
endif (%(libname)s_INCLUDE_DIR AND %(libname)s_LIBRARY) |
|---|
| 73 |
|
|---|
| 74 |
if (%(libname)s_FOUND) |
|---|
| 75 |
if (NOT %(libname)s_FIND_QUIETLY) |
|---|
| 76 |
message(STATUS "Found %(libname)s: ${%(libname)s_LIBRARY}") |
|---|
| 77 |
endif (NOT %(libname)s_FIND_QUIETLY) |
|---|
| 78 |
else (%(libname)s_FOUND) |
|---|
| 79 |
if (%(libname)s_FIND_REQUIRED) |
|---|
| 80 |
message(STATUS "Looked for %(libname)s libraries named ${%(libname)s_NAMES}.") |
|---|
| 81 |
message(STATUS "Include file detected: [${%(libname)s_INCLUDE_DIR}].") |
|---|
| 82 |
message(STATUS "Lib file detected: [${%(libname)s_LIBRARY}].") |
|---|
| 83 |
message(FATAL_ERROR "=========> Could NOT find %(libname)s library") |
|---|
| 84 |
endif (%(libname)s_FIND_REQUIRED) |
|---|
| 85 |
endif (%(libname)s_FOUND) |
|---|
| 86 |
|
|---|
| 87 |
mark_as_advanced( |
|---|
| 88 |
%(libname)s_LIBRARY |
|---|
| 89 |
%(libname)s_INCLUDE_DIR |
|---|
| 90 |
) |
|---|
| 91 |
""" |
|---|
| 92 |
|
|---|
| 93 |
def main(): |
|---|
| 94 |
if len(sys.argv) < 2: |
|---|
| 95 |
sys.stderr.write("Use: %s <libname> [<libfile> [<include>s]]" % \ |
|---|
| 96 |
sys.argv[0]) |
|---|
| 97 |
# endif |
|---|
| 98 |
|
|---|
| 99 |
libname = sys.argv[1] |
|---|
| 100 |
if len(sys.argv) > 2: |
|---|
| 101 |
libfile = sys.argv[2] |
|---|
| 102 |
if len(sys.argv) > 3: |
|---|
| 103 |
include = sys.argv[3] |
|---|
| 104 |
else: |
|---|
| 105 |
include = libfile + ".h" |
|---|
| 106 |
# endif |
|---|
| 107 |
else: |
|---|
| 108 |
libfile = sys.argv[1].lower() |
|---|
| 109 |
include = libfile + ".h" |
|---|
| 110 |
# endif |
|---|
| 111 |
fout = open("Find%s.cmake" % libname, "w") |
|---|
| 112 |
fout.write(TEMPLATE % { "libname": libname, |
|---|
| 113 |
"include": include, |
|---|
| 114 |
"libfile" : libfile }) |
|---|
| 115 |
fout.close() |
|---|
| 116 |
# enddef |
|---|
| 117 |
|
|---|
| 118 |
if __name__ == "__main__": |
|---|
| 119 |
main() |
|---|