-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from tritonuas/feat/cmake-war
feat/cmake war
- Loading branch information
Showing
7 changed files
with
211 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,53 @@ | ||
FROM ubuntu:22.04 | ||
# https://gist.github.com/SSARCandy/fc960d8905330ac695e71e3f3807ce3d | ||
# OpenCV dependencies from above | ||
RUN apt-get update \ | ||
&& apt-get upgrade -y \ | ||
&& apt-get install -y build-essential \ | ||
gdb \ | ||
git \ | ||
cmake \ | ||
clang-tidy \ | ||
wget | ||
wget \ | ||
ccache \ | ||
vim | ||
# cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev | ||
# python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev | ||
|
||
# the official docs say also these | ||
# https://docs.opencv.org/4.x/d7/d9f/tutorial_linux_install.html | ||
# sudo apt update && sudo apt install -y cmake g++ wget unzip | ||
# xz? bzip2? | ||
|
||
# TODO: is it possible to save the built opencv in the docker build? Need to see what cmake keeps checking and wasting time on. | ||
|
||
RUN apt-get update \ | ||
&& rm -rf /var/lib/apt/lists/* \ | ||
&& wget https://github.com/Kitware/CMake/releases/download/v3.27.7/cmake-3.27.7-linux-x86_64.sh \ | ||
-q -O /tmp/cmake-install.sh \ | ||
&& chmod u+x /tmp/cmake-install.sh \ | ||
&& mkdir /opt/cmake-3.24.1 \ | ||
&& /tmp/cmake-install.sh --skip-license --prefix=/opt/cmake-3.24.1 \ | ||
&& rm /tmp/cmake-install.sh \ | ||
&& ln -s /opt/cmake-3.24.1/bin/* /usr/local/bin | ||
|
||
WORKDIR /obcpp | ||
|
||
COPY . /obcpp | ||
|
||
WORKDIR /obcpp/build | ||
|
||
# RUN cmake .. | ||
|
||
# RUN make obcpp # parallelize this | ||
|
||
CMD ["/bin/bash"] | ||
# CMD ["/obcpp/build/bin/obcpp"] | ||
|
||
# docker build - < Dockerfile | ||
# docker build -t "test" . | ||
# docker run -it --rm test | ||
|
||
# https://www.jmoisio.eu/en/blog/2020/06/01/building-cpp-containers-using-docker-and-cmake/ | ||
# find -name "*Cache.txt" -delete | ||
|
||
# TODO: this container is way too big for some reason. Refer to above blog post for staged build (may not want to do that for development tho. I am unable to get devcontainers running) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
include(FetchContent) | ||
|
||
# Fetch the main OpenCV repository | ||
FetchContent_Declare(OpenCV | ||
URL https://github.com/opencv/opencv/archive/refs/tags/4.8.1.tar.gz | ||
OVERRIDE_FIND_PACKAGE | ||
) | ||
|
||
# set( OPENCV_EXTRA_MODULES_PATH ${OpenCV_SOURCE_DIR}/../opencvcontrib-src/modules) | ||
# Fetch the OpenCV contrib repository | ||
FetchContent_Declare(OpenCVContrib | ||
URL https://github.com/opencv/opencv_contrib/archive/refs/tags/4.8.1.tar.gz | ||
# SOURCE_DIR "${CMAKE_BINARY_DIR}/opencv_contrib-src" # Specify a separate source directory | ||
# PREFIX "${CMAKE_BINARY_DIR}/opencv_contrib-prefix" # Specify a separate prefix directory | ||
) | ||
|
||
# Make both OpenCV and OpenCV contrib available | ||
FetchContent_MakeAvailable(OpenCV OpenCVContrib) | ||
|
||
# Find OpenCV | ||
find_package(OpenCV REQUIRED COMPONENTS core imgproc highgui features2d flann dnn imgcodecs videoio imgproc ml) | ||
set(OpenCV_INCLUDE_DIRS ${OpenCV_SOURCE_DIR}/include ) | ||
# file(GLOB_RECURSE HEADERS "${OpenCV_SOURCE_DIR}/modules/**/*.hpp") | ||
# Add OpenCV's contrib modules to the target | ||
target_link_libraries(${PROJECT_NAME} PRIVATE ${OpenCV_LIBS} opencv_core opencv_highgui opencv_features2d opencv_flann opencv_imgcodecs opencv_dnn opencv_videoio opencv_imgproc opencv_ml ) | ||
|
||
# Specify include directories, including OpenCV's contrib | ||
target_include_directories(${PROJECT_NAME} PRIVATE | ||
${OpenCV_INCLUDE_DIRS} | ||
${OpenCVContrib_SOURCE_DIR}/modules # Include contrib modules | ||
${OPENCV_CONFIG_FILE_INCLUDE_DIR} | ||
${OPENCV_MODULE_opencv_core_LOCATION}/include | ||
${OPENCV_MODULE_opencv_highgui_LOCATION}/include | ||
${OPENCV_MODULE_opencv_features2d_LOCATION}/include | ||
|
||
${OPENCV_MODULE_opencv_flann_LOCATION}/include | ||
${OPENCV_MODULE_opencv_imgcodecs_LOCATION}/include | ||
${OPENCV_MODULE_opencv_dnn_LOCATION}/include | ||
${OPENCV_MODULE_opencv_videoio_LOCATION}/include | ||
${OPENCV_MODULE_opencv_imgproc_LOCATION}/include | ||
${OPENCV_MODULE_opencv_ml_LOCATION}/include | ||
# ${HEADERS} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
include(FetchContent) | ||
Set(FETCHCONTENT_QUIET FALSE) | ||
|
||
FetchContent_Declare(Torch | ||
URL https://download.pytorch.org/libtorch/cpu/libtorch-cxx11-abi-shared-with-deps-2.1.0%2Bcpu.zip | ||
) | ||
# URL https://download.pytorch.org/libtorch/nightly/cpu/libtorch-shared-with-deps-latest.zip | ||
|
||
FetchContent_MakeAvailable(Torch) | ||
|
||
# message(FATAL_ERROR ${torch_SOURCE_DIR}) | ||
# set(Torch_DIR "${CMAKE_BINARY_DIR}/_deps/torch-src/share/cmake/Torch/") | ||
find_package(Torch REQUIRED HINTS "${torch_SOURCE_DIR}") | ||
|
||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}") | ||
|
||
# message(FATAL_ERROR ${TORCH_INCLUDE_DIRS}) | ||
target_link_libraries(${PROJECT_NAME} PRIVATE | ||
"${TORCH_LIBRARIES}" | ||
) | ||
target_include_directories(${PROJECT_NAME} PRIVATE ${TORCH_INCLUDE_DIRS}) | ||
|
||
# find_package(Torch REQUIRED) | ||
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}") | ||
|
||
# add_executable(example-app example-app.cpp) | ||
# target_link_libraries(example-app "${TORCH_LIBRARIES}") | ||
# set_property(TARGET example-app PROPERTY CXX_STANDARD 17) | ||
|
||
|
||
|
||
# add_executable(example-app example-app.cpp) | ||
# target_link_libraries(example-app "${TORCH_LIBRARIES}") | ||
# set_property(TARGET example-app PROPERTY CXX_STANDARD 17) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,38 @@ | ||
{ pkgs ? import <nixpkgs> {} }: | ||
{pkgs ? import <nixpkgs> {}}: | ||
(pkgs.buildFHSUserEnv { | ||
name = "OBCPP"; | ||
targetPkgs = pkgs: (with pkgs; [ | ||
python3 | ||
ccache | ||
# ninja | ||
# pipenv | ||
|
||
pkgs.mkShell { | ||
buildInputs = [ | ||
pkgs.gcc | ||
pkgs.cmake | ||
pkgs.libclang | ||
]; | ||
} | ||
# LSP | ||
# python39Packages.python-lsp-server | ||
|
||
# C deps | ||
glib | ||
glibc | ||
stdenv | ||
zlib | ||
|
||
gcc | ||
cmake | ||
libclang | ||
xz | ||
bzip2 | ||
|
||
]); | ||
runScript = "bash"; | ||
profile = '' | ||
LD_LIBRARY_PATH=${pkgs.zlib}/lib:${pkgs.bzip2}/lib:$LD_LIBRARY_PATH | ||
# set SOURCE_DATE_EPOCH so that we can use python wheels | ||
SOURCE_DATE_EPOCH=$(date +%s) | ||
PATH=$HOME/.local/bin:$PATH | ||
# PYTHONPATH=$HOME/.local/lib/python3.9/site-packages:$PYTHONPATH | ||
# export PIP_PREFIX=$(pwd)/_build/pip_packages | ||
# export PYTHONPATH="$PIP_PREFIX/${pkgs.python3.sitePackages}:$PYTHONPATH" | ||
# export PATH="$PIP_PREFIX/bin:$PATH" | ||
# unset SOURCE_DATE_EPOCH | ||
''; | ||
}).env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters