diff --git a/.github/workflows/linux-x86-cpu-gcc.yml b/.github/workflows/linux-x86-cpu-gcc.yml index a81c28e..7244b2b 100644 --- a/.github/workflows/linux-x86-cpu-gcc.yml +++ b/.github/workflows/linux-x86-cpu-gcc.yml @@ -31,17 +31,17 @@ jobs: - name: update run: sudo apt update - name: install_dep - run: sudo apt install libgtk2.0-dev + run: sudo apt install libgtk2.0-dev libva-dev - name: install_conan run: | pip3 install conan conan profile detect --force - name: build run: | - mkdir build + conan graph info . conan install . --build=missing -pr:h=docker/x86_gcc_profile - cd build + cd build_Linux cmake .. make -j 2 - name: test - run: cd build && make test \ No newline at end of file + run: cd build_Linux && make test \ No newline at end of file diff --git a/.github/workflows/macos-x86-cpu-clang.yml b/.github/workflows/macos-x86-cpu-clang.yml index 2c69d1d..514c1a4 100644 --- a/.github/workflows/macos-x86-cpu-clang.yml +++ b/.github/workflows/macos-x86-cpu-clang.yml @@ -42,10 +42,9 @@ jobs: - name: build run: | rm /usr/local/Cellar/cmake/3.27.3/share/cmake/Modules/Findprotobuf.cmake - mkdir build conan install . --build=missing - cd build + cd build_Macos cmake .. make -j 2 - name: test - run: cd build && make test \ No newline at end of file + run: cd build_Macos && make test \ No newline at end of file diff --git a/.github/workflows/windows-x86-cpu-msvc.yml b/.github/workflows/windows-x86-cpu-msvc.yml index 9d6e1b6..b0a470a 100644 --- a/.github/workflows/windows-x86-cpu-msvc.yml +++ b/.github/workflows/windows-x86-cpu-msvc.yml @@ -36,10 +36,9 @@ jobs: - name: build run: | rm 'C:/Program Files/CMake/share/cmake-3.27/Modules/FindProtobuf.cmake' - mkdir build conan install . --build=missing -pr:h=docker/x86_msvc_profile - cd build + cd build_Windows cmake .. cmake --build . --config Release - name: test - run: cd build && ctest \ No newline at end of file + run: cd build_Windows && ctest \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index ec8bfb5..de09810 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,6 +30,10 @@ option(BUILD_PYTHON "build python bindings" OFF) option(BUILD_GRAPH_ONLY "only build graph module" OFF) option(BUILD_EXAMPLES "build examples " ON) option(ENABLE_RTTI "enable rtti " ON) +if (ANDROID) +include_directories($ENV{ANDROID_NDK_HOME}/sources/android) +add_definitions(-DMEDIAPIPE_MOBILE) +endif() if(USE_CCACHE AND NOT MSVC) find_program(CCACHE_EXE ccache) if(CCACHE_EXE ) diff --git a/README.md b/README.md index 75c7012..30c05b2 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,9 @@ Builds the mediapipe graph module using cmake, conan, and allows conan packaging for various graphing tasks. +## Change Log +* 2023/08/30 supports building on [Mac](.github/workflows/macos-x86-cpu-clang.yml), [Linux](.github/workflows/linux-x86-cpu-gcc.yml), [Windows](doc/build_with_msvc.md), [Android](doc/build_with_ndk.md) + ## Quick Start 1. Build the Docker image ```bash @@ -145,10 +148,8 @@ I20230721 17:08:09.525879 140015 hello_world.cc:57] Hello World! I20230721 17:08:09.525885 140015 hello_world.cc:57] Hello World! I20230721 17:08:09.525892 140015 hello_world.cc:57] Hello World! ``` -Building with MSVC on windows, please refer to [BuildWithMSVC](./doc/build_with_msvc.md) ## TODO List * [ ] Clean up redundant code step by step -* [ ] Use docker/conan to support multi-platform compilation. * [ ] Add doc, CI, CD, CT, code formatting checking and other related processes. * [ ] Improve tutorials and code examples * [ ] Add pipieline test benchmark. diff --git a/conanfile.py b/conanfile.py index 842f2a2..a58ceff 100644 --- a/conanfile.py +++ b/conanfile.py @@ -39,9 +39,18 @@ def config_options(self): del self.options.fPIC def configure(self): - self.options["glog"].with_unwind=False if self.options.shared: self.options.rm_safe("fPIC") + self.options['glog'].with_unwind = False + self.options["opencv/*"].with_gtk = False + self.options["opencv/*"].with_vulkan = False + self.options["opencv/*"].with_ffmpeg = False + self.options["opencv/*"].gapi = False + self.options["opencv/*"].objdetect = False + self.options["opencv/*"].photo = False + self.options["opencv/*"].dnn = False + self.options["opencv/*"].optflow = True + self.options["opencv/*"].ximgproc = True @property def _min_cppstd(self): return "14" @@ -62,15 +71,15 @@ def validate(self): def layout(self): cmake_layout(self) - self.folders.generators = 'build' + self.folders.generators = f'build_{self.settings.os}' def requirements(self): self.requires("abseil/20230125.1", visible=True) - self.requires("protobuf/3.17.1", visible=True) + self.requires("protobuf/3.21.12", visible=True) self.requires("glog/0.5.0", visible=True) self.test_requires("gtest/1.13.0") self.test_requires("zlib/1.2.13") - self.test_requires("opencv/3.4.12") + self.test_requires("opencv/4.5.5") self.test_requires("tensorflow-lite/2.10.0") self.test_requires("cpuinfo/cci.20220228") self.test_requires("pybind11/2.10.1") @@ -86,6 +95,8 @@ def generate(self): tc.variables["BUILD_PYTHON"] = False tc.variables["BUILD_EXAMPLES"] = False tc.variables['BUILD_GRAPH_ONLY'] = True + if self.settings.os == 'Android': + tc.variables['BUILD_PROTO_FILES'] = False if self.options.enable_rtti: tc.variables['ENABLE_RTTI'] = True else: diff --git a/doc/build_with_ndk.md b/doc/build_with_ndk.md new file mode 100644 index 0000000..da04704 --- /dev/null +++ b/doc/build_with_ndk.md @@ -0,0 +1,32 @@ +## Build with NDK for android + +1. setup ndk + * download and unzip android ndk package (we have tested with ndk v22b) + * set 'export ANDROID_NDK_HOME=Your NDK root dir' to your .bashrc or .zshrc +2. cross-build + * generate protobuf cpp files with your host profile(Linux, Mac or Windows) + * `cp mediapipe/framework/stream_handler/default_input_stream_handler.pb.cc test_package` + * `conan create . -pr docker/ndk_profile --build=missing` +3. test + * copy the generated 'example' file in test_package to you android deivce's '/data/local/tmp' + * just run it and the results will be like bellow: + ``` bash + c2q:/data/local/tmp $ ./example + I20230831 13:39:44.527252 16470 example.cc:39] node { + calculator: "SquareIntCalculator" + input_stream: "in" + output_stream: "out" + } + input_stream: "in" + output_stream: "out" + I20230831 13:39:44.532116 16470 example.cc:55] 0 + I20230831 13:39:44.532189 16470 example.cc:55] 1 + I20230831 13:39:44.532212 16470 example.cc:55] 4 + I20230831 13:39:44.532227 16470 example.cc:55] 9 + I20230831 13:39:44.532239 16470 example.cc:55] 16 + I20230831 13:39:44.532253 16470 example.cc:55] 25 + I20230831 13:39:44.532266 16470 example.cc:55] 36 + I20230831 13:39:44.532279 16470 example.cc:55] 49 + I20230831 13:39:44.532290 16470 example.cc:55] 64 + I20230831 13:39:44.532302 16470 example.cc:55] 81 + ``` \ No newline at end of file diff --git a/docker/ndk_profile b/docker/ndk_profile index 08a9971..178a148 100644 --- a/docker/ndk_profile +++ b/docker/ndk_profile @@ -7,10 +7,6 @@ compiler=clang compiler.libcxx=c++_static compiler.cppstd=17 compiler.version=12 -[tool_requires] -[options] -[env] -CONAN_CMAKE_TOOLCHAIN_FILE=/opt/android-ndk/build/cmake/android.toolchain.cmake [conf] tools.system.package_manager:mode=install -tools.android:ndk_path=/opt/android-ndk \ No newline at end of file +tools.android:ndk_path=$ENV{ANDROID_NDK_HOME} \ No newline at end of file diff --git a/mediapipe/framework/CMakeLists.txt b/mediapipe/framework/CMakeLists.txt index 381e289..21ceed3 100644 --- a/mediapipe/framework/CMakeLists.txt +++ b/mediapipe/framework/CMakeLists.txt @@ -1,5 +1,4 @@ add_library(graph - ${CMAKE_CURRENT_SOURCE_DIR}/timestamp.cc ${CMAKE_CURRENT_SOURCE_DIR}/basic_types_registration.cc ${CMAKE_CURRENT_SOURCE_DIR}/calculator.pb.cc @@ -63,8 +62,12 @@ ${CMAKE_CURRENT_SOURCE_DIR}/tool/packet_generator_wrapper_calculator.pb.cc ${CMAKE_CURRENT_SOURCE_DIR}/tool/simulation_clock.cc ${CMAKE_CURRENT_SOURCE_DIR}/tool/simulation_clock_executor.cc ${PROJECT_SOURCE_DIR}/mediapipe/util/cpu_util.cc -#/opt/android-ndk/sources/android/cpufeatures/cpu-features.c ) +if (ANDROID) +target_sources(graph PRIVATE +$ENV{ANDROID_NDK_HOME}/sources/android/cpufeatures/cpu-features.c +) +endif() add_subdirectory(api2) add_subdirectory(deps) if(ENABLE_PROFILER) diff --git a/mediapipe/util/cpu_util.cc b/mediapipe/util/cpu_util.cc index 2750f4f..c7c1c7c 100644 --- a/mediapipe/util/cpu_util.cc +++ b/mediapipe/util/cpu_util.cc @@ -17,7 +17,7 @@ #include #ifdef __ANDROID__ -#include "/opt/android-ndk/sources/android/cpufeatures/cpu-features.h" +#include "cpufeatures/cpu-features.h" #elif _WIN32 #include #else diff --git a/test_package/conanfile.py b/test_package/conanfile.py index 41a57a0..7603682 100644 --- a/test_package/conanfile.py +++ b/test_package/conanfile.py @@ -17,7 +17,7 @@ def generate(self): def requirements(self): self.requires(self.tested_reference_str) self.requires("abseil/20230125.1", visible=True) - self.requires("protobuf/3.17.1", visible=True) + self.requires("protobuf/3.21.12", visible=True) self.requires("glog/0.5.0", visible=True) def build(self):