Skip to content

Commit

Permalink
Introduce macOS framework (#827)
Browse files Browse the repository at this point in the history
* introduce macos framework

* distribute

* fix

* fix

* fix

* fedora fix
  • Loading branch information
MaxRayskiy authored Dec 22, 2022
1 parent 690d096 commit 16beef1
Show file tree
Hide file tree
Showing 20 changed files with 177 additions and 41 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/build-test-distribute.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ jobs:
mv meshlib-ubuntu20-dev.deb meshlib_${{needs.versioning-and-release-url.outputs.version_tag}}_ubuntu20-dev.deb
mv meshlib-ubuntu22-dev.deb meshlib_${{needs.versioning-and-release-url.outputs.version_tag}}_ubuntu22-dev.deb
mv meshlib-dev.rpm meshlib_${{needs.versioning-and-release-url.outputs.version_tag}}-dev.rpm
mv meshlib_x64.pkg meshlib_${{needs.versioning-and-release-url.outputs.version_tag}}_x64.pkg
mv meshlib_arm.pkg meshlib_${{needs.versioning-and-release-url.outputs.version_tag}}_arm.pkg
- name: Upload Distributives
run: |
Expand All @@ -157,6 +159,8 @@ jobs:
meshlib_${{needs.versioning-and-release-url.outputs.version_tag}}_ubuntu20-dev.deb \
meshlib_${{needs.versioning-and-release-url.outputs.version_tag}}_ubuntu22-dev.deb \
meshlib_${{needs.versioning-and-release-url.outputs.version_tag}}-dev.rpm \
meshlib_${{needs.versioning-and-release-url.outputs.version_tag}}_x64.pkg \
meshlib_${{needs.versioning-and-release-url.outputs.version_tag}}_arm.pkg
update-artifacts:
timeout-minutes: 15
Expand Down
22 changes: 21 additions & 1 deletion .github/workflows/build-test-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,20 @@ on:
jobs:
macos-build-test:
timeout-minutes: 60
runs-on: [macos-latest]
runs-on: ${{ matrix.runner }}
strategy:
matrix:
os: [ x64, arm ]
config: [Release]
compiler: [Сlang]
include:
- compiler: Сlang
cxx-compiler: /usr/bin/clang++
c-compiler: /usr/bin/clang
- os: x64
runner: macos-latest
- os: arm
runner: macos-arm-build

steps:
- name: Checkout
Expand All @@ -40,10 +45,25 @@ jobs:
CMAKE_CXX_COMPILER: ${{ matrix.cxx-compiler }}
# not realy needed
CMAKE_C_COMPILER: ${{ matrix.c-compiler }}
MESHLIB_VERSION: ${{ inputs.version }}

- name: Unit Tests
run: ./build/${{ matrix.config }}/bin/MRTest

- name: Python Tests
working-directory: ./build/${{ matrix.config }}/bin
run: python3 ./../../../scripts/run_python_test_script.py

- name: Create Pkg
if: ${{ inputs.UPLOAD_ARTIFACTS }}
run: |
./scripts/distribution_apple.sh
mv MeshLib_.pkg meshlib_${{matrix.os}}.pkg
- name: Upload Macos Distribution
if: ${{ inputs.UPLOAD_ARTIFACTS }}
uses: actions/upload-artifact@v3
with:
name: Distributives
path: meshlib_${{matrix.os}}.pkg
retention-days: 1
24 changes: 16 additions & 8 deletions .github/workflows/versioning-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,23 @@ jobs:
<a href="${{env.RELEASE_PATH}}/meshlib_${{steps.version.outputs.version}}_ubuntu22-dev.deb">deb</a>
</td>
</tr>
<tr>
<td align="center">Fedora 35 x64</td>
<td align="center">
<a href="${{env.RELEASE_PATH}}/meshlib_${{steps.version.outputs.version}}-dev.rpm">rpm</a>
</td>
</tr>
<tr>
<td align="center">MacOS</td>
<td colspan=3 align="center"> Coming soon! :green_apple:</td>
<td align="center">Fedora 35 x64</td>
<td align="center">
<a href="${{env.RELEASE_PATH}}/meshlib_${{steps.version.outputs.version}}-dev.rpm">rpm</a>
</td>
</tr>
<tr>
<td align="center">MacOS x64</td>
<td align="center">
<a href="${{env.RELEASE_PATH}}/meshlib_${{steps.version.outputs.version}}_x64.pkg">x64 pkg</a>
</td>
</tr>
<tr>
<td align="center">MacOS arm</td>
<td align="center">
<a href="${{env.RELEASE_PATH}}/meshlib_${{steps.version.outputs.version}}_arm.pkg">arm pkg</a>
</td>
</tr>
</tbody>
</table>
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ thirdparty_build/*
distr/*
*.log
/docker/logs/
macos/Resources/LICENSE
48 changes: 34 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ ENDIF() # NOT MR_EMSCRIPTEN

project (MeshLib CXX)
add_compile_definitions(MR_PROJECT_NAME=\"MeshLib\")
add_compile_definitions(MR_FRAMEWORK)

# all binaries will be located in ./build/Release/bin
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
Expand Down Expand Up @@ -65,7 +66,7 @@ IF(NOT MR_EMSCRIPTEN)
IF(APPLE)
include_directories(${HOMEBREW_PREFIX}/include)
# need to hardcode some path to fix wheel (no option to pass path)
set(CMAKE_INSTALL_RPATH "@loader_path;@loader_path/../;@loader_path/meshlib;${THIRDPARTY_LIB_DIR};${CMAKE_BINARY_DIR}/bin")
set(CMAKE_INSTALL_RPATH "@loader_path;@loader_path/..;@loader_path/../lib;@loader_path/meshlib;${THIRDPARTY_LIB_DIR};${CMAKE_BINARY_DIR}/bin")
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
ELSE()
# set platform dependent flags
Expand Down Expand Up @@ -155,16 +156,37 @@ ENDIF()
add_compile_definitions(SPDLOG_COMPILED_LIB SPDLOG_SHARED_LIB)
ENDIF() # NOT MR_EMSCRIPTEN

set(MR_BIN_DIR "bin")
set(MR_INCLUDE_DIR "include/MeshLib")
set(MR_MAIN_LIB_DIR "lib/MeshLib")
set(MR_PY_LIB_DIR "${MR_MAIN_LIB_DIR}/meshlib")
set(MR_RESOURCES_DIR "etc/MeshLib")
set(MR_FONTS_DIR "share/fonts")
IF(NOT $ENV{MR_VERSION} STREQUAL "")
set(MESHLIB_VERSION $ENV{MR_VERSION})
ELSE()
set(MESHLIB_VERSION 0.0.0)
ENDIF()
message("version: ${MESHLIB_VERSION}")

if(NOT APPLE)
set(MR_ROOT "./usr/local")
set(MR_BIN_DIR "${MR_ROOT}/bin")
set(MR_INCLUDE_DIR "${MR_ROOT}/include/MeshLib")
set(MR_MAIN_LIB_DIR "${MR_ROOT}/lib/MeshLib")
set(MR_PY_LIB_DIR "${MR_MAIN_LIB_DIR}/meshlib")
set(MR_RESOURCES_DIR "${MR_ROOT}/etc/MeshLib")
set(MR_FONTS_DIR "${MR_ROOT}/share/fonts")
set(MR_CONFIG_DIR ${MR_MAIN_LIB_DIR})
else()
set(MR_ROOT "./Library/Frameworks/MeshLib.framework/Versions/${MESHLIB_VERSION}")
set(MR_BIN_DIR "${MR_ROOT}/bin")
set(MR_INCLUDE_DIR "${MR_ROOT}/include")
set(MR_MAIN_LIB_DIR "${MR_ROOT}/lib")
set(MR_PY_LIB_DIR "${MR_MAIN_LIB_DIR}/meshlib")
set(MR_RESOURCES_DIR "${MR_ROOT}/Resources")
set(MR_FONTS_DIR "${MR_ROOT}/Resources/fonts")
set(MR_CONFIG_DIR ${MR_ROOT}/Resources)
endif()

add_subdirectory(${PROJECT_SOURCE_DIR}/MRMesh ./MRMesh)
add_subdirectory(${PROJECT_SOURCE_DIR}/MRViewer ./MRViewer)
add_subdirectory(${PROJECT_SOURCE_DIR}/MRCommonPlugins ./MRCommonPlugins)
add_subdirectory(${PROJECT_SOURCE_DIR}/MRPch ./MRPch)
IF(NOT MR_EMSCRIPTEN)
add_subdirectory(${PROJECT_SOURCE_DIR}/mrmeshpy ./mrmeshpy)
add_subdirectory(${PROJECT_SOURCE_DIR}/mrmeshnumpy ./mrmeshnumpy)
Expand All @@ -174,20 +196,18 @@ ENDIF() # NOT MR_EMSCRIPTEN
add_subdirectory(${PROJECT_SOURCE_DIR}/MRTest ./MRTest)
add_subdirectory(${PROJECT_SOURCE_DIR}/MRViewerApp ./MRViewerApp)

IF(NOT MESHLIB_VERSION)
set(MESHLIB_VERSION 0.0.0)
ENDIF()

include(CMakePackageConfigHelpers)
configure_package_config_file(meshlib-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/meshlib-config.cmake
INSTALL_DESTINATION ${MR_MAIN_LIB_DIR}
INSTALL_DESTINATION ${MR_CONFIG_DIR}
PATH_VARS MR_INCLUDE_DIR MR_MAIN_LIB_DIR)


write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/meshlib-config-version.cmake
VERSION ${MESHLIB_VERSION}
COMPATIBILITY ExactVersion)

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/meshlib-config.cmake ${CMAKE_CURRENT_BINARY_DIR}/meshlib-config-version.cmake
DESTINATION ${MR_MAIN_LIB_DIR})
DESTINATION ${MR_CONFIG_DIR})

set(CPACK_GENERATOR "DRAGNDROP")
include(CPack)
5 changes: 4 additions & 1 deletion examples/cmake-example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ add_executable(${PROJECT_NAME} main.cpp)

find_package(MeshLib CONFIG REQUIRED)
target_include_directories(${PROJECT_NAME} PUBLIC ${MESHLIB_INCLUDE_DIR} ${MESHLIB_THIRDPARTY_INCLUDE_DIR})
target_link_libraries(${PROJECT_NAME} MeshLib::MRMesh)

find_package(Boost COMPONENTS REQUIRED )

target_link_libraries(${PROJECT_NAME} MeshLib::MRMesh Boost::boost)
20 changes: 20 additions & 0 deletions macos/Distribution.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<installer-gui-script minSpecVersion="1">
<title>MeshLib</title>
<background alignment="bottomleft" file="./background.png" mime-type="image/png" scaling="proportional"/>
<background-darkAqua alignment="bottomleft" file="./background.png" mime-type="image/png" scaling="proportional"/>
<license file="LICENSE" mime-type="text/richtext"/>
<conclusion file="Conclusion.rtf" mime-type="text/richtext"/>
<pkg-ref id="com.MeshInspector.MeshLib"/>
<options customize="never" require-scripts="false" hostArchitectures="x86_64,arm64"/>
<choices-outline>
<line choice="default">
<line choice="com.MeshInspector.MeshLib"/>
</line>
</choices-outline>
<choice id="default"/>
<choice id="com.MeshInspector.MeshLib" visible="false">
<pkg-ref id="com.MeshInspector.MeshLib"/>
</choice>
<pkg-ref id="com.MeshInspector.MeshLib" version="0" onConclusion="none">MeshLib.pkg</pkg-ref>
</installer-gui-script>
Binary file added macos/MeshInspector_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions macos/Resources/Conclusion.rtf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{\rtf1\ansi\ansicpg1252\cocoartf1561\cocoasubrtf200
{\fonttbl\f0\fswiss\fcharset0 Helvetica;\f1\fnil\fcharset0 LucidaGrande-Bold;\f2\fnil\fcharset0 LucidaGrande;
\f3\fnil\fcharset0 Monaco;}
{\colortbl;\red255\green255\blue255;}
{\*\expandedcolortbl;;}
\margl1440\margr1440\vieww10540\viewh8400\viewkind0
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural\partightenfactor0

\f0\fs28 \cf0 Congratulations!
\fs24
\f1\b\fs28 MeshLib
\f2\b0 was successfully installed.
\fs24 \
\
}
Binary file added macos/Resources/background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions meshlib-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ get_filename_component(SELF_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
include(${SELF_DIR}/cmake/MRMeshConfig.cmake)
include(${SELF_DIR}/cmake/MRViewerConfig.cmake)
include(${SELF_DIR}/cmake/MRCommonPluginsConfig.cmake)

if(APPLE)
message("You can install required packages via brew: ' xargs brew install < /Library/Frameworks/MeshLib.framework/Versions/Current/scripts/macos.txt '")
endif(APPLE)
2 changes: 1 addition & 1 deletion scripts/MeshLib-dev.spec
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ MR_INSTALL_RES_DIR="$RPM_BUILD_ROOT/usr/local/etc/MeshLib/"
MR_INSTALL_INCLUDE_DIR="$RPM_BUILD_ROOT/usr/local/include/MeshLib/"

cd ./build/Release
cmake --install . --prefix "$RPM_BUILD_ROOT/usr/local/"
cmake --install . --prefix "$RPM_BUILD_ROOT/"
cd -

#mkdirs
Expand Down
2 changes: 1 addition & 1 deletion scripts/distribution.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ if [ -d "./distr/" ]; then
fi

cd ./build/Release
cmake --install . --prefix "../../distr/meshlib-dev/usr/local"
cmake --install . --prefix "../../distr/meshlib-dev"
cd -

MR_INSTALL_LIB_DIR="/usr/local/lib/MeshLib"
Expand Down
37 changes: 37 additions & 0 deletions scripts/distribution_apple.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

if [ -d "./Library" ];
then rm -rf "./Library";
fi

cd ./build/Release
cmake --install . --prefix=../..
cd -
MR_VERSION=$(ls ./Library/Frameworks/MeshLib.framework/Versions/)
echo "version: ${MR_VERSION}"
MR_PREFIX="./Library/Frameworks/MeshLib.framework/Versions/${MR_VERSION}"
echo "prefix: ${MR_PREFIX}"

cp -rL ./lib "${MR_PREFIX}/lib/"
cp -rL ./include "${MR_PREFIX}/include/"

cp ./LICENSE ./macos/Resources
mkdir "${MR_PREFIX}"/requirements/
cp ./requirements/macos.txt "${MR_PREFIX}"/requirements/

ln -s "/Library/Frameworks/MeshLib.framework/Versions/${MR_VERSION}" "./Library/Frameworks/MeshLib.framework/Versions/Current"
ln -s "/Library/Frameworks/MeshLib.framework/Resources" "./Library/Frameworks/MeshLib.framework/Versions/${MR_VERSION}/Resources"

# be carefull with pkg names! The pkg can fail to build
pkgbuild \
--root Library \
--identifier com.MeshInspector.MeshLib \
--install-location /Library \
MeshLib.pkg


productbuild \
--distribution ./macos/Distribution.xml \
--package-path ./MeshLib.pkg \
--resources ./macos/Resources \
MeshLib_.pkg
5 changes: 2 additions & 3 deletions scripts/install_brew_requirements.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#!/bin/bash

# run from repo root
# NODE: using this script is deprecated! Better install meshrus(-dev).rpm package
# This script installs requirements by `dnf` if not already installed
# `distribution.sh` uses this script as preinstall
# NODE: using this script is deprecated! Better install meshlib(-dev).pkg package
# This script installs requirements by `brew` if not already installed

requirements_file=requirements/macos.txt
for req in `cat $requirements_file`
Expand Down
4 changes: 2 additions & 2 deletions source/MRCommonPlugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ install(FILES ${HEADERS}
DESTINATION "${MR_INCLUDE_DIR}/${PROJECT_NAME}")

install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}Config.cmake
DESTINATION ${MR_MAIN_LIB_DIR}/cmake)
DESTINATION ${MR_CONFIG_DIR}/cmake)

install(FILES ${HEADERS} DESTINATION "${MR_INCLUDE_DIR}/${PROJECT_NAME}")
install(FILES ${UI_JSON} DESTINATION "${MR_RESOURCES_DIR}")
Expand All @@ -60,4 +60,4 @@ install(FILES ${ITEMS_JSON} DESTINATION "${MR_RESOURCES_DIR}")
install(EXPORT ${PROJECT_NAME}
FILE ${PROJECT_NAME}Targets.cmake
NAMESPACE MeshLib::
DESTINATION ${MR_MAIN_LIB_DIR}/cmake)
DESTINATION ${MR_CONFIG_DIR}/cmake)
7 changes: 4 additions & 3 deletions source/MRMesh/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ ELSE()
)
ENDIF()


set(CMAKE_INSTALL_PREFIX "/Library/Frameworks")
install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}
DESTINATION "${MR_MAIN_LIB_DIR}")
Expand All @@ -180,10 +180,11 @@ install(FILES ${HEADERS}
DESTINATION "${MR_INCLUDE_DIR}/${PROJECT_NAME}")

install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}Config.cmake
DESTINATION ${MR_MAIN_LIB_DIR}/cmake)
DESTINATION ${MR_CONFIG_DIR}/cmake)


install(EXPORT ${PROJECT_NAME}
FILE ${PROJECT_NAME}Targets.cmake
NAMESPACE MeshLib::
DESTINATION ${MR_MAIN_LIB_DIR}/cmake)
DESTINATION ${MR_CONFIG_DIR}/cmake)

8 changes: 8 additions & 0 deletions source/MRMesh/MRSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,11 @@ std::filesystem::path GetResourcesDirectory()
if ( std::find( exePath.begin(), exePath.end(), "build" ) != exePath.end() )
return exePath;
#ifdef __APPLE__
#ifdef MR_FRAMEWORK
return "/Library/Frameworks/" + std::string( MR_PROJECT_NAME ) + ".framework/Versions/Current/Resources/";
#else
return "/Applications/" + std::string( MR_PROJECT_NAME ) + ".app/Contents/Resources/";
#endif
#else
return "/usr/local/etc/" + std::string( MR_PROJECT_NAME ) + "/";
#endif
Expand Down Expand Up @@ -177,7 +181,11 @@ std::filesystem::path GetLibsDirectory()
if ( std::find( exePath.begin(), exePath.end(), "build" ) != exePath.end() )
return exePath;
#ifdef __APPLE__
#ifdef MR_FRAMEWORK
return "/Library/Frameworks/" + std::string( MR_PROJECT_NAME ) + ".framework/Versions/Current/lib/";
#else
return "/Applications/" + std::string( MR_PROJECT_NAME ) + ".app/Contents/libs/";
#endif
#else
return "/usr/local/lib/" + std::string( MR_PROJECT_NAME ) + "/";
#endif
Expand Down
4 changes: 2 additions & 2 deletions source/MRViewer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ install(FILES ${HEADERS}
DESTINATION "${MR_INCLUDE_DIR}/${PROJECT_NAME}")

install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}Config.cmake
DESTINATION ${MR_MAIN_LIB_DIR}/cmake)
DESTINATION ${MR_CONFIG_DIR}/cmake)

install(FILES ${HEADERS} DESTINATION "${MR_INCLUDE_DIR}/${PROJECT_NAME}")
install(FILES ${MAIN_FONTS} DESTINATION "${MR_FONTS_DIR}")
Expand All @@ -102,4 +102,4 @@ install(DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/resource DESTINATION "${MR_R
install(EXPORT ${PROJECT_NAME}
FILE ${PROJECT_NAME}Targets.cmake
NAMESPACE MeshLib::
DESTINATION ${MR_MAIN_LIB_DIR}/cmake)
DESTINATION ${MR_CONFIG_DIR}/cmake)
Loading

0 comments on commit 16beef1

Please sign in to comment.