Commit a4fb7f5d authored by Ghislain MARY's avatar Ghislain MARY
Browse files

Fix Python module on Mac OS X.

parent 2b279e81
......@@ -113,7 +113,7 @@ endif()
add_library(pylinphone MODULE "${SOURCE_FILENAME}")
target_compile_options(pylinphone PUBLIC ${LINPHONE_CPPFLAGS})
target_include_directories(pylinphone PUBLIC ${LINPHONE_INCLUDE_DIRS} ${PYTHON_INCLUDE_DIRS})
set(PYLINPHONE_LINK_LIBRARIES ${LINPHONE_LIBRARIES} ${PYTHON_LIBRARIES})
set(PYLINPHONE_LINK_LIBRARIES ${LINPHONE_LIBRARIES})
if(WIN32)
find_library(GCC_LIBRARIES gcc)
find_library(MINGWEX_LIBRARIES mingwex)
......@@ -121,8 +121,12 @@ if(WIN32)
endif()
target_link_libraries(pylinphone ${PYLINPHONE_LINK_LIBRARIES})
string(REPLACE ";" " " LINPHONE_LDFLAGS_STR "${LINPHONE_LDFLAGS}")
if(NOT "${LINPHONE_LDFLAGS_STR}" STREQUAL "")
set_target_properties(pylinphone PROPERTIES LINK_FLAGS "${LINPHONE_LDFLAGS_STR}")
set(PYLINPHONE_LDFLAGS "")
if(APPLE)
set(PYLINPHONE_LDFLAGS "${LINPHONE_LDFLAGS_STR} -undefined dynamic_lookup")
endif()
if(NOT "${PYLINPHONE_LDFLAGS}" STREQUAL "")
set_target_properties(pylinphone PROPERTIES LINK_FLAGS "${PYLINPHONE_LDFLAGS}")
endif()
set_target_properties(pylinphone PROPERTIES OUTPUT_NAME linphone PREFIX "" SUFFIX "${PY_MODULE_EXT}")
if(UNIX)
......@@ -140,6 +144,11 @@ foreach(PACKAGE_TO_BUILD ${PACKAGES_TO_BUILD})
"-DINPUT_DIR=${CMAKE_CURRENT_SOURCE_DIR}" "-DOUTPUT_DIR=${CMAKE_CURRENT_BINARY_DIR}"
"-P" "${CMAKE_CURRENT_SOURCE_DIR}/prepare_packaging.cmake"
)
if(APPLE)
add_custom_command(TARGET pylinphone POST_BUILD
COMMAND "${PYTHON_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/mac_rpath.py" "${CMAKE_CURRENT_BINARY_DIR}/build_${PACKAGE_TO_BUILD}/linphone/linphone"
)
endif()
endforeach()
if(WIN32)
......
#!/usr/bin/python
import sys
import getopt
import os
import subprocess
import re
# List directory files
def list_files(source_dir):
source_dir = os.path.abspath(source_dir)
# Build file list
filelist = []
for file in os.listdir(source_dir):
if os.path.isdir(os.path.join(source_dir, file)) == False:
root, ext = os.path.splitext(file)
if ext == '.dylib':
filelist.append(file)
return filelist
# List libraries used in a file
def list_libraries(file):
print "Exec: /usr/bin/otool -L %s" % file
ret = subprocess.check_output(["/usr/bin/otool", "-L", file])
librarylist = []
for a in ret.split("\n"):
pop = re.search("^\s+(\S*).*$", a)
if pop:
librarylist.append(pop.group(1))
return librarylist
# Change library id
def change_library_id(file, id):
id = "@loader_path/" + id
os.chmod(file, 0o755)
print "%s: Change id %s" % (file, id)
ret = subprocess.check_output(["/usr/bin/install_name_tool", "-id", id, file], stderr=subprocess.STDOUT)
# Change path to a library in a file
def change_library_path(file, old, new, path = ""):
if len(path)> 0 and path[-1] <> '/':
path = path + "/"
new = "@loader_path/" + path + new
os.chmod(file, 0o755)
print "%s: Replace %s -> %s" % (file, old, new)
ret = subprocess.check_output(["/usr/bin/install_name_tool", "-change", old, new, file])
# Replace libraries used by a file
def replace_libraries(file, name, libraries, path = ""):
print "---------------------------------------------"
print "Replace libraries in %s" % file
change_library_id(file, name)
librarylist = list_libraries(file)
for lib in libraries:
if lib <> name:
completelib = [s for s in librarylist if lib in s]
if len(completelib) == 1:
change_library_path(file, completelib[0], lib, path)
print "---------------------------------------------"
def main(argv=None):
if argv is None:
argv = sys.argv
if len(argv) > 1 and len(argv) <= 3:
path = argv[1]
file_list = list_files(path)
if len(argv) <= 2:
for file in file_list:
replace_libraries(os.path.join(path, file), file, file_list)
else:
path2 = argv[2]
if os.path.isdir(path2):
file_list2 = list_files(path2)
for file in file_list2:
replace_libraries(os.path.join(path2, file), file, file_list, os.path.relpath(path, path2))
else:
file = argv[2]
replace_libraries(file, os.path.basename(file), file_list, os.path.relpath(path, os.path.dirname(file)))
if __name__ == "__main__":
sys.exit(main())
......@@ -34,7 +34,7 @@ set(OUTPUT_DIR "${OUTPUT_DIR}/build_${PACKAGE_TYPE}/linphone")
file(MAKE_DIRECTORY "${OUTPUT_DIR}/linphone")
configure_file("${INPUT_DIR}/__init__.py.cmake" "${OUTPUT_DIR}/linphone/__init__.py")
file(COPY "${LINPHONE_PYTHON_MODULE}" DESTINATION "${OUTPUT_DIR}/linphone")
if(UNIX)
if(UNIX AND NOT APPLE)
foreach(reallib ${LINPHONE_DYNAMIC_LIBRARIES_TO_INSTALL})
get_filename_component(libpath ${reallib} DIRECTORY)
get_filename_component(reallibname ${reallib} NAME)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment