forked from volca02/openDarkEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPythonDeps.cmake
58 lines (45 loc) · 2.25 KB
/
PythonDeps.cmake
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
# Helper. Statically linked python needs some deps, and the FindPython.cmake script does not set those
MACRO(FIND_PYTHON_DEPS _LIBS_TO_ADD)
# SET(${_LIBS_TO_ADD})
FIND_PACKAGE(PythonInterp REQUIRED)
# Execute the one-liner to get the python deps
IF(PYTHONINTERP_FOUND)
EXEC_PROGRAM(${PYTHON_EXECUTABLE} ARGS "-c 'from distutils.sysconfig import get_config_var; print(get_config_var(\"LIBS\") + \" \" + get_config_var(\"SYSLIBS\"))'"
OUTPUT_VARIABLE PYDEPS
RETURN_VALUE PYRET
)
# The return value should be Zero, otherwise, an error is indicated
IF(NOT PYRET)
# Ok, execution went fine
# Remove the -l parts, and do other small changes needed as well...
SET(_LIBNAMES)
STRING(REGEX REPLACE "-l" "" _LIBNAMES "${PYDEPS}")
STRING(REGEX REPLACE "[\n\r]" " " _LIBNAMES "${_LIBNAMES}")
STRING(REGEX REPLACE " " " " _LIBNAMES "${_LIBNAMES}")
STRING(REGEX REPLACE " " ";" _LIBNAMES "${_LIBNAMES}")
# Now. For each of the listed libs, try to find it using FIND_LIBRARY (pthread -> /usr/lib/libpthread.so, etc)
FOREACH(_LIB ${_LIBNAMES})
# As the CMake caches things, it is important to have a different name for each lib path, otherwise
# the FIND_LIBRARY won't search
# Var Name will contain the lib name
SET(_VARNAME "_LIB_${_LIB}")
SET(${_VARNAME})
# Find it, concantenate the result list
FIND_LIBRARY(${_VARNAME} ${_LIB} PATHS /usr/lib /lib)
IF(${_VARNAME})
# Semicolon is the THING. It took me a while to find this out...
SET(${_LIBS_TO_ADD} "${${_LIBS_TO_ADD}};${${_VARNAME}}")
ELSE(${_VARNAME})
MESSAGE(FATAL_ERROR "Python static linking dependency ${_LIB} not found!")
ENDIF(${_VARNAME})
# SET(${_VARNAME})
MARK_AS_ADVANCED(${_VARNAME})
ENDFOREACH(_LIB)
# Done...
ELSE(NOT PYRET)
MESSAGE(FATAL_ERROR "Python static linking dependencies could not be evaluated - return value non-zero")
ENDIF(NOT PYRET)
ELSE(PYTHONINTERP_FOUND)
MESSAGE(FATAL_ERROR "Python interpreter not found, but needed to determine static linking dependencies")
ENDIF(PYTHONINTERP_FOUND)
ENDMACRO(FIND_PYTHON_DEPS _LIBS_TO_ADD)