Skip to content

Commit

Permalink
[sdl2-image] Features must use sdl2[x11] on Linux (#23725)
Browse files Browse the repository at this point in the history
* Fix shared libs suffix

* Remove version-string

* version

* Use cmake version of shared lib suffix

* version

* Remove old feature processing

* version

* Real fix

* [sdl2] Fix x11 feature

* format

* version

* Fix suffix again

* version

* Fix external dependencies

* version

* Fix WebP linkage

* version

* Fix PNG linkage

* version

* Mark everything as default feature for testing

* version

* Trigger rebuild of sdl2pp

* version

* congig file

* Fix flags

* version

* Fix flags

* version

* Disable UWP warnings for TIFF

* version

* Fix CXX

* version

* revert cmake version

* version

* Fix config

* version

* Revert sdl2pp

* Fix config

* version

* Create config.cmake.in file

* version
  • Loading branch information
Thomas1664 authored Apr 15, 2022
1 parent 94c2aed commit 05bcc5f
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 92 deletions.
94 changes: 32 additions & 62 deletions ports/sdl2-image/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,14 @@ project(SDL2_image C)

### configuration ###

list(APPEND CMAKE_MODULE_PATH "${CURRENT_INSTALLED_DIR}/share/libwebp")
# enable all file formats which are supported natively
set(SUPPORTED_FORMATS BMP GIF LBM PCX PNM TGA XPM XCF XV SVG)

# enable all file formats which are supported through external dependencies
# first try to load them statically (lib file in vcpkg installation)
# if this fails try to make them a dynamic dependency (dll will be loaded at runtime) if possible. vcpkg cannot resolve these dependencies!
# else do not support this file format at all

# Can be explicitly enabled or disabled via USE_XYZ
set(DEPENDENCIES PNG JPEG TIFF WEBP)

# patch library names for preprocessor flags
set(JPEG_FLAG JPG)
set(TIFF_FLAG TIF)

# names of potentially dynamically loaded libraries
set(JPEG_DYNAMIC \"libjpeg-9.dll\")
set(PNG_DYNAMIC \"libpng16-16.dll\")
set(TIFF_DYNAMIC \"libtiff-5.dll\")
set(WEBP_DYNAMIC \"libwebp-4.dll\")
option(USE_WEBP "Enable support for WebP format" OFF)
option(USE_PNG "Enable support for PNG format" OFF)
option(USE_JPEG "Enable support for JPEG format" OFF)
option(USE_TIFF "Enable support for TIFF format" OFF)

### implementation ###

Expand Down Expand Up @@ -74,33 +61,34 @@ include_directories(${CMAKE_SOURCE_DIR})
target_link_libraries(SDL2_image SDL2::SDL2)

# external dependencies
foreach(DEPENDENCY IN LISTS DEPENDENCIES)
if(NOT USE_${DEPENDENCY})
continue()
endif()
find_package(${DEPENDENCY})

if(NOT DEFINED ${DEPENDENCY}_FLAG)
set(${DEPENDENCY}_FLAG ${DEPENDENCY})
endif()
if(USE_WEBP)
find_package(WebP CONFIG REQUIRED)
add_definitions(-DLOAD_WEBP)
target_link_libraries(SDL2_image PRIVATE WebP::webp)
endif()

add_definitions(-DLOAD_${${DEPENDENCY}_FLAG})
if(${DEPENDENCY}_FOUND)
message(STATUS " --> linking statically.")
target_link_libraries(SDL2_image ${${DEPENDENCY}_LIBRARIES})
elseif(DEFINED ${DEPENDENCY}_DYNAMIC)
message(STATUS " --> linking dynamically.")
add_definitions(-DLOAD_${${DEPENDENCY}_FLAG}_DYNAMIC=${${DEPENDENCY}_DYNAMIC})
set(RUNTIME_DEPENDENCIES ON)
else()
message(STATUS " --> skipping.")
endif()
endforeach(DEPENDENCY)
if(USE_PNG)
find_package(libpng REQUIRED)
add_definitions(-DLOAD_PNG)
target_link_libraries(SDL2_image PRIVATE png)
endif()

if(DEFINED RUNTIME_DEPENDENCIES)
include_directories(VisualC/external/include)
if(USE_JPEG)
find_package(JPEG REQUIRED)
add_definitions(-DLOAD_JPG)
target_link_libraries(SDL2_image PRIVATE ${JPEG_LIBRARIES})
endif()

if(USE_TIFF)
find_package(TIFF REQUIRED)
add_definitions(-DLOAD_TIF)
target_link_libraries(SDL2_image PRIVATE TIFF::TIFF)

if(CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4996")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4996")
endif()
endif()

install(TARGETS SDL2_image
EXPORT SDL2_image
Expand All @@ -110,11 +98,10 @@ install(TARGETS SDL2_image

install(FILES SDL_image.h DESTINATION include/SDL2 CONFIGURATIONS Release)

file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/sdl2-image-config.cmake"
[[include(CMakeFindDependencyMacro)
find_dependency(SDL2 CONFIG)
include("${CMAKE_CURRENT_LIST_DIR}/sdl2-image-targets.cmake")
]])
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/sdl2-image-config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/sdl2-image-config.cmake" @ONLY
INSTALL_DESTINATION "share/sdl2-image")

set(prefix "")
set(exec_prefix [[${prefix}]])
set(libdir [[${prefix}/lib]])
Expand All @@ -141,20 +128,3 @@ install(EXPORT SDL2_image
FILE sdl2-image-targets.cmake
NAMESPACE SDL2::
)

message(STATUS "Link-time dependencies:")
message(STATUS " " SDL2::SDL2)
foreach(DEPENDENCY ${DEPENDENCIES})
if(${DEPENDENCY}_FOUND)
message(STATUS " " ${DEPENDENCY})
endif()
endforeach(DEPENDENCY)

if(DEFINED RUNTIME_DEPENDENCIES)
message(STATUS "Run-time dependencies:")
foreach(DEPENDENCY ${DEPENDENCIES})
if(NOT ${DEPENDENCY}_FOUND AND DEFINED ${DEPENDENCY}_DYNAMIC)
message(STATUS " " ${${DEPENDENCY}_DYNAMIC})
endif()
endforeach(DEPENDENCY)
endif()
26 changes: 8 additions & 18 deletions ports/sdl2-image/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,20 @@ vcpkg_extract_source_archive_ex(
)

file(COPY "${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt" DESTINATION "${SOURCE_PATH}")
file(COPY "${CMAKE_CURRENT_LIST_DIR}/sdl2-image-config.cmake.in" DESTINATION "${SOURCE_PATH}")

set(USE_JPEG OFF)
if("libjpeg-turbo" IN_LIST FEATURES)
set(USE_JPEG ON)
endif()

set(USE_TIFF OFF)
if("tiff" IN_LIST FEATURES)
set(USE_TIFF ON)
endif()

set(USE_WEBP OFF)
if("libwebp" IN_LIST FEATURES)
set(USE_WEBP ON)
endif()
vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS
FEATURES
libjpeg-turbo USE_JPEG
tiff USE_TIFF
libwebp USE_WEBP
)

vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}"
OPTIONS
"-DCURRENT_INSTALLED_DIR=${CURRENT_INSTALLED_DIR}"
-DUSE_PNG=ON
-DUSE_JPEG=${USE_JPEG}
-DUSE_TIFF=${USE_TIFF}
-DUSE_WEBP=${USE_WEBP}
${FEATURE_OPTIONS}
)

vcpkg_cmake_install()
Expand Down
6 changes: 6 additions & 0 deletions ports/sdl2-image/sdl2-image-config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
include(CMakeFindDependencyMacro)
find_dependency(SDL2 CONFIG)
if(@USE_WEBP@)
find_dependency(WebP CONFIG)
endif()
include("${CMAKE_CURRENT_LIST_DIR}/sdl2-image-targets.cmake")
29 changes: 25 additions & 4 deletions ports/sdl2-image/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "sdl2-image",
"version-string": "2.0.5",
"port-version": 4,
"version": "2.0.5",
"port-version": 5,
"description": "SDL_image is an image file loading library. It loads images as SDL surfaces and textures, and supports the following formats: BMP, GIF, JPEG, LBM, PCX, PNG, PNM, TGA, TIFF, WEBP, XCF, XPM, XV",
"homepage": "https://www.libsdl.org/projects/SDL_image",
"dependencies": [
Expand All @@ -20,18 +20,39 @@
"libjpeg-turbo": {
"description": "Support for JPEG image format",
"dependencies": [
"libjpeg-turbo"
"libjpeg-turbo",
{
"name": "sdl2",
"features": [
"x11"
],
"platform": "!windows"
}
]
},
"libwebp": {
"description": "Support for WEBP image format.",
"dependencies": [
"libwebp"
"libwebp",
{
"name": "sdl2",
"features": [
"x11"
],
"platform": "!windows"
}
]
},
"tiff": {
"description": "Support for TIFF image format",
"dependencies": [
{
"name": "sdl2",
"features": [
"x11"
],
"platform": "!windows"
},
"tiff"
]
}
Expand Down
6 changes: 2 additions & 4 deletions ports/sdl2/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS
)

if ("x11" IN_LIST FEATURES)
if (VCPKG_TARGET_IS_WINDOWS)
message(FATAL_ERROR "Feature x11 only support UNIX.")
endif()
message(WARNING "You will need to install Xorg dependencies to use feature x11:\nsudo apt install libx11-dev libxft-dev libxext-dev\n")
endif()

Expand Down Expand Up @@ -84,7 +81,6 @@ if(VCPKG_TARGET_IS_WINDOWS AND NOT VCPKG_TARGET_IS_UWP AND NOT VCPKG_TARGET_IS_M
endforeach()
endif()

configure_file("${SOURCE_PATH}/LICENSE.txt" "${CURRENT_PACKAGES_DIR}/share/${PORT}/copyright" COPYONLY)
vcpkg_copy_pdbs()

set(DYLIB_COMPATIBILITY_VERSION_REGEX "set\\(DYLIB_COMPATIBILITY_VERSION (.+)\\)")
Expand All @@ -100,3 +96,5 @@ if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug")
endif()

vcpkg_fixup_pkgconfig()

file(INSTALL "${SOURCE_PATH}/LICENSE.txt" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright)
5 changes: 3 additions & 2 deletions ports/sdl2/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "sdl2",
"version": "2.0.20",
"port-version": 1,
"port-version": 2,
"description": "Simple DirectMedia Layer is a cross-platform development library designed to provide low level access to audio, keyboard, mouse, joystick, and graphics hardware via OpenGL and Direct3D.",
"homepage": "https://www.libsdl.org/download-2.0.php",
"dependencies": [
Expand All @@ -19,7 +19,8 @@
"description": "Vulkan functionality for SDL"
},
"x11": {
"description": "Dynamically load X11 support"
"description": "Dynamically load X11 support",
"supports": "!windows"
}
}
}
4 changes: 2 additions & 2 deletions versions/baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -6370,15 +6370,15 @@
},
"sdl2": {
"baseline": "2.0.20",
"port-version": 1
"port-version": 2
},
"sdl2-gfx": {
"baseline": "1.0.4",
"port-version": 8
},
"sdl2-image": {
"baseline": "2.0.5",
"port-version": 4
"port-version": 5
},
"sdl2-mixer": {
"baseline": "2.0.4",
Expand Down
5 changes: 5 additions & 0 deletions versions/s-/sdl2-image.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"versions": [
{
"git-tree": "623548e8c929f2160320bf9644e2cd5a75d4a608",
"version": "2.0.5",
"port-version": 5
},
{
"git-tree": "9042c449fc4c728c5b428332e09bc6d21a2acf34",
"version-string": "2.0.5",
Expand Down
5 changes: 5 additions & 0 deletions versions/s-/sdl2.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"versions": [
{
"git-tree": "abf71c19917402dddef261e80d55c8ec04e9bf54",
"version": "2.0.20",
"port-version": 2
},
{
"git-tree": "9900463f2847ed86e25bac1688c527ae3486a024",
"version": "2.0.20",
Expand Down

0 comments on commit 05bcc5f

Please sign in to comment.