diff --git a/CMakeLists.txt b/CMakeLists.txt index fa5df8ff..f99ecfe6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ FATAL: In-source builds are not allowed. endif() -cmake_minimum_required(VERSION 3.10) +cmake_minimum_required(VERSION 3.13) set(CMAKE_CXX_COMPILER g++) @@ -31,22 +31,25 @@ add_executable(${PROJECT_NAME} ${SOURCES}) # ============================= # Libraries -# NOTE: add each library's include directory to clang-tidy in the Linting section -add_subdirectory(deps/json) -target_link_libraries(${PROJECT_NAME} - PRIVATE - nlohmann_json::nlohmann_json -) +set(DEPS_DIRECTORY ${PROJECT_SOURCE_DIR}/deps) + +add_subdirectory(${DEPS_DIRECTORY}/arena-sdk) +add_subdirectory(${DEPS_DIRECTORY}/json) # ============================= # ============================= # Unit tests add_subdirectory(tests) -add_subdirectory(deps/google-test) +add_subdirectory(${DEPS_DIRECTORY}/google-test) # ============================= # ============================= # Linting +get_target_property(PROJECT_LIBS_INCLUDE_DIRS ${PROJECT_NAME} INCLUDE_DIRECTORIES) +foreach(dir ${PROJECT_LIBS_INCLUDE_DIRS}) + string(APPEND LIB_INCLUDE_CLANG_TIDY_STRING "-I${dir};") +endforeach() + # Adding lint target if clang-tidy executable is found find_program(CLANG_TIDY "clang-tidy") if(CLANG_TIDY) @@ -58,8 +61,10 @@ if(CLANG_TIDY) -- -std=c++${CMAKE_CXX_STANDARD} -I${INCLUDE_DIRECTORY} - # NOTE: need to add include directory for every library - -I./_deps/json-src/include/ + # NOTE:might need to add include directory if library's + # include directory is not in LIB_INCLUDE_CLANG_TIDY_STRING + -I${CMAKE_BINARY_DIR}/_deps/json-src/single_include + ${LIB_INCLUDE_CLANG_TIDY_STRING} ) else() message(FATAL_ERROR "clang-tidy executable not found. Check the README for steps to install it on your system") diff --git a/Dockerfile b/Dockerfile index 4d8ebec9..083b4e60 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,4 +5,5 @@ RUN apt-get update \ gdb \ git \ cmake \ - clang-tidy + clang-tidy \ + wget \ No newline at end of file diff --git a/deps/arena-sdk/CMakeLists.txt b/deps/arena-sdk/CMakeLists.txt new file mode 100644 index 00000000..9fbbef47 --- /dev/null +++ b/deps/arena-sdk/CMakeLists.txt @@ -0,0 +1,31 @@ +if(UNIX AND NOT APPLE) + set(ARENA_SDK_DIR "${CMAKE_BINARY_DIR}/_deps/arena-sdk") + set(INSTALL_SCRIPT "${PROJECT_SOURCE_DIR}/deps/arena-sdk/install-arena.sh") + + # run install script with output directory as argument + execute_process( + COMMAND sh ${INSTALL_SCRIPT} ${ARENA_SDK_DIR} + RESULT_VARIABLE ret + ) + if(ret EQUAL "0") + # Add a preprocessor macro that will enable us to compile + # functionality that depends on the Arena SDK. + target_compile_definitions(${PROJECT_NAME} PRIVATE + ARENA_SDK_INSTALLED + ) + else() + message(FATAL_ERROR "Unable to install Arena-SDK. ${INSTALL_SCRIPT} script exited with code ${ret}.") + endif() + + target_include_directories(${PROJECT_NAME} PRIVATE + "${ARENA_SDK_DIR}/extracted/include/Arena" + "${ARENA_SDK_DIR}/extracted/GenICam/library/CPP/include" + ) + file(GLOB_RECURSE ARENA_LIBS + "${ARENA_SDK_DIR}/extracted/lib64/*.so" + "${ARENA_SDK_DIR}/extracted/ffmpeg/*.so" + ) + target_link_libraries(${PROJECT_NAME} PRIVATE + ${ARENA_LIBS} + ) +endif() diff --git a/deps/arena-sdk/install-arena.sh b/deps/arena-sdk/install-arena.sh new file mode 100755 index 00000000..e51bd130 --- /dev/null +++ b/deps/arena-sdk/install-arena.sh @@ -0,0 +1,64 @@ +#!/bin/sh + +set -e + +PKGS_DIR=$1 + +if [ ! "$PKGS_DIR" ]; then + echo "ERROR: Could not install Arena SDK. Did not specify installation directory. Must provide installation directory as an argument" + exit 1 +fi + +mkdir -p "$PKGS_DIR" + +ARCH=`uname -m` +OS=`uname` + +echo "Installing Arena SDK for $ARCH on $OS to $PKGS_DIR" +if [ $OS != "Linux" ]; then + echo "ERROR: Arena SDK can only be installed on Linux" + exit 1 +else + # pull Arena SDK from TUAS Google Drive + # https://drive.google.com/drive/folders/1Ek1luFtO-FpDUJHP9_NQ9RH5dYhyhWXi?usp=share_link + if [ $ARCH = "aarch64" ]; then + FILE_NAME="ArenaSDK_v0.1.49_Linux_ARM64.tar.gz" + FILE_ID="1VtBji-cWfetM5nXZwt55JuHPWPGahQOH" + ARENA_SDK_DIR="ArenaSDK_Linux_ARM64" + ARENA_CONF="Arena_SDK_ARM64.conf" + elif [ $ARCH = "x86_64" ]; then + FILE_NAME="ArenaSDK_v0.1.68_Linux_x64.tar.gz" + FILE_ID="1pQtheOK-f2N4C2CDi43HTqttGuxHKptg" + ARENA_SDK_DIR="ArenaSDK_Linux_x64" + ARENA_CONF="Arena_SDK_Linux_x64.conf" + else + echo "ERROR: Unable to install Arena-SDK. Unkown architecture $ARCH. Architecture must be aarch64 or x86_64." + exit 1 + fi; + + if [ ! -d "$PKGS_DIR/$ARENA_SDK_DIR" ]; then \ + # Check that wget is installed + if ! command -v wget > /dev/null; then \ + echo "ERROR: Unable to install Arena-SDK. wget is not installed. Install wget for your system and retry." + exit 1 + fi; + + # Check that tar is installed + if ! command -v tar > /dev/null; then \ + echo "ERROR: Unable to install Arena-SDK. tar is not installed. Install tar for your system and retry." + exit 1 + fi; + + # This command is kinda crazy to bypass Google drive's virus scanning warning for large files https://medium.com/@acpanjan/download-google-drive-files-using-wget-3c2c025a8b99 + wget --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate "https://docs.google.com/uc?export=download&id=$FILE_ID" -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p')&id=$FILE_ID" -O "$PKGS_DIR/$FILE_NAME" && rm -rf /tmp/cookies.txt + tar xf "$PKGS_DIR/$FILE_NAME" --directory="$PKGS_DIR" + else \ + echo "WARNING: Arena SDK is already installed at $PKGS_DIR/$ARENA_SDK_DIR. Will not download again."; \ + fi; + + # Symlink arch specific arena install to architecture agnostic directory. + # Build system can point to this folder without knowing which architecture to use. + SYMLINKED_DIR="$PKGS_DIR/extracted" + echo "Symlinking $ARENA_SDK_DIR to $SYMLINKED_DIR" + ln -sf "$PKGS_DIR/$ARENA_SDK_DIR" "$SYMLINKED_DIR" +fi; diff --git a/deps/json/CMakeLists.txt b/deps/json/CMakeLists.txt index 16428350..f563a301 100644 --- a/deps/json/CMakeLists.txt +++ b/deps/json/CMakeLists.txt @@ -7,4 +7,8 @@ FetchContent_Declare(json GIT_SHALLOW TRUE GIT_TAG v3.11.2) -FetchContent_MakeAvailable(json) \ No newline at end of file +FetchContent_MakeAvailable(json) + +target_link_libraries(${PROJECT_NAME} PRIVATE + nlohmann_json::nlohmann_json +) diff --git a/include/camera/lucid.hpp b/include/camera/lucid.hpp index ec61b252..64bdf4a0 100644 --- a/include/camera/lucid.hpp +++ b/include/camera/lucid.hpp @@ -1,10 +1,14 @@ #ifndef CAMERA_LUCID_HPP_ #define CAMERA_LUCID_HPP_ +#ifdef ARENA_SDK_INSTALLED + #include "interface.hpp" class LucidCamera : public CameraInterface { // override all the camera connection interface functions }; -#endif // CAMERA_LUCID_HPP_ \ No newline at end of file +#endif // ARENA_SDK_INSTALLED + +#endif // CAMERA_LUCID_HPP_