-DBUILD_PORTABLE_LINUX for static linking against opencv and libc++

This gets us back to glibc 2.27 (ubuntu 18.04) -- debian stretch would
be nicer, but the default build tools (c++1x, cmake) gets slightly more
interesting.

The output binaries seem like they could be smaller...
This commit is contained in:
sz 2022-02-17 22:53:35 -06:00
parent 729eb7ebcb
commit 7bb1bc8896
2 changed files with 27 additions and 1 deletions

View File

@ -33,8 +33,17 @@ else() # if not wasm, go find opencv. 3 or 4 should both work
include_directories(${OpenCV_INCLUDE_DIRS})
endif()
if(DEFINED BUILD_PORTABLE_LINUX)
find_package(PkgConfig REQUIRED)
pkg_check_modules(OPENCV4 REQUIRED opencv4)
link_directories(${OPENCV4_STATIC_LIBRARY_DIRS})
# statically link c++/gcc (not libc!!)
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -static-libstdc++ -static-libgcc")
endif()
if(NOT DEFINED OPENCV_LIBS)
set(OPENCV_LIBS "opencv_calib3d" "opencv_imgcodecs" "opencv_imgproc" "opencv_photo" "opencv_core")
set(OPENCV_LIBS "opencv_calib3d" "opencv_imgcodecs" "opencv_imgproc" "opencv_photo" "opencv_core" ${OPENCV4_STATIC_LIBRARIES})
endif()
if(NOT DEFINED CPPFILESYSTEM)

17
package-portable-linux.sh Normal file
View File

@ -0,0 +1,17 @@
#!/bin/sh
# docker run --mount type=bind,source="$(pwd)",target="/usr/src/app" -it ubuntu:18.04
cd /usr/src/app
apt update
apt install -y pkgconf g++ cmake
apt install -y libgles2-mesa-dev libglfw3-dev
cd opencv4/
mkdir build-portable/ && cd build-portable/
cmake .. -DCMAKE_BUILD_TYPE=RELEASE -DBUILD_SHARED_LIBS=OFF -DOPENCV_GENERATE_PKGCONFIG=YES -DOPENCV_FORCE_3RDPARTY_BUILD=YES
make -j5 install
cd /usr/src/app
mkdir build-portable/ && cd build-portable/
cmake .. -DBUILD_PORTABLE_LINUX=1
make -j5 install