Skip to content

Commit 0508d99

Browse files
committed
Add missing files from jeds repo
1 parent 73e4b96 commit 0508d99

File tree

3 files changed

+224
-0
lines changed

3 files changed

+224
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# CorrectWindowsPaths - this module defines one macro
2+
#
3+
# CONVERT_CYGWIN_PATH( PATH )
4+
# This uses the command cygpath (provided by cygwin) to convert
5+
# unix-style paths into paths useable by cmake on windows
6+
7+
macro (CONVERT_CYGWIN_PATH _path)
8+
if (WIN32)
9+
EXECUTE_PROCESS(COMMAND cygpath.exe -m ${${_path}}
10+
OUTPUT_VARIABLE ${_path})
11+
string (STRIP ${${_path}} ${_path})
12+
endif (WIN32)
13+
endmacro (CONVERT_CYGWIN_PATH)
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# PackageMultipass - this module defines two macros
2+
#
3+
# FIND_PACKAGE_MULTIPASS (Name CURRENT
4+
# STATES VAR0 VAR1 ...
5+
# DEPENDENTS DEP0 DEP1 ...)
6+
#
7+
# This function creates a cache entry <UPPERCASED-Name>_CURRENT which
8+
# the user can set to "NO" to trigger a reconfiguration of the package.
9+
# The first time this function is called, the values of
10+
# <UPPERCASED-Name>_VAR0, ... are saved. If <UPPERCASED-Name>_CURRENT
11+
# is false or if any STATE has changed since the last time
12+
# FIND_PACKAGE_MULTIPASS() was called, then CURRENT will be set to "NO",
13+
# otherwise CURRENT will be "YES". IF not CURRENT, then
14+
# <UPPERCASED-Name>_DEP0, ... will be FORCED to NOTFOUND.
15+
# Example:
16+
# find_path (FOO_DIR include/foo.h)
17+
# FIND_PACKAGE_MULTIPASS (Foo foo_current
18+
# STATES DIR
19+
# DEPENDENTS INCLUDES LIBRARIES)
20+
# if (NOT foo_current)
21+
# # Make temporary files, run programs, etc, to determine FOO_INCLUDES and FOO_LIBRARIES
22+
# endif (NOT foo_current)
23+
#
24+
# MULTIPASS_SOURCE_RUNS (Name INCLUDES LIBRARIES SOURCE RUNS LANGUAGE)
25+
# Always runs the given test, use this when you need to re-run tests
26+
# because parent variables have made old cache entries stale. The LANGUAGE
27+
# variable is either C or CXX indicating which compiler the test should
28+
# use.
29+
# MULTIPASS_C_SOURCE_RUNS (Name INCLUDES LIBRARIES SOURCE RUNS)
30+
# DEPRECATED! This is only included for backwards compatability. Use
31+
# the more general MULTIPASS_SOURCE_RUNS instead.
32+
# Always runs the given test, use this when you need to re-run tests
33+
# because parent variables have made old cache entries stale.
34+
35+
macro (FIND_PACKAGE_MULTIPASS _name _current)
36+
string (TOUPPER ${_name} _NAME)
37+
set (_args ${ARGV})
38+
list (REMOVE_AT _args 0 1)
39+
40+
set (_states_current "YES")
41+
list (GET _args 0 _cmd)
42+
if (_cmd STREQUAL "STATES")
43+
list (REMOVE_AT _args 0)
44+
list (GET _args 0 _state)
45+
while (_state AND NOT _state STREQUAL "DEPENDENTS")
46+
# The name of the stored value for the given state
47+
set (_stored_var PACKAGE_MULTIPASS_${_NAME}_${_state})
48+
if (NOT "${${_stored_var}}" STREQUAL "${${_NAME}_${_state}}")
49+
set (_states_current "NO")
50+
endif (NOT "${${_stored_var}}" STREQUAL "${${_NAME}_${_state}}")
51+
set (${_stored_var} "${${_NAME}_${_state}}" CACHE INTERNAL "Stored state for ${_name}." FORCE)
52+
list (REMOVE_AT _args 0)
53+
list (GET _args 0 _state)
54+
endwhile (_state AND NOT _state STREQUAL "DEPENDENTS")
55+
endif (_cmd STREQUAL "STATES")
56+
57+
set (_stored ${_NAME}_CURRENT)
58+
if (NOT ${_stored})
59+
set (${_stored} "YES" CACHE BOOL "Is the configuration for ${_name} current? Set to \"NO\" to reconfigure." FORCE)
60+
set (_states_current "NO")
61+
endif (NOT ${_stored})
62+
63+
set (${_current} ${_states_current})
64+
if (NOT ${_current} AND PACKAGE_MULTIPASS_${_name}_CALLED)
65+
message (STATUS "Clearing ${_name} dependent variables")
66+
# Clear all the dependent variables so that the module can reset them
67+
list (GET _args 0 _cmd)
68+
if (_cmd STREQUAL "DEPENDENTS")
69+
list (REMOVE_AT _args 0)
70+
foreach (dep ${_args})
71+
set (${_NAME}_${dep} "NOTFOUND" CACHE INTERNAL "Cleared" FORCE)
72+
endforeach (dep)
73+
endif (_cmd STREQUAL "DEPENDENTS")
74+
set (${_NAME}_FOUND "NOTFOUND" CACHE INTERNAL "Cleared" FORCE)
75+
endif ()
76+
set (PACKAGE_MULTIPASS_${name}_CALLED YES CACHE INTERNAL "Private" FORCE)
77+
endmacro (FIND_PACKAGE_MULTIPASS)
78+
79+
80+
macro (MULTIPASS_SOURCE_RUNS includes libraries source runs language)
81+
include (Check${language}SourceRuns)
82+
# This is a ridiculous hack. CHECK_${language}_SOURCE_* thinks that if the
83+
# *name* of the return variable doesn't change, then the test does
84+
# not need to be re-run. We keep an internal count which we
85+
# increment to guarantee that every test name is unique. If we've
86+
# gotten here, then the configuration has changed enough that the
87+
# test *needs* to be rerun.
88+
if (NOT MULTIPASS_TEST_COUNT)
89+
set (MULTIPASS_TEST_COUNT 00)
90+
endif (NOT MULTIPASS_TEST_COUNT)
91+
math (EXPR _tmp "${MULTIPASS_TEST_COUNT} + 1") # Why can't I add to a cache variable?
92+
set (MULTIPASS_TEST_COUNT ${_tmp} CACHE INTERNAL "Unique test ID")
93+
set (testname MULTIPASS_TEST_${MULTIPASS_TEST_COUNT}_${runs})
94+
set (CMAKE_REQUIRED_INCLUDES ${includes})
95+
set (CMAKE_REQUIRED_LIBRARIES ${libraries})
96+
if(${language} STREQUAL "C")
97+
check_c_source_runs ("${source}" ${testname})
98+
elseif(${language} STREQUAL "CXX")
99+
check_cxx_source_runs ("${source}" ${testname})
100+
endif()
101+
set (${runs} "${${testname}}")
102+
endmacro (MULTIPASS_SOURCE_RUNS)
103+
104+
macro (MULTIPASS_C_SOURCE_RUNS includes libraries source runs)
105+
multipass_source_runs("${includes}" "${libraries}" "${source}" ${runs} "C")
106+
endmacro (MULTIPASS_C_SOURCE_RUNS)
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# ResolveCompilerPaths - this module defines two macros
2+
#
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.
8+
# Example:
9+
#
10+
# RESOLVE_LIBRARIES (FOO_LIBRARIES "-L/A -la -L/B -lb -lc -ld")
11+
#
12+
# will be resolved to
13+
#
14+
# FOO_LIBRARIES:STRING="/A/liba.so;/B/libb.so;/A/libc.so;/usr/lib/libd.so"
15+
#
16+
# if the filesystem looks like
17+
#
18+
# /A: liba.so libc.so
19+
# /B: liba.so libb.so
20+
# /usr/lib: liba.so libb.so libc.so libd.so
21+
#
22+
# and /usr/lib is a system directory.
23+
#
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).
26+
#
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.
31+
# Example:
32+
#
33+
# RESOLVE_INCLUDES (FOO_INCLUDES "-I/A -DBAR='\"irrelevant -I/string here\"' -I/B")
34+
#
35+
# will be resolved to
36+
#
37+
# FOO_INCLUDES:STRING="/A;/B"
38+
#
39+
# assuming both directories exist.
40+
# Note: as currently implemented, the -I/string will be picked up mistakenly (cry, cry)
41+
include (CorrectWindowsPaths)
42+
43+
macro (RESOLVE_LIBRARIES LIBS LINK_LINE)
44+
string (REGEX MATCHALL "((-L|-l|-Wl)([^\" ]+|\"[^\"]+\")|[^\" ]+\\.(a|so|dll|lib))" _all_tokens "${LINK_LINE}")
45+
set (_libs_found "")
46+
set (_directory_list "")
47+
foreach (token ${_all_tokens})
48+
if (token MATCHES "-L([^\" ]+|\"[^\"]+\")")
49+
# If it's a library path, add it to the list
50+
string (REGEX REPLACE "^-L" "" token ${token})
51+
string (REGEX REPLACE "//" "/" token ${token})
52+
convert_cygwin_path(token)
53+
list (APPEND _directory_list ${token})
54+
elseif (token MATCHES "^(-l([^\" ]+|\"[^\"]+\")|[^\" ]+\\.(a|so|dll|lib))")
55+
# It's a library, resolve the path by looking in the list and then (by default) in system directories
56+
if (WIN32) #windows expects "libfoo", linux expects "foo"
57+
string (REGEX REPLACE "^-l" "lib" token ${token})
58+
else (WIN32)
59+
string (REGEX REPLACE "^-l" "" token ${token})
60+
endif (WIN32)
61+
set (_root "")
62+
if (token MATCHES "^/")# We have an absolute path
63+
#separate into a path and a library name:
64+
string (REGEX MATCH "[^/]*\\.(a|so|dll|lib)$" libname ${token})
65+
string (REGEX MATCH ".*[^${libname}$]" libpath ${token})
66+
convert_cygwin_path(libpath)
67+
set (_directory_list ${_directory_list} ${libpath})
68+
set (token ${libname})
69+
endif (token MATCHES "^/")
70+
set (_lib "NOTFOUND" CACHE FILEPATH "Cleared" FORCE)
71+
find_library (_lib ${token} HINTS ${_directory_list} ${_root})
72+
if (_lib)
73+
string (REPLACE "//" "/" _lib ${_lib})
74+
list (APPEND _libs_found ${_lib})
75+
else (_lib)
76+
message (STATUS "Unable to find library ${token}")
77+
endif (_lib)
78+
endif (token MATCHES "-L([^\" ]+|\"[^\"]+\")")
79+
endforeach (token)
80+
set (_lib "NOTFOUND" CACHE INTERNAL "Scratch variable" FORCE)
81+
# only the LAST occurence of each library is required since there should be no circular dependencies
82+
if (_libs_found)
83+
list (REVERSE _libs_found)
84+
list (REMOVE_DUPLICATES _libs_found)
85+
list (REVERSE _libs_found)
86+
endif (_libs_found)
87+
set (${LIBS} "${_libs_found}")
88+
endmacro (RESOLVE_LIBRARIES)
89+
90+
macro (RESOLVE_INCLUDES INCS COMPILE_LINE)
91+
string (REGEX MATCHALL "-I([^\" ]+|\"[^\"]+\")" _all_tokens "${COMPILE_LINE}")
92+
set (_incs_found "")
93+
foreach (token ${_all_tokens})
94+
string (REGEX REPLACE "^-I" "" token ${token})
95+
string (REGEX REPLACE "//" "/" token ${token})
96+
convert_cygwin_path(token)
97+
if (EXISTS ${token})
98+
list (APPEND _incs_found ${token})
99+
else (EXISTS ${token})
100+
message (STATUS "Include directory ${token} does not exist")
101+
endif (EXISTS ${token})
102+
endforeach (token)
103+
list (REMOVE_DUPLICATES _incs_found)
104+
set (${INCS} "${_incs_found}")
105+
endmacro (RESOLVE_INCLUDES)

0 commit comments

Comments
 (0)