diff --git a/CMakeLists.txt b/CMakeLists.txt index d93c6c92..968c582d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -299,7 +299,7 @@ endif() # Use `Compatible Interface Properties` to ensure a shared SDL3_image is built with a shared SDL3 if(SDL3IMAGE_BUILD_SHARED_LIBS) - set_property(TARGET ${sdl3_image_target_name} PROPERTY INTERFACE_SDL3_SHARED ${SDL3IMAGE_BUILD_SHARED_LIBS}) + set_property(TARGET ${sdl3_image_target_name} PROPERTY INTERFACE_SDL3_SHARED TRUE) set_property(TARGET ${sdl3_image_target_name} APPEND PROPERTY COMPATIBLE_INTERFACE_BOOL SDL3_SHARED) endif() @@ -313,6 +313,7 @@ if(SDL3IMAGE_BUILD_SHARED_LIBS) endif() set(INSTALL_EXTRA_TARGETS) +set(INSTALL_EXTRA_CMAKE_MODULES) set(PC_LIBS) set(PC_REQUIRES) @@ -358,7 +359,9 @@ if(SDL3IMAGE_ZLIB) else() set(ZLIB_LIBRARY zlibstatic) endif() - list(APPEND INSTALL_EXTRA_TARGETS ${ZLIB_LIBRARY}) + if(SDL3IMAGE_ZLIB_SHARED OR NOT SDL3IMAGE_BUILD_SHARED_LIBS) + list(APPEND INSTALL_EXTRA_TARGETS ${ZLIB_LIBRARY}) + endif() set_target_properties(${ZLIB_LIBRARY} PROPERTIES EXPORT_NAME external_zlib) add_library(SDL3_image::external_zlib ALIAS ${ZLIB_LIBRARY}) else() @@ -370,9 +373,12 @@ endif() if(SDL3IMAGE_DAV1D) if(SDL3IMAGE_DAV1D_VENDORED) message(STATUS "${PROJECT_NAME}: Using vendored dav1d") + set(BUILD_SHARED_LIBS ${SDL3IMAGE_DAV1D_SHARED}) add_subdirectory(external/dav1d) set(DAV1D_LIBRARY dav1d) - list(APPEND INSTALL_EXTRA_TARGETS dav1d) + if(SDL3IMAGE_DAV1D_SHARED OR NOT SDL3IMAGE_BUILD_SHARED_LIBS) + list(APPEND INSTALL_EXTRA_TARGETS dav1d) + endif() else() message(FATAL_ERROR "Not implemented") endif() @@ -387,8 +393,11 @@ if(SDL3IMAGE_AVIF) set(AVIF_CODEC_DAV1D ON CACHE BOOL "Use dav1d codec for decoding" FORCE) set(AVIF_LOCAL_DAV1D OFF CACHE BOOL "Build dav1d by libaf" FORCE) set(LIBAVIF_WITH_SHARPYUV_SDLIMAGE ${SDL3IMAGE_WEBP} CACHE BOOL "Build libavif with sharpyuv support (re-use sharpyuv built by libwebp)" FORCE) + set(BUILD_SHARED_LIBS ${SDL3IMAGE_AVIF_SHARED}) add_subdirectory(external/libavif EXCLUDE_FROM_ALL) - list(APPEND INSTALL_EXTRA_TARGETS avif) + if(SDL3IMAGE_AVIF_SHARED OR NOT SDL3IMAGE_BUILD_SHARED_LIBS) + list(APPEND INSTALL_EXTRA_TARGETS avif) + endif() set_target_properties(avif PROPERTIES EXPORT_NAME external_libavif) add_library(SDL3_image::external_libavif ALIAS avif) if(NOT SDL3IMAGE_AVIF_SHARED) @@ -453,7 +462,9 @@ if(SDL3IMAGE_JPG) sdl_check_project_in_subfolder(external/jpeg libjpeg SDL3IMAGE_VENDORED) set(BUILD_SHARED_LIBS ${SDL3IMAGE_JPG_SHARED}) add_subdirectory(external/jpeg EXCLUDE_FROM_ALL) - list(APPEND INSTALL_EXTRA_TARGETS jpeg) + if(SDL3IMAGE_JPG_SHARED OR NOT SDL3IMAGE_BUILD_SHARED_LIBS) + list(APPEND INSTALL_EXTRA_TARGETS jpeg) + endif() set_target_properties(jpeg PROPERTIES EXPORT_NAME external_libjpeg) add_library(SDL3_image::external_libjpeg ALIAS jpeg) if(NOT SDL3IMAGE_JPG_SHARED) @@ -491,6 +502,8 @@ if(SDL3IMAGE_JXL) message(STATUS "${PROJECT_NAME}: Using vendored libjxl") # BUILD_TESTING variable is used by libjxl set(BUILD_TESTING OFF CACHE BOOL "build testing") + # JPEGXL_ENABLE_BENCHMARK variable is used by libjxl + set(JPEGXL_ENABLE_BENCHMARK OFF CACHE BOOL "libjpegxl benchmark" FORCE) # JPEGXL_ENABLE_TOOLS variable is used by libjxl set(JPEGXL_ENABLE_JNI OFF CACHE BOOL "build jpegxl fni") # JPEGXL_ENABLE_MANPAGES variable is used by libjxl @@ -504,18 +517,19 @@ if(SDL3IMAGE_JXL) sdl_check_project_in_subfolder(external/libjxl libjxl SDL3IMAGE_VENDORED) set(BUILD_SHARED_LIBS ${SDL3IMAGE_JXL_SHARED}) add_subdirectory(external/libjxl EXCLUDE_FROM_ALL) - if(BUILD_SHARED_LIBS) + if(SDL3IMAGE_JXL_SHARED) set(jxl_lib jxl) - list(APPEND INSTALL_EXTRA_TARGETS brotlidec brotlicommon brotlienc ${jxl_lib}) - if(NOT SDL3IMAGE_JXL_SHARED) - list(APPEND PC_LIBS - -l$ -l$ - -l$ -l$ - ) - endif() + set(jxl_install_libs brotlidec brotlicommon brotlienc jxl) else() set(jxl_lib jxl_dec-static) - list(APPEND INSTALL_EXTRA_TARGETS brotlidec-static brotlicommon-static hwy ${jxl_lib}) + set(jxl_install_libs brotlidec-static brotlicommon-static hwy jxl_dec-static) + list(APPEND PC_LIBS + -l$ -l$ + -l$ -l$ + ) + endif() + if(SDL3IMAGE_JXL_SHARED OR NOT SDL3IMAGE_BUILD_SHARED_LIBS) + list(APPEND INSTALL_EXTRA_TARGETS ${jxl_install_libs}) endif() set_target_properties(${jxl_lib} PROPERTIES EXPORT_NAME external_libjxl) add_library(SDL3_image::external_libjxl ALIAS ${jxl_lib}) @@ -527,6 +541,7 @@ if(SDL3IMAGE_JXL) find_package(libjxl REQUIRED) if(NOT SDL3IMAGE_JXL_SHARED) list(APPEND PC_REQUIRES libjxl) + list(APPEND INSTALL_EXTRA_CMAKE_MODULES cmake/Findlibjxl.cmake) endif() endif() if(SDL3IMAGE_JXL_SHARED) @@ -571,8 +586,11 @@ if(SDL3IMAGE_PNG) set(PNG_LIBRARY png_static) endif() add_library(PNG::PNG ALIAS ${PNG_LIBRARY}) + set_property(TARGET ${PNG_LIBRARY} PROPERTY DEBUG_POSTFIX "") target_include_directories(${sdl3_image_target_name} PRIVATE external/libpng) - list(APPEND INSTALL_EXTRA_TARGETS ${PNG_LIBRARY}) + if(SDL3IMAGE_PNG_SHARED OR NOT SDL3IMAGE_BUILD_SHARED_LIBS) + list(APPEND INSTALL_EXTRA_TARGETS ${PNG_LIBRARY}) + endif() set_target_properties(${PNG_LIBRARY} PROPERTIES EXPORT_NAME external_libpng) add_library(SDL3_image::external_libpng ALIAS ${PNG_LIBRARY}) if(NOT SDL3IMAGE_PNG_SHARED) @@ -654,7 +672,9 @@ if(SDL3IMAGE_TIF) set(BUILD_SHARED_LIBS ${SDL3IMAGE_TIF_SHARED}) add_subdirectory(external/libtiff EXCLUDE_FROM_ALL) add_library(TIFF::TIFF ALIAS tiff) - list(APPEND INSTALL_EXTRA_TARGETS tiff) + if(SDL3IMAGE_TIF_SHARED OR NOT SDL3IMAGE_BUILD_SHARED_LIBS) + list(APPEND INSTALL_EXTRA_TARGETS tiff) + endif() set_target_properties(tiff PROPERTIES EXPORT_NAME external_libtiff) add_library(SDL3_image::external_libtiff ALIAS tiff) if(NOT SDL3IMAGE_TIF_SHARED) @@ -695,9 +715,11 @@ if(SDL3IMAGE_WEBP) target_include_directories(${sdl3_image_target_name} PRIVATE external/libwebp/src) add_library(WebP::webp ALIAS webp) add_library(WebP::webpdemux ALIAS webpdemux) - list(APPEND INSTALL_EXTRA_TARGETS webp webpdemux) - if(NOT BUILD_SHARED_LIBS) - list(APPEND INSTALL_EXTRA_TARGETS sharpyuv) + if(SDL3IMAGE_WEBP_SHARED OR NOT SDL3IMAGE_BUILD_SHARED_LIBS) + list(APPEND INSTALL_EXTRA_TARGETS webp webpdemux) + if(NOT SDL3IMAGE_WEBP_SHARED) + list(APPEND INSTALL_EXTRA_TARGETS sharpyuv) + endif() endif() set_target_properties(webp PROPERTIES EXPORT_NAME "external_libwebp") set_target_properties(webpdemux PROPERTIES EXPORT_NAME "external_webpdemux") @@ -708,6 +730,7 @@ if(SDL3IMAGE_WEBP) find_package(webp REQUIRED) if(NOT SDL3IMAGE_WEBP_SHARED) list(APPEND PC_REQUIRES libwebp) + list(APPEND INSTALL_EXTRA_CMAKE_MODULES cmake/Findwebp.cmake) endif() endif() if(SDL3IMAGE_WEBP_SHARED) @@ -763,10 +786,14 @@ if(SDL3IMAGE_INSTALL) if(INSTALL_EXTRA_TARGETS) set_property(TARGET ${INSTALL_EXTRA_TARGETS} PROPERTY PUBLIC_HEADER "") + set(archive_destination) + if(NOT BUILD_SHARED_LIBS) + set(archive_destination ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT devel) + endif() install( TARGETS ${INSTALL_EXTRA_TARGETS} EXPORT SDL3ImageExports - ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT devel + ${archive_destination} LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT library RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT library ) @@ -798,8 +825,7 @@ if(SDL3IMAGE_INSTALL) FILES "${CMAKE_CURRENT_BINARY_DIR}/SDL3_imageConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/SDL3_imageConfigVersion.cmake" - cmake/Findlibjxl.cmake - cmake/Findwebp.cmake + ${INSTALL_EXTRA_CMAKE_MODULES} DESTINATION "${SDL3IMAGE_INSTALL_CMAKEDIR}" COMPONENT devel ) diff --git a/cmake/SDL3_imageConfig.cmake.in b/cmake/SDL3_imageConfig.cmake.in index ddac56f3..16e50bf5 100644 --- a/cmake/SDL3_imageConfig.cmake.in +++ b/cmake/SDL3_imageConfig.cmake.in @@ -8,23 +8,28 @@ set_package_properties(SDL3_image PROPERTIES set(SDL3_image_FOUND ON) -set(SDL3IMAGE_AVIF @SDL3IMAGE_AVIF@) -set(SDL3IMAGE_BMP @SDL3IMAGE_BMP@) -set(SDL3IMAGE_GIF @SDL3IMAGE_GIF@) -set(SDL3IMAGE_JPG @SDL3IMAGE_JPG@) -set(SDL3IMAGE_JXL @SDL3IMAGE_JXL@) -set(SDL3IMAGE_LBM @SDL3IMAGE_LBM@) -set(SDL3IMAGE_PCX @SDL3IMAGE_PCX@) -set(SDL3IMAGE_PNG @SDL3IMAGE_PNG@) -set(SDL3IMAGE_PNM @SDL3IMAGE_PNM@) -set(SDL3IMAGE_QOI @SDL3IMAGE_QOI@) -set(SDL3IMAGE_SVG @SDL3IMAGE_SVG@) -set(SDL3IMAGE_TGA @SDL3IMAGE_TGA@) -set(SDL3IMAGE_TIF @SDL3IMAGE_TIF@) -set(SDL3IMAGE_XCF @SDL3IMAGE_XCF@) -set(SDL3IMAGE_XPM @SDL3IMAGE_XPM@) -set(SDL3IMAGE_XV @SDL3IMAGE_XV@) -set(SDL3IMAGE_WEBP @SDL3IMAGE_WEBP@) +set(SDL3IMAGE_AVIF @SDL3IMAGE_AVIF@) +set(SDL3IMAGE_AVIF_SHARED @SDL3IMAGE_AVIF_SHARED@) +set(SDL3IMAGE_BMP @SDL3IMAGE_BMP@) +set(SDL3IMAGE_GIF @SDL3IMAGE_GIF@) +set(SDL3IMAGE_JPG @SDL3IMAGE_JPG@) +set(SDL3IMAGE_JPG_SHARED @SDL3IMAGE_JPG_SHARED@) +set(SDL3IMAGE_JXL @SDL3IMAGE_JXL@) +set(SDL3IMAGE_JXL_SHARED @SDL3IMAGE_JXL_SHARED@) +set(SDL3IMAGE_LBM @SDL3IMAGE_LBM@) +set(SDL3IMAGE_PCX @SDL3IMAGE_PCX@) +set(SDL3IMAGE_PNG @SDL3IMAGE_PNG@) +set(SDL3IMAGE_PNG_SHARED @SDL3IMAGE_PNG_SHARED@) +set(SDL3IMAGE_PNM @SDL3IMAGE_PNM@) +set(SDL3IMAGE_QOI @SDL3IMAGE_QOI@) +set(SDL3IMAGE_SVG @SDL3IMAGE_SVG@) +set(SDL3IMAGE_TGA @SDL3IMAGE_TGA@) +set(SDL3IMAGE_TIF @SDL3IMAGE_TIF@) +set(SDL3IMAGE_TIF_SHARED @SDL3IMAGE_TIF_SHARED@) +set(SDL3IMAGE_XCF @SDL3IMAGE_XCF@) +set(SDL3IMAGE_XPM @SDL3IMAGE_XPM@) +set(SDL3IMAGE_XV @SDL3IMAGE_XV@) +set(SDL3IMAGE_WEBP_SHARED @SDL3IMAGE_WEBP_SHARED@) set(SDL3IMAGE_JPG_SAVE @SDL3IMAGE_JPG_SAVE@) set(SDL3IMAGE_PNG_SAVE @SDL3IMAGE_PNG_SAVE@) @@ -44,23 +49,35 @@ endif() if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/SDL3_image-static-targets.cmake") if(SDL3IMAGE_VENDORED) - if(SDL3IMAGE_WEBP) + if(SDL3IMAGE_AVIF AND NOT SDL3IMAGE_AVIF_SHARED) find_package(Threads) endif() - if(SDL3IMAGE_JXL) + if(SDL3IMAGE_JXL AND NOT SDL3IMAGE_JXL_SHARED) include(CheckLanguage) check_language(CXX) if(NOT CMAKE_CXX_COMPILER AND NOT _sdl3image_nowarning) message(WARNING "CXX language not enabled. Linking to SDL3_image::SDL3_image-static might fail.") endif() endif() + if(SDL3IMAGE_TIF AND NOT SDL3IMAGE_TIF_SHARED) + if(NOT TARGET CMath::CMath) + add_library(CMath::CMath INTERFACE IMPORTED) + find_library(CMATH_LIBRARY NAMES m) + if(CMATH_LIBRARY) + set_property(TARGET CMath::CMath PROPERTY INTERFACE_LINK_LIBRARIES "${CMAKE_LIBRARY}") + endif() + endif() + endif() + if(SDL3IMAGE_WEBP AND NOT SDL3IMAGE_WEBP_SHARED) + find_package(Threads) + endif() else() set(_sdl_cmake_module_path "${CMAKE_MODULE_PATH}") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}") include(CMakeFindDependencyMacro) - if(SDL3IMAGE_AVIF AND NOT TARGET avif) + if(SDL3IMAGE_AVIF AND NOT TARGET avif AND NOT SDL3IMAGE_AVIF_SHARED) find_package(libavif 1.0 QUIET) if(NOT libavif_FOUND) find_package(libavif @LIBAVIF_MINIMUM_VERSION@ QUIET) @@ -71,7 +88,7 @@ if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/SDL3_image-static-targets.cmake") endif() endif() - if(SDL3IMAGE_JPG AND NOT TARGET JPEG::JPEG) + if(SDL3IMAGE_JPG AND NOT TARGET JPEG::JPEG AND NOT SDL3IMAGE_JPG_SHARED) find_dependency(JPEG) endif() @@ -80,7 +97,7 @@ if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/SDL3_image-static-targets.cmake") find_dependency(libjxl) endif() - if(SDL3IMAGE_PNG AND NOT TARGET PNG::PNG) + if(SDL3IMAGE_PNG AND NOT TARGET PNG::PNG AND NOT SDL3IMAGE_PNG_SHARED) find_dependency(PNG) endif() @@ -88,7 +105,7 @@ if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/SDL3_image-static-targets.cmake") find_dependency(TIFF) endif() - if(SDL3IMAGE_WEBP AND NOT TARGET WebP::webp) + if(SDL3IMAGE_WEBP AND NOT TARGET WebP::webp AND NOT SDL3IMAGE_WEBP_SHARED) list(APPEND webp_ROOT "${CMAKE_CURRENT_LIST_DIR}") find_dependency(webp) endif() diff --git a/cmake/test/main.c b/cmake/test/main.c index 22fde13c..2f1ce62b 100644 --- a/cmake/test/main.c +++ b/cmake/test/main.c @@ -2,15 +2,31 @@ #include #include +#define TEST_INIT_FLAG(FLAG) do { \ + if ((IMG_Init(FLAG) & FLAG) == FLAG) { \ + SDL_Log("IMG_Init("#FLAG") succeeded"); \ + } else { \ + SDL_Log("IMG_Init("#FLAG") failed"); \ + } \ + } while (0); + +#define FOREACH_INIT_FLAGS(X) \ + X(IMG_INIT_JPG) \ + X(IMG_INIT_PNG) \ + X(IMG_INIT_TIF) \ + X(IMG_INIT_WEBP) \ + X(IMG_INIT_JXL) \ + X(IMG_INIT_AVIF) \ + int main(int argc, char *argv[]) { if (SDL_Init(0) < 0) { - SDL_Log("Could not initialize SDL: %s\n", SDL_GetError()); + SDL_Log("SDL_Init(0) failed: %s\n", SDL_GetError()); return 1; } - if (IMG_Init(0) == 0) { - SDL_Log("No image formats supported\n"); - } + + FOREACH_INIT_FLAGS(TEST_INIT_FLAG) + IMG_Quit(); SDL_Quit(); return 0; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index e6efdf9d..0a008285 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -2,6 +2,8 @@ enable_testing() +set(CMAKE_POSITION_INDEPENDENT_CODE OFF) + set(RESOURCE_FILES palette.bmp palette.gif