Changeset View
Changeset View
Standalone View
Standalone View
cmake/FindLibraryWithDebug.cmake
- This file was added.
1 | # | ||||
---|---|---|---|---|---|
2 | # FIND_LIBRARY_WITH_DEBUG | ||||
3 | # -> enhanced FIND_LIBRARY to allow the search for an | ||||
4 | # optional debug library with a WIN32_DEBUG_POSTFIX similar | ||||
5 | # to CMAKE_DEBUG_POSTFIX when creating a shared lib | ||||
6 | # it has to be the second and third argument | ||||
7 | | ||||
8 | # Copyright (c) 2007, Christian Ehrlicher, <ch.ehrlicher@gmx.de> | ||||
9 | | ||||
10 | # Redistribution and use in source and binary forms, with or without | ||||
11 | # modification, are permitted provided that the following conditions | ||||
12 | # are met: | ||||
13 | # 1. Redistributions of source code must retain the above copyright | ||||
14 | # notice, this list of conditions and the following disclaimer. | ||||
15 | # 2. Redistributions in binary form must reproduce the above copyright | ||||
16 | # notice, this list of conditions and the following disclaimer in the | ||||
17 | # documentation and/or other materials provided with the distribution. | ||||
18 | # 3. Neither the name of the University nor the names of its contributors | ||||
19 | # may be used to endorse or promote products derived from this software | ||||
20 | # without specific prior written permission. | ||||
21 | # | ||||
22 | # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||||
23 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||||
24 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||||
25 | # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||||
26 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||||
27 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||||
28 | # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||||
29 | # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||||
30 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||||
31 | # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||||
32 | # SUCH DAMAGE. | ||||
33 | | ||||
34 | MACRO(FIND_LIBRARY_WITH_DEBUG var_name win32_dbg_postfix_name dgb_postfix libname) | ||||
35 | | ||||
36 | IF(NOT "${win32_dbg_postfix_name}" STREQUAL "WIN32_DEBUG_POSTFIX") | ||||
37 | | ||||
38 | # no WIN32_DEBUG_POSTFIX -> simply pass all arguments to FIND_LIBRARY | ||||
39 | FIND_LIBRARY(${var_name} | ||||
40 | ${win32_dbg_postfix_name} | ||||
41 | ${dgb_postfix} | ||||
42 | ${libname} | ||||
43 | ${ARGN} | ||||
44 | ) | ||||
45 | | ||||
46 | ELSE(NOT "${win32_dbg_postfix_name}" STREQUAL "WIN32_DEBUG_POSTFIX") | ||||
47 | | ||||
48 | IF(NOT WIN32) | ||||
49 | # on non-win32 we don't need to take care about WIN32_DEBUG_POSTFIX | ||||
50 | | ||||
51 | FIND_LIBRARY(${var_name} ${libname} ${ARGN}) | ||||
52 | | ||||
53 | ELSE(NOT WIN32) | ||||
54 | | ||||
55 | # 1. get all possible libnames | ||||
56 | SET(args ${ARGN}) | ||||
57 | SET(newargs "") | ||||
58 | SET(libnames_release "") | ||||
59 | SET(libnames_debug "") | ||||
60 | | ||||
61 | LIST(LENGTH args listCount) | ||||
62 | | ||||
63 | IF("${libname}" STREQUAL "NAMES") | ||||
64 | SET(append_rest 0) | ||||
65 | LIST(APPEND args " ") | ||||
66 | | ||||
67 | FOREACH(i RANGE ${listCount}) | ||||
68 | LIST(GET args ${i} val) | ||||
69 | | ||||
70 | IF(append_rest) | ||||
71 | LIST(APPEND newargs ${val}) | ||||
72 | ELSE(append_rest) | ||||
73 | IF("${val}" STREQUAL "PATHS") | ||||
74 | LIST(APPEND newargs ${val}) | ||||
75 | SET(append_rest 1) | ||||
76 | ELSE("${val}" STREQUAL "PATHS") | ||||
77 | LIST(APPEND libnames_release "${val}") | ||||
78 | LIST(APPEND libnames_debug "${val}${dgb_postfix}") | ||||
79 | ENDIF("${val}" STREQUAL "PATHS") | ||||
80 | ENDIF(append_rest) | ||||
81 | | ||||
82 | ENDFOREACH(i) | ||||
83 | | ||||
84 | ELSE("${libname}" STREQUAL "NAMES") | ||||
85 | | ||||
86 | # just one name | ||||
87 | LIST(APPEND libnames_release "${libname}") | ||||
88 | LIST(APPEND libnames_debug "${libname}${dgb_postfix}") | ||||
89 | | ||||
90 | SET(newargs ${args}) | ||||
91 | | ||||
92 | ENDIF("${libname}" STREQUAL "NAMES") | ||||
93 | | ||||
94 | # search the release lib | ||||
95 | FIND_LIBRARY(${var_name}_RELEASE | ||||
96 | NAMES ${libnames_release} | ||||
97 | ${newargs} | ||||
98 | ) | ||||
99 | | ||||
100 | # search the debug lib | ||||
101 | FIND_LIBRARY(${var_name}_DEBUG | ||||
102 | NAMES ${libnames_debug} | ||||
103 | ${newargs} | ||||
104 | ) | ||||
105 | | ||||
106 | IF(${var_name}_RELEASE AND ${var_name}_DEBUG) | ||||
107 | | ||||
108 | # both libs found | ||||
109 | SET(${var_name} optimized ${${var_name}_RELEASE} | ||||
110 | debug ${${var_name}_DEBUG}) | ||||
111 | | ||||
112 | ELSE(${var_name}_RELEASE AND ${var_name}_DEBUG) | ||||
113 | | ||||
114 | IF(${var_name}_RELEASE) | ||||
115 | | ||||
116 | # only release found | ||||
117 | SET(${var_name} ${${var_name}_RELEASE}) | ||||
118 | | ||||
119 | ELSE(${var_name}_RELEASE) | ||||
120 | | ||||
121 | # only debug (or nothing) found | ||||
122 | SET(${var_name} ${${var_name}_DEBUG}) | ||||
123 | | ||||
124 | ENDIF(${var_name}_RELEASE) | ||||
125 | | ||||
126 | ENDIF(${var_name}_RELEASE AND ${var_name}_DEBUG) | ||||
127 | | ||||
128 | MARK_AS_ADVANCED(${var_name}_RELEASE) | ||||
129 | MARK_AS_ADVANCED(${var_name}_DEBUG) | ||||
130 | | ||||
131 | ENDIF(NOT WIN32) | ||||
132 | | ||||
133 | ENDIF(NOT "${win32_dbg_postfix_name}" STREQUAL "WIN32_DEBUG_POSTFIX") | ||||
134 | | ||||
135 | ENDMACRO(FIND_LIBRARY_WITH_DEBUG) |