1 # ResolveCompilerPaths - this module defines two macros
3 # RESOLVE_LIBRARIES (XXX_LIBRARIES LINK_LINE)
4 # This macro is intended to be used by FindXXX.cmake modules.
5 # It parses a compiler link line and resolves all libraries
6 # (-lfoo) using the library path contexts (-L/path) in scope.
7 # The result in XXX_LIBRARIES is the list of fully resolved libs.
10 # RESOLVE_LIBRARIES (FOO_LIBRARIES "-L/A -la -L/B -lb -lc -ld")
14 # FOO_LIBRARIES:STRING="/A/liba.so;/B/libb.so;/A/libc.so;/usr/lib/libd.so"
16 # if the filesystem looks like
20 # /usr/lib: liba.so libb.so libc.so libd.so
22 # and /usr/lib is a system directory.
24 # Note: If RESOLVE_LIBRARIES() resolves a link line differently from
25 # the native linker, there is a bug in this macro (please report it).
27 # RESOLVE_INCLUDES (XXX_INCLUDES INCLUDE_LINE)
28 # This macro is intended to be used by FindXXX.cmake modules.
29 # It parses a compile line and resolves all includes
30 # (-I/path/to/include) to a list of directories. Other flags are ignored.
33 # RESOLVE_INCLUDES (FOO_INCLUDES "-I/A -DBAR='\"irrelevant -I/string here\"' -I/B")
37 # FOO_INCLUDES:STRING="/A;/B"
39 # assuming both directories exist.
40 # Note: as currently implemented, the -I/string will be picked up mistakenly (cry, cry)
42 macro (RESOLVE_LIBRARIES_DIR LIBS_DIR LINK_LINE)
43 string (REGEX MATCHALL "-L([^\" ]+|\"[^\"]+\")" _all_tokens "${LINK_LINE}")
46 foreach (token ${_all_tokens})
47 string (REGEX REPLACE "-L" "" token ${token})
48 string (REGEX REPLACE "//" "/" token ${token})
49 string (REGEX REPLACE "\n" "" token ${token})
50 list (APPEND _directory_list ${token})
52 set (${LIBS_DIR} ${_directory_list})
53 endmacro (RESOLVE_LIBRARIES_DIR)
55 macro (RESOLVE_LIBRARIES LIBS LINK_LINE)
57 #message(${LINK_LINE})
58 string (REGEX MATCHALL "(((-L|-l|-Wl)([^\" ]+|\"[^\"]+\")|/[^\" ]+(a|so|dll|dylib))|(-framework Accelerate))" _all_tokens "${LINK_LINE}")
59 #message(${_all_tokens})
62 foreach (token ${_all_tokens})
63 if (token MATCHES "-L([^\" ]+|\"[^\"]+\")")
64 # If it's a library path, add it to the list
65 string (REGEX REPLACE "^-L" "" token ${token})
66 string (REGEX REPLACE "//" "/" token ${token})
67 string (REGEX REPLACE "\n" "" token ${token})
68 list (APPEND _directory_list ${token})
69 endif (token MATCHES "-L([^\" ]+|\"[^\"]+\")")
71 foreach (token ${_all_tokens})
72 if (token MATCHES "^(-l([^\" ]+|\"[^\"]+\")|/[^\" ]+(a|so|dll|dylib))")
73 string (REGEX REPLACE "\n" "" token ${token})
74 # It's a library, resolve the path by looking in the list and then (by default) in system directories
75 string (REGEX REPLACE "^-l" "" token ${token})
77 if (token MATCHES "^/") # We have an absolute path, add root to the search path
79 endif (token MATCHES "^/")
80 set (_lib "NOTFOUND" CACHE FILEPATH "Cleared" FORCE)
81 find_library (_lib ${token} HINTS ${_directory_list} ${_root})
83 string (REPLACE "//" "/" _lib ${_lib})
84 list (APPEND _libs_found ${_lib})
86 #message (STATUS "Unable to find library ${token}")
88 endif (token MATCHES "^(-l([^\" ]+|\"[^\"]+\")|/[^\" ]+(a|so|dll|dylib))")
90 foreach (token ${_all_tokens})
91 if (token MATCHES "-framework Accelerate")
92 list(APPEND _libs_found ${token})
93 endif (token MATCHES "-framework Accelerate")
96 list (REVERSE _libs_found)
97 list (REMOVE_DUPLICATES _libs_found)
98 list (REVERSE _libs_found)
100 set (${LIBS} "${_libs_found}")
101 endmacro (RESOLVE_LIBRARIES)
103 macro (RESOLVE_INCLUDES INCS COMPILE_LINE)
104 string (REGEX MATCHALL "-I([^\" ]+|\"[^\"]+\")" _all_tokens "${COMPILE_LINE}")
106 foreach (token ${_all_tokens})
107 string (REGEX REPLACE "^-I" "" token ${token})
108 string (REGEX REPLACE "//" "/" token ${token})
109 string (REGEX REPLACE "\n" "" token ${token})
111 list (APPEND _incs_found ${token})
112 else (EXISTS ${token})
113 #message (STATUS "Include directory ${token} does not exist")
114 endif (EXISTS ${token})
117 list (REMOVE_DUPLICATES _incs_found)
119 set (${INCS} "${_incs_found}")
120 endmacro (RESOLVE_INCLUDES)
122 macro (RESOLVE_DEFINITIONS DEF COMPILE_LINE)
123 string (REGEX MATCHALL "-D[0-9A-Z_]+(=[a-zA-z0-9]+)?" _all_tokens "${COMPILE_LINE}")
124 # message(STATUS ${_all_tokens})
126 foreach (token ${_all_tokens})
127 string (REGEX REPLACE "^-D" "-DMOAB_" token ${token})
128 list (APPEND _incs_found ${token})
131 list (REMOVE_DUPLICATES _incs_found)
133 set (${DEF} "${_incs_found}")
134 endmacro (RESOLVE_DEFINITIONS)