Skip to content

Commit

Permalink
Build libwebp with CMake
Browse files Browse the repository at this point in the history
- Remove static libwebp CMake build script
- Fix an install_name_tool invocation for libwebp
  • Loading branch information
encelo committed Mar 10, 2024
1 parent 829be03 commit e5875a9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 77 deletions.
4 changes: 0 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ cmake_minimum_required(VERSION 3.12)
project(nCine-libraries)

option(BUILD_WEBP "Build the WebP library" ON)
option(BUILD_WEBP_STATIC "Build the static version of the WebP library" OFF)
option(BUILD_PNG "Build the zlib and the PNG library" ON)
option(BUILD_GLEW "Build the GLEW library" ON)
option(BUILD_GLFW "Build the GLFW library" ON)
Expand Down Expand Up @@ -56,9 +55,6 @@ ProcessorCount(CPUS)
if(BUILD_WEBP)
include(webp)
endif()
if(BUILD_WEBP AND BUILD_WEBP_STATIC)
include(webp_static)
endif()
if(BUILD_PNG)
include(zlib)
include(png)
Expand Down
58 changes: 19 additions & 39 deletions cmake/webp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,22 @@ set(URL_MD5_WEBP 34869086761c0e2da6361035f7b64771)
set(LIBNAME_WEBP libwebp)
set(LIBNAME_SHARPYUV libsharpyuv)
set(LIBNAME_WEBPDECODER libwebpdecoder)
set(LIBNAME_WEBP_IMPLIB libwebp_dll) # for dynamic linking
set(LIBNAME_SHARPYUV_IMPLIB libsharpyuv_dll) # for dynamic linking
set(LIBNAME_WEBPDECODER_IMPLIB libwebpdecoder_dll) # for dynamic linking
set(PROJECT_SRC_WEBP ${EP_BASE}/Source/project_${TARGET_WEBP})
set(COMMON_CMAKE_ARGS_WEBP -DWEBP_BUILD_ANIM_UTILS=OFF -DWEBP_BUILD_CWEBP=OFF -DWEBP_BUILD_DWEBP=OFF -DWEBP_BUILD_GIF2WEBP=OFF -DWEBP_BUILD_IMG2WEBP=OFF -DWEBP_BUILD_VWEBP=OFF -DWEBP_BUILD_WEBPINFO=OFF -DWEBP_BUILD_LIBWEBPMUX=OFF -DWEBP_BUILD_WEBPMUX=OFF -DWEBP_BUILD_EXTRAS=OFF)

if(MSVC)
if(CMAKE_CL_64)
set(ARCH_WEBP "x64")
else()
set(ARCH_WEBP "x86")
endif()

set(CONFIG_WEBP release-dynamic)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CONFIG_WEBP debug-dynamic)
set(LIBNAME_WEBP libwebp_debug)
set(LIBNAME_SHARPYUV libsharpyuv_debug)
set(LIBNAME_WEBPDECODER libwebpdecoder_debug)
set(LIBNAME_WEBP_IMPLIB libwebp_debug_dll)
set(LIBNAME_SHARPYUV_IMPLIB libsharpyuv_debug_dll)
set(LIBNAME_WEBPDECODER_IMPLIB libwebpdecoder_debug_dll)
endif()
set(OBJDIR_WEBP ${EP_BASE}/Source/project_${TARGET_WEBP}/${CONFIG_WEBP}/${CMAKE_VS_PLATFORM_NAME})

