libjpeg-turbo 命令行编译脚本(MinGW/MSVC/linux)

2019-05-25 22:24:36 浏览数 (1)

版权声明:本文为博主原创文章,转载请注明源地址。 https://cloud.tencent.com/developer/article/1433686

libjpeg-turbo用CMAKE命令行编译还是很方便的

编译libjpeg-turbo需要NASM支持,编译前请下载并正确安装。

代码语言:javascript复制
mkdir build
cd build
# 生成Makefile
cmake -G "MinGW Makefiles" 
    -DCMAKE_BUILD_TYPE=RELEASE 
    -DCMAKE_DEBUG_POSTFIX=_d 
    -DCMAKE_C_FLAGS=-m64 
    -DCMAKE_INSTALL_PREFIX=%安装路径% 
    ..
# 编译并安装到指定的路径
make install -j8

编译libjpeg-turbo 主要的一些可选项:

ENABLE_STATIC=FALSE 不编译静态库(默认为TRUE) ENABLE_SHARED=FALSE 不编译动态库(默认为TRUE) WITH_SIMD=FALSE 不支持SIMD指令(默认为TRUE),如果在虚拟机下编译,此选项要置为OFF

MinGW

完整脚本(build_jpeg_turbo_gcc.bat),该脚本自动判断当前gcc编译器的能力编译32/64位版本,执行脚本时如果带 DEBUG参数则编译DEBUG版,如:build_jpeg_turbo_gcc DEBUG,否则默认编译RELEASE版:

代码语言:javascript复制
@rem 根据%%1参数 编译DEBUG|RELEASE版本,默认RELEASE
@echo off 
echo build jpeg-turbo by MinGW
rem 判断是否安装了MinGW编译器,如果没有则报错退出
where gcc
if errorlevel 1 (
    echo MinGW/gcc NOT FOUND.
    exit -1
)
echo MinGW/gcc found.
rem 判断是否安装了cmake,如果没有则报错退出
where cmake
if errorlevel 1 (
    echo cmake NOT FOUND.
    echo download from http://cmake.org/ ,extract to disk 
    echo add installation path to environment variable PATH
    pause
    exit -1
)
echo cmake found.
rem 判断是否安装了nasm,如果没有则报错退出
where nasm
if errorlevel 1 (
    echo nasm NOT FOUND.
    echo download from https://www.nasm.us/ ,extract to disk 
    echo add installation path to environment variable PATH, version above 2.13.03 required.
    pause
    exit -1
)
echo nasm found.
set sh_folder=%~dp0
rem 定义编译的版本类型(DEBUG|RELEASE)
set build_type=RELEASE
rem 如果输入参数1为"DEBUG"(不区分大小写)则编译DEBUG版本
if /I "%1" == "DEBUG" ( set build_type=DEBUG) 
echo build_type=%build_type%

set source_folder=libjpeg-turbo-1.5.90
if not exist %source_folder% (
    echo not found source folder: %source_folder%,please unzip %source_folder%.zip in current folder
    pause
    exit -1
    )
pushd %sh_folder%%source_folder%
rem 判断是否能编译64位程序
gcc --version |findstr "sjlj seh"
if errorlevel 1 (
    echo unsupported x86_64 build
    )else call:gcc_x86_64

rem 判断是否能编译32位程序
gcc --version |findstr "sjlj dwarf"
if errorlevel 1 (
    echo unsupported x86 build  
    )else call:gcc_x86

goto :end
:gcc_x86
echo build x86 use MinGW 
if exist build_gcc_x86 rmdir build_gcc_x86 /s/q
mkdir build_gcc_x86
pushd build_gcc_x86
rem gcc SJLJ or DWARF distribution required

cmake -G "MinGW Makefiles" ^
    -DCMAKE_BUILD_TYPE=%build_type% ^
    -DCMAKE_DEBUG_POSTFIX=_d ^
    -DCMAKE_C_FLAGS=-m32 ^
    -DCMAKE_INSTALL_PREFIX=%sh_folder%/libjpeg-turbo-windows-gcc-x86 ^
    ..
make install -j8
popd
rmdir build_gcc_x86 /s/q
goto:eof

:gcc_x86_64
echo build x86_64 use MinGW 
if exist build_gcc_x86_64 rmdir build_gcc_x86_64 /s/q
mkdir build_gcc_x86_64
pushd build_gcc_x86_64
rem gcc SJLJ or SEH distribution required

cmake -G "MinGW Makefiles" ^
    -DCMAKE_BUILD_TYPE=%build_type% ^
    -DCMAKE_DEBUG_POSTFIX=_d ^
    -DCMAKE_C_FLAGS=-m64 ^
    -DCMAKE_INSTALL_PREFIX=%sh_folder%/libjpeg-turbo-windows-gcc-x86_64 ^
    ..
make install -j8
popd
rmdir build_gcc_x86_64 /s/q
goto:eof

:end
popd

build_jpeg_turbo_gcc.bat在gitee仓库的位置:

https://gitee.com/l0km/jpegwrapper/blob/master/dependencies/build_jpeg_turbo_gcc.bat

MSVC

MSVC编译脚本参见gitee仓库:

https://gitee.com/l0km/jpegwrapper/blob/master/dependencies/build_jpeg_turbo_msvc.bat

该脚本可以一次性自动编译生成32/64位以及/MT /MD的所有4版本(RELEASE)

这个目录下可以找到已经编译好的libjpeg-turbo的所有windows版本

https://gitee.com/l0km/jpegwrapper/blob/master/dependencies

执行该文件夹下的all_build_jpeg_turbo_msvc.bat,可以一次编译编译出debug/release版本。

Linux

linux下编译libjpeg-turbo的脚本:

https://gitee.com/l0km/jpegwrapper/blob/master/dependencies/build_jpeg_turbo.sh

0 人点赞