Skip to content

Commit

Permalink
init mac support
Browse files Browse the repository at this point in the history
  • Loading branch information
Fixstars-sam committed Dec 19, 2023
1 parent 3fa5b10 commit 0f1ad40
Show file tree
Hide file tree
Showing 22 changed files with 97 additions and 43 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/build*
__pycache__
.DS_Store
.vscode
19 changes: 17 additions & 2 deletions cmake/IonUtil.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,25 @@ function(ion_run NAME COMPILE_NAME)
COMMAND ${CMAKE_COMMAND} -E make_directory ${OUTPUT_PATH}
)
if (UNIX)
add_custom_command(OUTPUT ${HEADER} ${STATIC_LIB}
if(APPLE)
add_custom_command(OUTPUT ${HEADER} ${STATIC_LIB}
COMMAND ${CMAKE_SOURCE_DIR}/script/invoke.sh $<TARGET_FILE:${COMPILE_NAME}>
HL_TARGET ${IER_TARGET_STRING}
DYLD_LIBRARY_PATH ${Halide_DIR}/../../../bin
DYLD_LIBRARY_PATH ${CMAKE_BINARY_DIR}
DYLD_LIBRARY_PATH ${CMAKE_BINARY_DIR}/src/bb
DEPENDS ${COMPILE_NAME} ${OUTPUT_PATH}
WORKING_DIRECTORY ${OUTPUT_PATH})
else()
add_custom_command(OUTPUT ${HEADER} ${STATIC_LIB}
COMMAND ${CMAKE_SOURCE_DIR}/script/invoke.sh $<TARGET_FILE:${COMPILE_NAME}>
HL_TARGET ${IER_TARGET_STRING}
LD_LIBRARY_PATH ${Halide_DIR}/../../../bin
LD_LIBRARY_PATH ${CMAKE_BINARY_DIR}
LD_LIBRARY_PATH ${CMAKE_BINARY_DIR}/src/bb
DEPENDS ${COMPILE_NAME} ${OUTPUT_PATH}
WORKING_DIRECTORY ${OUTPUT_PATH})
endif()
else()
add_custom_command(OUTPUT ${HEADER} ${STATIC_LIB}
COMMAND ${CMAKE_SOURCE_DIR}/script/invoke.bat $<TARGET_FILE:${COMPILE_NAME}>
Expand Down Expand Up @@ -110,7 +121,11 @@ function(ion_register_test TEST_NAME EXEC_NAME)
cmake_parse_arguments(IERT "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

if (UNIX)
set(IERT_RUNTIME_ENVS "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/src/bb:${CMAKE_BINARY_DIR}/test")
if(APPLE)
set(IERT_RUNTIME_ENVS "DYLD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/src/bb:${CMAKE_BINARY_DIR}/test")
else()
set(IERT_RUNTIME_ENVS "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/src/bb:${CMAKE_BINARY_DIR}/test")
endif()
else()
set(IERT_RUNTIME_ENVS "PATH=${CMAKE_BINARY_DIR}/src/bb/$<$<CONFIG:Release>:Release>$<$<CONFIG:Debug>:Debug>\\\;${CMAKE_BINARY_DIR}/test/$<$<CONFIG:Release>:Release>$<$<CONFIG:Debug>:Debug>")
endif()
Expand Down
2 changes: 2 additions & 0 deletions example/u3v_camera1_opencv/u3v_camera1_opencv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ double exposure = 400;

#ifdef _WIN32
#define MODULE_NAME "ion-bb.dll"
#elif __APPLE__
#define MODULE_NAME "libion-bb.dylib"
#else
#define MODULE_NAME "libion-bb.so"
#endif
Expand Down
8 changes: 5 additions & 3 deletions example/u3v_camera1_opencv/u3v_camera1_opencv.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
import numpy as np
import cv2

import os
from sys import platform

feature_gain_key = 'Gain'
feature_exposure_key = 'ExposureTime'
num_bit_shift = 0

if os.name == 'nt':
if platform == "win32":
module_name = 'ion-bb.dll'
elif os.name == 'posix':
elif platform == "darwin":
module_name = 'libion-bb.dylib'
else:
module_name = 'libion-bb.so'

if __name__ == "__main__":
Expand Down
2 changes: 2 additions & 0 deletions example/u3v_camera2_opencv/u3v_camera2_opencv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ double exposure = 400;

#ifdef _WIN32
#define MODULE_NAME "ion-bb.dll"
#elif __APPLE__
#define MODULE_NAME "libion-bb.dylib"
#else
#define MODULE_NAME "libion-bb.so"
#endif
Expand Down
8 changes: 5 additions & 3 deletions example/u3v_camera2_opencv/u3v_camera2_opencv.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
import numpy as np
import cv2

import os
from sys import platform

feature_gain_key = 'Gain'
feature_exposure_key = 'ExposureTime'
num_bit_shift = 0

if os.name == 'nt':
if platform == "win32":
module_name = 'ion-bb.dll'
elif os.name == 'posix':
elif platform == "darwin":
module_name = 'libion-bb.dylib'
else:
module_name = 'libion-bb.so'

if __name__ == "__main__":
Expand Down
8 changes: 4 additions & 4 deletions src/bb/base/httplib.h
Original file line number Diff line number Diff line change
Expand Up @@ -1858,7 +1858,7 @@ socket_t create_socket(const char *host, int port, int socket_flags,
#endif
if (sock == INVALID_SOCKET) { continue; }

#ifndef _WIN32
#ifdef __unix__
if (fcntl(sock, F_SETFD, FD_CLOEXEC) == -1) { continue; }
#endif

Expand Down Expand Up @@ -3772,7 +3772,7 @@ inline Server::Server()
: new_task_queue(
[] { return new ThreadPool(CPPHTTPLIB_THREAD_POOL_COUNT); }),
svr_sock_(INVALID_SOCKET), is_running_(false) {
#ifndef _WIN32
#ifdef __unix__
signal(SIGPIPE, SIG_IGN);
#endif
}
Expand Down Expand Up @@ -4353,7 +4353,7 @@ inline bool Server::listen_internal() {
std::unique_ptr<TaskQueue> task_queue(new_task_queue());

while (svr_sock_ != INVALID_SOCKET) {
#ifndef _WIN32
#ifdef __unix__
if (idle_interval_sec_ > 0 || idle_interval_usec_ > 0) {
#endif
auto val = detail::select_read(svr_sock_, idle_interval_sec_,
Expand All @@ -4362,7 +4362,7 @@ inline bool Server::listen_internal() {
task_queue->on_idle();
continue;
}
#ifndef _WIN32
#ifdef __unix__
}
#endif
socket_t sock = accept(svr_sock_, nullptr, nullptr);
Expand Down
9 changes: 9 additions & 0 deletions src/bb/dnn/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,22 @@ set(LINK_DIRS
${OpenCV_DIR}/lib)

if (UNIX)
if (APPLE)
set(LIBRARIES
dl
pthread
m
z
${OpenCV_LIBRARIES})
else()
set(LIBRARIES
rt
dl
pthread
m
z
${OpenCV_LIBRARIES})
endif()
else()
set(LIBRARIES ${OpenCV_LIBRARIES})
endif()
8 changes: 4 additions & 4 deletions src/bb/dnn/httplib.h
Original file line number Diff line number Diff line change
Expand Up @@ -1858,7 +1858,7 @@ socket_t create_socket(const char *host, int port, int socket_flags,
#endif
if (sock == INVALID_SOCKET) { continue; }

#ifndef _WIN32
#ifdef __unix__
if (fcntl(sock, F_SETFD, FD_CLOEXEC) == -1) { continue; }
#endif

Expand Down Expand Up @@ -3772,7 +3772,7 @@ inline Server::Server()
: new_task_queue(
[] { return new ThreadPool(CPPHTTPLIB_THREAD_POOL_COUNT); }),
svr_sock_(INVALID_SOCKET), is_running_(false) {
#ifndef _WIN32
#ifdef __unix__
signal(SIGPIPE, SIG_IGN);
#endif
}
Expand Down Expand Up @@ -4353,7 +4353,7 @@ inline bool Server::listen_internal() {
std::unique_ptr<TaskQueue> task_queue(new_task_queue());

while (svr_sock_ != INVALID_SOCKET) {
#ifndef _WIN32
#ifdef __unix__
if (idle_interval_sec_ > 0 || idle_interval_usec_ > 0) {
#endif
auto val = detail::select_read(svr_sock_, idle_interval_sec_,
Expand All @@ -4362,7 +4362,7 @@ inline bool Server::listen_internal() {
task_queue->on_idle();
continue;
}
#ifndef _WIN32
#ifdef __unix__
}
#endif
socket_t sock = accept(svr_sock_, nullptr, nullptr);
Expand Down
2 changes: 1 addition & 1 deletion src/bb/dnn/onnxruntime_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace dnn {
#define ORT_API_VERSION 5

// SAL2 Definitions
#ifndef _WIN32
#if defined(__unix__) || defined(__APPLE__)
#define _In_
#define _In_z_
#define _In_opt_
Expand Down
6 changes: 6 additions & 0 deletions src/bb/fpga/config.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
if (UNIX)
if (APPLE)
set(LIBRARIES
dl
pthread)
else()
set(LIBRARIES
rt
dl
pthread)
endif()
endif()
8 changes: 4 additions & 4 deletions src/bb/image-io/bb.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define ION_BB_IMAGE_IO_BB_H

#include <ion/ion.h>
#ifndef _WIN32
#ifdef __unix__
#include <linux/videodev2.h>
#endif

Expand Down Expand Up @@ -60,7 +60,7 @@ const int BayerMap::bayer_map[4][4]{
{1, 2, 0, 1} // GBRG
};

#ifndef _WIN32
#ifdef __unix__
uint32_t make_pixel_format(BayerMap::Pattern bayer_pattern, int32_t bit_width)
{
uint32_t pix_format;
Expand Down Expand Up @@ -544,7 +544,7 @@ class GUIDisplay : public ion::BuildingBlock<GUIDisplay> {
}
};

#ifndef _WIN32
#ifdef __unix__
class FBDisplay : public ion::BuildingBlock<FBDisplay> {
public:
GeneratorParam<std::string> gc_title{"gc_title", "FBDisplay"};
Expand Down Expand Up @@ -1195,7 +1195,7 @@ class BinaryLoader : public ion::BuildingBlock<BinaryLoader> {
} // namespace bb
} // namespace ion

#ifndef _WIN32
#ifdef __unix__
ION_REGISTER_BUILDING_BLOCK(ion::bb::image_io::IMX219, image_io_imx219);
ION_REGISTER_BUILDING_BLOCK(ion::bb::image_io::D435, image_io_d435);

Expand Down
23 changes: 16 additions & 7 deletions src/bb/image-io/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,22 @@ set(INCLUDE_DIRS
set(LINK_DIRS
${OpenCV_DIR}/lib)

set(LIBRARIES
rt
dl
pthread
m
z
${OpenCV_LIBRARIES})
if (APPLE)
set(LIBRARIES
dl
pthread
m
z
${OpenCV_LIBRARIES})
else()
set(LIBRARIES
rt
dl
pthread
m
z
${OpenCV_LIBRARIES})
endif()
else()
# NOTE: Tentatively OpenCV is not supported in Windows release
endif()
8 changes: 4 additions & 4 deletions src/bb/image-io/httplib.h
Original file line number Diff line number Diff line change
Expand Up @@ -1858,7 +1858,7 @@ socket_t create_socket(const char *host, int port, int socket_flags,
#endif
if (sock == INVALID_SOCKET) { continue; }

#ifndef _WIN32
#ifdef __unix__
if (fcntl(sock, F_SETFD, FD_CLOEXEC) == -1) { continue; }
#endif

Expand Down Expand Up @@ -3772,7 +3772,7 @@ inline Server::Server()
: new_task_queue(
[] { return new ThreadPool(CPPHTTPLIB_THREAD_POOL_COUNT); }),
svr_sock_(INVALID_SOCKET), is_running_(false) {
#ifndef _WIN32
#ifdef __unix__
signal(SIGPIPE, SIG_IGN);
#endif
}
Expand Down Expand Up @@ -4353,7 +4353,7 @@ inline bool Server::listen_internal() {
std::unique_ptr<TaskQueue> task_queue(new_task_queue());

while (svr_sock_ != INVALID_SOCKET) {
#ifndef _WIN32
#ifdef __unix__
if (idle_interval_sec_ > 0 || idle_interval_usec_ > 0) {
#endif
auto val = detail::select_read(svr_sock_, idle_interval_sec_,
Expand All @@ -4362,7 +4362,7 @@ inline bool Server::listen_internal() {
task_queue->on_idle();
continue;
}
#ifndef _WIN32
#ifdef __unix__
}
#endif
socket_t sock = accept(svr_sock_, nullptr, nullptr);
Expand Down
2 changes: 1 addition & 1 deletion src/bb/image-io/rt.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class RegisterExtern {
#include "rt_u3v.h"
#include "rt_file.h"

#ifndef _WIN32
#ifdef __unix__
#include "rt_display.h"
#include "rt_realsense.h"
#include "rt_v4l2.h"
Expand Down
4 changes: 2 additions & 2 deletions src/bb/image-io/rt_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <unordered_map>
#include <vector>

#ifndef _WIN32
#ifdef __unix__
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#endif
Expand Down Expand Up @@ -154,7 +154,7 @@ std::tuple<std::string, std::string> parse_url(const std::string &url) {
return std::tuple<std::string, std::string>(host_name, path_name);
}

#ifndef _WIN32
#ifdef __unix__
cv::Mat get_image(const std::string &url) {
if (url.empty()) {
return {};
Expand Down
4 changes: 2 additions & 2 deletions src/bb/image-io/rt_display.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <stdexcept>

#ifndef _WIN32
#ifdef __unix__
#include <fcntl.h>
#include <linux/fb.h>
#include <sys/ioctl.h>
Expand All @@ -17,7 +17,7 @@

#include "rt_common.h"

#ifndef _WIN32
#ifdef __unix__
namespace {

class FBDev {
Expand Down
4 changes: 2 additions & 2 deletions src/bb/image-io/rt_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
#include "rt_common.h"
#include "httplib.h"

#ifndef _WIN32
#ifdef __unix__
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#endif

#ifndef _WIN32
#ifdef __unix__
extern "C" int ION_EXPORT ion_bb_image_io_color_data_loader(halide_buffer_t *session_id_buf, halide_buffer_t *url_buf, int32_t width, int32_t height, halide_buffer_t *out) {

using namespace ion::bb::image_io;
Expand Down
Loading

0 comments on commit 0f1ad40

Please sign in to comment.