ExternalProject_Add(project_${TARGET_WEBP}
URL ${URL_WEBP}
URL_MD5 ${URL_MD5_WEBP}
CONFIGURE_COMMAND ""
BUILD_COMMAND nmake /f Makefile.vc ARCH=${ARCH_WEBP} CFG=${CONFIG_WEBP} OBJDIR=.
BUILD_IN_SOURCE 1
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_if_different ${OBJDIR_WEBP}/bin/${LIBNAME_WEBP}.dll ${BINDIR}/
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${OBJDIR_WEBP}/bin/${LIBNAME_SHARPYUV}.dll ${BINDIR}/
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${OBJDIR_WEBP}/bin/${LIBNAME_WEBPDECODER}.dll ${BINDIR}/
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${OBJDIR_WEBP}/lib/${LIBNAME_WEBP_IMPLIB}.lib ${LIBDIR}/
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${OBJDIR_WEBP}/lib/${LIBNAME_SHARPYUV_IMPLIB}.lib ${LIBDIR}/
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${OBJDIR_WEBP}/lib/${LIBNAME_WEBPDECODER_IMPLIB}.lib ${LIBDIR}/
CMAKE_ARGS ${COMMON_CMAKE_ARGS_WEBP} -DBUILD_SHARED_LIBS=ON
BUILD_COMMAND ${CMAKE_COMMAND} --build . --config ${CMAKE_BUILD_TYPE} --parallel
BUILD_IN_SOURCE 0
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_BUILD_TYPE}/${LIBNAME_WEBP}.dll ${BINDIR}/
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_BUILD_TYPE}/${LIBNAME_SHARPYUV}.dll ${BINDIR}/
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_BUILD_TYPE}/${LIBNAME_WEBPDECODER}.dll ${BINDIR}/
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_BUILD_TYPE}/${LIBNAME_WEBP}.lib ${LIBDIR}/
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_BUILD_TYPE}/${LIBNAME_SHARPYUV}.lib ${LIBDIR}/
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_BUILD_TYPE}/${LIBNAME_WEBPDECODER}.lib ${LIBDIR}/
COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SRC_WEBP}/src/webp ${INCDIR}/webp
COMMAND ${CMAKE_COMMAND} -E remove ${INCDIR}/webp/config.h.in
)
Expand All @@ -51,17 +31,17 @@ elseif(APPLE)
ExternalProject_Add(project_${TARGET_WEBP}
URL ${URL_WEBP}
URL_MD5 ${URL_MD5_WEBP}
CONFIGURE_COMMAND ./configure --enable-shared=yes --enable-static=no --prefix=
BUILD_COMMAND make -j${CPUS}
BUILD_IN_SOURCE 1
CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} ${COMMON_CMAKE_ARGS_WEBP} -DBUILD_SHARED_LIBS=ON
BUILD_COMMAND ${CMAKE_COMMAND} --build . --parallel
BUILD_IN_SOURCE 0
INSTALL_COMMAND ${CMAKE_COMMAND} -E make_directory ${FRAMEWORK_DIR_WEBP}/Versions/A
COMMAND ${CMAKE_COMMAND} -E create_symlink A ${FRAMEWORK_DIR_WEBP}/Versions/Current
COMMAND ${CMAKE_COMMAND} -E copy_if_different src/.libs/${DYLIBNAME_WEBP} ${FRAMEWORK_DIR_WEBP}/Versions/A/
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${DYLIBNAME_WEBP} ${FRAMEWORK_DIR_WEBP}/Versions/A/
COMMAND ${CMAKE_COMMAND} -E create_symlink Versions/Current/${DYLIBNAME_WEBP} ${FRAMEWORK_DIR_WEBP}/${TARGET_WEBP}
COMMAND ${CMAKE_COMMAND} -E copy_if_different sharpyuv/.libs/${DYLIBNAME_SHARPYUV} ${FRAMEWORK_DIR_WEBP}/Versions/A/
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${DYLIBNAME_SHARPYUV} ${FRAMEWORK_DIR_WEBP}/Versions/A/
COMMAND ${CMAKE_COMMAND} -E create_symlink Versions/Current/${DYLIBNAME_SHARPYUV} ${FRAMEWORK_DIR_WEBP}/sharpyuv
COMMAND install_name_tool -id "@rpath/${TARGET_WEBP}.framework/${TARGET_WEBP}" ${FRAMEWORK_DIR_WEBP}/${TARGET_WEBP}
COMMAND install_name_tool ${FRAMEWORK_DIR_WEBP}/Versions/A/${DYLIBNAME_WEBP} -change "/lib/${DYLIBNAME_SHARPYUV}" "@loader_path/${DYLIBNAME_SHARPYUV}"
COMMAND install_name_tool -change "@rpath/${DYLIBNAME_SHARPYUV}" "@rpath/${TARGET_WEBP}.framework/sharpyuv" ${FRAMEWORK_DIR_WEBP}/Versions/A/${DYLIBNAME_WEBP}
COMMAND install_name_tool -id "@rpath/${TARGET_WEBP}.framework/sharpyuv" ${FRAMEWORK_DIR_WEBP}/sharpyuv
COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SRC_WEBP}/src/webp ${FRAMEWORK_DIR_WEBP}/Versions/A/Headers/
COMMAND ${CMAKE_COMMAND} -E remove ${FRAMEWORK_DIR_WEBP}/Versions/A/Headers/config.h.in
Expand All @@ -87,9 +67,9 @@ else()
ExternalProject_Add(project_${TARGET_WEBP}
URL ${URL_WEBP}
URL_MD5 ${URL_MD5_WEBP}
CONFIGURE_COMMAND ./configure --enable-shared=yes --enable-static=no --prefix=${DESTINATION_PATH} --exec-prefix=${DESTINATION_PATH}
BUILD_COMMAND make -j${CPUS}
BUILD_IN_SOURCE 1
CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} ${COMMON_CMAKE_ARGS_WEBP} -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=${DESTINATION_PATH}
BUILD_COMMAND ${CMAKE_COMMAND} --build . --parallel
BUILD_IN_SOURCE 0
INSTALL_COMMAND make install
)
endif()
34 changes: 0 additions & 34 deletions cmake/webp_static.cmake

This file was deleted.

0 comments on commit e5875a9

Please sign in to comment.