Skip to content

Instantly share code, notes, and snippets.

@jungin500
Last active April 10, 2023 08:58
Show Gist options
  • Save jungin500/7c33012a9395ee3f7f69279894344a74 to your computer and use it in GitHub Desktop.
Save jungin500/7c33012a9395ee3f7f69279894344a74 to your computer and use it in GitHub Desktop.
[macOS] Installing older version of NCNN (20210720) on Ventura
#!/bin/bash
# Install NCNN with OpenMP, OpenCV, Vulkan
# Reference: https://github.com/actions/runner-images/issues/5555#issuecomment-1133906879
## Install homebrew requirements
brew install libomp protobuf
## OpenCV 3.x is recommended for examples installation
brew install opencv@3
export PATH="/opt/homebrew/opt/opencv@3/bin:$PATH"
# Below are copied and modified slightly
# from: https://github.com/Tencent/ncnn/wiki/how-to-build#build-for-macos
## Install Vulkan SDK
wget https://sdk.lunarg.com/sdk/download/1.2.189.0/mac/vulkansdk-macos-1.2.189.0.dmg?Human=true -O vulkansdk-macos-1.2.189.0.dmg
hdiutil attach vulkansdk-macos-1.2.189.0.dmg
sudo /Volumes/vulkansdk-macos-1.2.189.0/InstallVulkan.app/Contents/MacOS/InstallVulkan --root `pwd`/vulkansdk-macos-1.2.189.0 --accept-licenses --default-answer --confirm-command install
hdiutil detach /Volumes/vulkansdk-macos-1.2.189.0
export VULKAN_SDK=`pwd`/vulkansdk-macos-1.2.189.0/macOS
## Build flag
cd <ncnn-root-dir>
mkdir -p build
cd build
### -DOpenMP... flags are mandatory,
### as cmake won't find libomp installed with homebrew.
cmake -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" \
-DVulkan_INCLUDE_DIR="$VULKAN_SDK/MoltenVK/include" \
-DVulkan_LIBRARY="$VULKAN_SDK/MoltenVK/dylib/macOS/libMoltenVK.dylib" \
-DOpenMP_C_FLAGS="-Xclang -fopenmp -I/opt/homebrew/opt/libomp/include" \
-DOpenMP_C_LIB_NAMES=libomp \
-DOpenMP_CXX_FLAGS="-Xclang -fopenmp -I/opt/homebrew/opt/libomp/include" \
-DOpenMP_CXX_LIB_NAMES=libomp \
-DOpenMP_libomp_LIBRARY=/opt/homebrew/opt/libomp/lib/libomp.dylib \
-DNCNN_VULKAN=ON -DNCNN_BUILD_EXAMPLES=ON ..
cmake --build . -j 3
cmake --build . --target install
@jungin500
Copy link
Author

Fixed OpenMP_libomp_LIBRARY which couldn't find libomp.dylib during linking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment