From 5f62487189ad5ce0cfcf63831b9451229c160f12 Mon Sep 17 00:00:00 2001 From: Vincent Rabaud Date: Wed, 22 Feb 2017 15:57:06 +0100 Subject: [PATCH] Install binaries, libraries and headers in CMake. Change-Id: Iaf32c716e0252f9a0e9f5d663f02b8fad98096e2 --- CMakeLists.txt | 72 +++++++++++++++++++++++++++++++++++++++ README | 13 +++++-- cmake/WebPConfig.cmake.in | 6 ++++ 3 files changed, 88 insertions(+), 3 deletions(-) create mode 100644 cmake/WebPConfig.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index e4f06b94..977e7374 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,10 @@ endif() include(cmake/config.h.cmake) +# Extract the version of the library. +file(READ ${CMAKE_CURRENT_SOURCE_DIR}/configure.ac SOURCE_FILE) +string(REGEX MATCH "[0-9.]+" WEBP_VERSION ${SOURCE_FILE}) + ################################################################################ # Options. if(WEBP_ENABLE_SWAP_16BIT_CSP) @@ -94,6 +98,7 @@ foreach(FILE ${WEBP_SIMD_FILES_NOT_TO_INCLUDE}) list(REMOVE_ITEM WEBP_DSP_DEC_SRCS ${FILE}) endforeach() +### Define the mandatory libraries. # Build the webpdecoder library. add_definitions(-Wall) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/ ${WEBP_DEP_INCLUDE_DIRS}) @@ -124,6 +129,29 @@ set_target_properties(webpdecode webpdspdecode webputilsdecode add_library(webpdemux ${WEBP_DEMUX_SRCS}) target_link_libraries(webpdemux webp) +# Set the version numbers. +function(parse_version FILE NAME VAR) + file(READ ${CMAKE_CURRENT_SOURCE_DIR}/src/${FILE} SOURCE_FILE) + string(REGEX MATCH "${NAME}_la_LDFLAGS[^\n]* -version-info [0-9:]+" TMP + ${SOURCE_FILE}) + string(REGEX MATCH "[0-9:]+" TMP ${TMP}) + string(REGEX REPLACE ":" "." VERSION ${TMP}) + set(${VAR} "${VERSION}" PARENT_SCOPE) +endfunction() +parse_version(Makefile.am webp WEBP_WEBP_SOVERSION) +set_target_properties(webp PROPERTIES VERSION ${WEBP_VERSION} + SOVERSION ${WEBP_WEBP_SOVERSION}) +parse_version(Makefile.am webpdecoder WEBP_DECODER_SOVERSION) +set_target_properties(webpdecoder PROPERTIES VERSION ${WEBP_VERSION} + SOVERSION ${WEBP_DECODER_SOVERSION}) +parse_version(demux/Makefile.am webpdemux WEBP_DEMUX_SOVERSION) +set_target_properties(webpdemux PROPERTIES VERSION ${WEBP_VERSION} + SOVERSION ${WEBP_DEMUX_SOVERSION}) + +# Define the libraries to install. +set(INSTALLED_LIBRARIES webpdecoder webp webpdemux) + +### Deal with SIMD. # Change the compile flags for SIMD files we use. list(LENGTH WEBP_SIMD_FILES_TO_INCLUDE WEBP_SIMD_FILES_TO_INCLUDE_LENGTH) math(EXPR WEBP_SIMD_FILES_TO_INCLUDE_RANGE @@ -173,6 +201,7 @@ if(WEBP_BUILD_DWEBP) "dwebp") add_executable(dwebp ${DWEBP_SRCS}) target_link_libraries(dwebp exampleutil imagedec imageenc webpdecoder) + install(TARGETS dwebp RUNTIME DESTINATION bin) endif() if(WEBP_BUILD_CWEBP) @@ -182,6 +211,7 @@ if(WEBP_BUILD_CWEBP) "cwebp") add_executable(cwebp ${CWEBP_SRCS}) target_link_libraries(cwebp exampleutil imagedec webp) + install(TARGETS cwebp RUNTIME DESTINATION bin) endif() if(WEBP_BUILD_GIF2WEBP OR WEBP_BUILD_IMG2WEBP) @@ -189,6 +219,10 @@ if(WEBP_BUILD_GIF2WEBP OR WEBP_BUILD_IMG2WEBP) "") add_library(webpmux ${WEBP_MUX_SRCS}) target_link_libraries(webpmux webp) + parse_version(mux/Makefile.am webpmux WEBP_MUX_SOVERSION) + set_target_properties(webpmux PROPERTIES VERSION ${WEBP_VERSION} + SOVERSION ${WEBP_MUX_SOVERSION}) + list(APPEND INSTALLED_LIBRARIES webpmux) endif() if(WEBP_BUILD_GIF2WEBP) @@ -199,6 +233,7 @@ if(WEBP_BUILD_GIF2WEBP) add_executable(gif2webp ${GIF2WEBP_SRCS}) target_link_libraries(gif2webp exampleutil imageioutil webp webpmux ${WEBP_DEP_IMG_LIBRARIES}) + install(TARGETS gif2webp RUNTIME DESTINATION bin) endif() if(WEBP_BUILD_IMG2WEBP) @@ -208,6 +243,7 @@ if(WEBP_BUILD_IMG2WEBP) "img2webp") add_executable(img2webp ${IMG2WEBP_SRCS}) target_link_libraries(img2webp exampleutil imagedec imageioutil webp webpmux) + install(TARGETS img2webp RUNTIME DESTINATION bin) endif() if(WEBP_BUILD_WEBP_JS) @@ -220,3 +256,39 @@ if(WEBP_BUILD_WEBP_JS) target_compile_definitions(webp_js PUBLIC EMSCRIPTEN WEBP_HAVE_SDL) target_compile_definitions(webpdecoder PUBLIC EMSCRIPTEN) endif() + +# Install the different headers and libraries. +install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/webp/decode.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/webp/demux.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/webp/encode.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/webp/mux.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/webp/mux_types.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/webp/types.h + DESTINATION include/webp) +install(TARGETS ${INSTALLED_LIBRARIES} + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib) + +# Create the CMake version file. +include(CMakePackageConfigHelpers) +write_basic_package_version_file( + "${CMAKE_CURRENT_BINARY_DIR}/WebPConfigVersion.cmake" + VERSION ${WEBP_VERSION} + COMPATIBILITY AnyNewerVersion +) + +# Create the Config file. +include(CMakePackageConfigHelpers) +set(ConfigPackageLocation share/WebP/cmake/) +configure_package_config_file( + ${CMAKE_CURRENT_SOURCE_DIR}/cmake/WebPConfig.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/WebPConfig.cmake + INSTALL_DESTINATION ${ConfigPackageLocation} +) + +# Install the generated CMake files. +install( + FILES "${CMAKE_CURRENT_BINARY_DIR}/WebPConfigVersion.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/WebPConfig.cmake" + DESTINATION ${ConfigPackageLocation} +) diff --git a/README b/README index 4c15c4ad..8b821f1d 100644 --- a/README +++ b/README @@ -113,8 +113,8 @@ make install CMake: ------ -The support for CMake is minimal: it only helps you compile libwebp, cwebp and -dwebp. +With CMake, you can compile libwebp, cwebp, dwebp, gif2web, img2webp and the +JS bindings. Prerequisites: A compiler (e.g., gcc with autotools) and CMake. @@ -129,12 +129,19 @@ mkdir build && cd build && cmake ../ make make install -If you also want cwebp or dwebp, you will need to enable them through CMake: +If you also want any of the executables, you will need to enable them through +CMake, e.g.: cmake -DWEBP_BUILD_CWEBP=ON -DWEBP_BUILD_DWEBP=ON ../ or through your favorite interface (like ccmake or cmake-qt-gui). +Finally, once installed, you can also use WebP in your CMake project by doing: + +find_package(WebP) + +which will define the CMake variables WebP_INCLUDE_DIRS and WebP_LIBRARIES. + Gradle: ------- The support for Gradle is minimal: it only helps you compile libwebp, cwebp and diff --git a/cmake/WebPConfig.cmake.in b/cmake/WebPConfig.cmake.in new file mode 100644 index 00000000..ef3df2fb --- /dev/null +++ b/cmake/WebPConfig.cmake.in @@ -0,0 +1,6 @@ +@PACKAGE_INIT@ + +set(WebP_INCLUDE_DIRS "webp") +set(WEBP_INCLUDE_DIRS ${WebP_INCLUDE_DIRS}) +set(WebP_LIBRARIES "@INSTALLED_LIBRARIES@") +set(WEBP_LIBRARIES "${WebP_LIBRARIES}")