Skip to content

Commit

Permalink
ci: add fixup_tar to handle rpath and depdendencies
Browse files Browse the repository at this point in the history
Signed-off-by: AlexandraTrifan <Alexandra.Trifan@analog.com>
  • Loading branch information
AlexandraTrifan committed Oct 23, 2024
1 parent ff932a4 commit d92e36b
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 7 deletions.
55 changes: 55 additions & 0 deletions CI/macOS/fixup_tar
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash

#!/bin/bash -xe
WORKDIR=$(pwd)
cd $WORKDIR/build_tar
# Extract tar.gz to temp folder
tarname=$(find . -maxdepth 1 -name '*.tar.gz')
if [ -z "${tarname}" ]; then
echo "tar.gz not found"
exit 1
fi
# Remove .tar.gz from filename
subfoldername=$(echo "${tarname}" | rev | cut -b 8- | rev)

mkdir -p temp_tar
tar -xzf "${tarname}" -C temp_tar
mv "temp_tar/${subfoldername}" temp
cd temp

deps_dir=Library/Frameworks/libm2k.framework/Versions/Current/Dependencies
libm2k_loc=Library/Frameworks/libm2k.framework/Versions/Current/libm2k
libm2kheaders_loc=Library/Frameworks/libm2k.framework/Versions/Current/Headers/*

mkdir -p "${deps_dir}"

# Create links to framework files
mkdir -p usr/local/{lib,include}
ln -fs "../../../${libm2k_loc}" usr/local/lib/libm2k.dylib
# ln -fs "../../../${libm2kheaders_loc}" usr/local/include/iio.h

# Update rpath of library
install_name_tool -add_rpath @loader_path/. "${libm2k_loc}"

# Copy dependent libs to local libs, and update rpath of dependencies
for each in $(otool -L "${libm2k_loc}" |grep '\/usr\/local\|homebrew' |cut -f2 | cut -d' ' -f1) ; do
name=$(basename "${each}")
cp "${each}" "${deps_dir}"
chmod +w "${deps_dir}/${name}"
install_name_tool -id "@rpath/Dependencies/${name}" "${deps_dir}/${name}"
install_name_tool -change "${each}" "@rpath/Dependencies/${name}" "${libm2k_loc}"
codesign --force -s - "${deps_dir}/${name}"
done

# Update tools
for tool in Library/Frameworks/libm2k.framework/Tools/*;
do
install_name_tool -add_rpath @loader_path/../.. "${tool}"
done

# Remove old tar and create new one
rm "../${tarname}"
tar -czf "../${tarname}" .
cd ..
rm -rf temp

2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ if (BUILD_EXAMPLES)
endif()

# Create an installer if compiling for OSX
if(OSX_PACKAGE)
if(OSX_PACKAGE AND OSX_FRAMEWORK)
set(LIBM2K_PKG ${CMAKE_CURRENT_BINARY_DIR}/libm2k-${PROJECT_VERSION}.g${LIBM2K_VERSION_GIT}.pkg)
set(LIBM2K_TEMP_PKG ${CMAKE_CURRENT_BINARY_DIR}/libm2k-${VERSION}-temp.pkg)
set(LIBM2K_DISTRIBUTION_XML ${CMAKE_CURRENT_BINARY_DIR}/Distribution.xml)
Expand Down
11 changes: 5 additions & 6 deletions tools/m2kcli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,11 @@ if (NOT WIN32)
endif()
endif()

if (NOT SKIP_INSTALL_ALL)
if((${CMAKE_SYSTEM_NAME} MATCHES "Darwin") AND OSX_PACKAGE)
install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION ${OSX_INSTALL_FRAMEWORKSDIR}/libm2k.framework/Tools)
else()
install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()

if((${CMAKE_SYSTEM_NAME} MATCHES "Darwin") AND OSX_PACKAGE)
install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION ${OSX_INSTALL_FRAMEWORKSDIR}/libm2k.framework/Tools)
else()
install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()

# Make the test targets available to the main CMakeLists.txt
Expand Down

0 comments on commit d92e36b

Please sign in to comment.