From e194928e8bf0ff147e90e5898d7a665ef0b6b204 Mon Sep 17 00:00:00 2001 From: Vincent Rabaud Date: Mon, 9 Oct 2023 15:18:21 +0200 Subject: [PATCH] Modernize CMake. This is mostly to be compliant with Cmake CI tests. Change-Id: I4bb20d7f93b3808bbb1374cef4fd4cb9767e91e0 --- CMakeLists.txt | 66 ++++++++++++++++++++++++++++++--------- cmake/WebPConfig.cmake.in | 17 ++++++++-- 2 files changed, 67 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3b105e37..0bbd9c5e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,6 +29,7 @@ endif() # Include dependencies. include(cmake/deps.cmake) +include(GNUInstallDirs) ################################################################################ # Options. @@ -120,13 +121,32 @@ target_link_libraries(webpdecoder ${WEBP_DEP_LIBRARIES}) # Build the webp library. add_library(webpencode OBJECT ${WEBP_ENC_SRCS}) +target_include_directories( + webpencode PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/src) add_library(webpdsp OBJECT ${WEBP_DSP_COMMON_SRCS} ${WEBP_DSP_DEC_SRCS} - ${WEBP_DSP_ENC_SRCS}) + ${WEBP_DSP_ENC_SRCS}) +target_include_directories(webpdsp PRIVATE ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}) add_library(webputils OBJECT ${WEBP_UTILS_COMMON_SRCS} ${WEBP_UTILS_DEC_SRCS} - ${WEBP_UTILS_ENC_SRCS}) + ${WEBP_UTILS_ENC_SRCS}) +target_include_directories(webputils PRIVATE ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}) add_library(webp $ $ - $ $) + $ $) +if(XCODE) + libwebp_add_stub_file(webp) +endif() target_link_libraries(webp ${WEBP_DEP_LIBRARIES}) +target_include_directories( + webp PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} + PUBLIC $ + $) +set_target_properties( + webp + PROPERTIES PUBLIC_HEADER "${CMAKE_CURRENT_SOURCE_DIR}/src/webp/decode.h;\ +${CMAKE_CURRENT_SOURCE_DIR}/src/webp/encode.h;\ +${CMAKE_CURRENT_SOURCE_DIR}/src/webp/types.h") # Make sure the OBJECT libraries are built with position independent code # (it is not ON by default). @@ -136,6 +156,17 @@ set_target_properties(webpdecode webpdspdecode webputilsdecode # Build the webp demux library. add_library(webpdemux ${WEBP_DEMUX_SRCS}) target_link_libraries(webpdemux webp) +target_include_directories( + webpdemux PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} + PUBLIC $) +set_target_properties( + webpdemux + PROPERTIES + PUBLIC_HEADER + "${CMAKE_CURRENT_SOURCE_DIR}/src/webp/decode.h;\ +${CMAKE_CURRENT_SOURCE_DIR}/src/webp/demux.h;\ +${CMAKE_CURRENT_SOURCE_DIR}/src/webp/mux_types.h;\ +${CMAKE_CURRENT_SOURCE_DIR}/src/webp/types.h") # Set the version numbers. function(parse_version FILE NAME VAR) @@ -242,6 +273,11 @@ if(WEBP_BUILD_GIF2WEBP OR WEBP_BUILD_IMG2WEBP) parse_version(mux/Makefile.am webpmux WEBP_MUX_SOVERSION) set_target_properties(webpmux PROPERTIES VERSION ${PACKAGE_VERSION} SOVERSION ${WEBP_MUX_SOVERSION}) + set_target_properties( + webpmux + PROPERTIES PUBLIC_HEADER "${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;") list(APPEND INSTALLED_LIBRARIES webpmux) endif() @@ -314,16 +350,18 @@ add_definitions(-DHAVE_CONFIG_H) include_directories(${CMAKE_CURRENT_BINARY_DIR}) # 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) +install( + TARGETS ${INSTALLED_LIBRARIES} + EXPORT WebPTargets + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/webp + INCLUDES + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +set(ConfigPackageLocation ${CMAKE_INSTALL_DATADIR}/WebP/cmake/) +install(EXPORT WebPTargets NAMESPACE WebP:: + DESTINATION ${ConfigPackageLocation}) # Create the CMake version file. include(CMakePackageConfigHelpers) @@ -340,7 +378,7 @@ configure_package_config_file( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/WebPConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/WebPConfig.cmake INSTALL_DESTINATION ${ConfigPackageLocation} -) + PATH_VARS CMAKE_INSTALL_INCLUDEDIR) # Install the generated CMake files. install( diff --git a/cmake/WebPConfig.cmake.in b/cmake/WebPConfig.cmake.in index ef3df2fb..24d9f34b 100644 --- a/cmake/WebPConfig.cmake.in +++ b/cmake/WebPConfig.cmake.in @@ -1,6 +1,19 @@ +set(WebP_VERSION @PROJECT_VERSION@) +set(WEBP_VERSION ${WebP_VERSION}) + @PACKAGE_INIT@ -set(WebP_INCLUDE_DIRS "webp") -set(WEBP_INCLUDE_DIRS ${WebP_INCLUDE_DIRS}) +if(@WEBP_USE_THREAD@) + include(CMakeFindDependencyMacro) + find_dependency(Threads REQUIRED) +endif() + +include("${CMAKE_CURRENT_LIST_DIR}/WebPTargets.cmake") + +set_and_check(WebP_INCLUDE_DIR "@PACKAGE_CMAKE_INSTALL_INCLUDEDIR@") +set(WebP_INCLUDE_DIRS ${WebP_INCLUDE_DIR}) +set(WEBP_INCLUDE_DIRS ${WebP_INCLUDE_DIR}) set(WebP_LIBRARIES "@INSTALLED_LIBRARIES@") set(WEBP_LIBRARIES "${WebP_LIBRARIES}") + +check_required_components(WebP)