New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add missing options to cmake script #189
Conversation
I just tested with Visual Studio 16 2019, which results in the following install prefix:
|
Imho the term vendor used here is a bit ambiguous, it could cause inadvertent confusion, package-maintainer bundled libs or something would be a better term |
and also be very careful with visibility... see https://gcc.gnu.org/wiki/Visibility - Problems with C++ exceptions (please read!) and potentially opencv/opencv#7565 |
would also recommend keeping more of the inline comments, makes it easier to track the changes |
package-maintainer is another thing. Perhaps you're right that
SDL_image is a pure c library without a c++ interface. |
You mean adding comments to the cmake script? Btw, does this cmake script work on your machine and build for your targets? |
Can you rebase this on the latest code? Does it make sense to make similar changes to the SDL_mixer and SDL_ttf libraries? Thanks! |
The creation of this pr was inspired by the lack of configuration options to enable/disable the various backends + use system packages. The CI failure is because not all dependencies of sdl_image can be used as a subproject without change. I just found out all dependencies are vendored as github project in the github libsdl-org organization, so I am able to patch those without bothering upstream. The following patches need to be applied to fix the dependencies (+dependencies of dependencies): brotli.patch diff --git a/CMakeLists.txt b/CMakeLists.txt
index a8ea872..dc6d092 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -175,14 +175,14 @@ endforeach()
foreach(lib IN LISTS BROTLI_SHARED_LIBS BROTLI_STATIC_LIBS)
target_link_libraries(${lib} ${LIBM_LIBRARY})
- set_property(TARGET ${lib} APPEND PROPERTY INCLUDE_DIRECTORIES ${BROTLI_INCLUDE_DIRS})
+ set_property(TARGET ${lib} APPEND PROPERTY INCLUDE_DIRECTORIES "$<BUILD_INTERFACE:${BROTLI_INCLUDE_DIRS}>")
set_target_properties(${lib} PROPERTIES
VERSION "${BROTLI_ABI_COMPATIBILITY}.${BROTLI_ABI_AGE}.${BROTLI_ABI_REVISION}"
SOVERSION "${BROTLI_ABI_COMPATIBILITY}")
if(NOT BROTLI_EMSCRIPTEN)
set_target_properties(${lib} PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
endif()
- set_property(TARGET ${lib} APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${BROTLI_INCLUDE_DIRS}")
+ set_property(TARGET ${lib} APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES "$<BUILD_INTERFACE:${BROTLI_INCLUDE_DIRS}>")
endforeach()
if(NOT BROTLI_EMSCRIPTEN) jpeg.patch diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3b49a85..34d487f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.1)
project(jpeg C)
-add_library(jpeg STATIC)
+add_library(jpeg)
target_sources(jpeg PRIVATE
jaricom.c jcapimin.c jcapistd.c jcarith.c jccoefct.c jccolor.c
jcdctmgr.c jchuff.c jcinit.c jcmainct.c jcmarker.c jcmaster.c
@@ -26,4 +26,4 @@ target_sources(jpeg PRIVATE jidctint.c jidctfst.c)
target_compile_definitions(jpeg PRIVATE -DAVOID_TABLES)
-target_include_directories(jpeg PUBLIC .)
+target_include_directories(jpeg PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>) libhighway.patch diff --git a/CMakeLists.txt b/CMakeLists.txt
index 69a8e61..0ed776b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -167,7 +167,7 @@ endif() # !MSVC
add_library(hwy STATIC ${HWY_SOURCES})
target_compile_options(hwy PRIVATE ${HWY_FLAGS})
set_property(TARGET hwy PROPERTY POSITION_INDEPENDENT_CODE ON)
-target_include_directories(hwy PUBLIC ${CMAKE_CURRENT_LIST_DIR})
+target_include_directories(hwy PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>")
add_library(hwy_contrib STATIC ${HWY_CONTRIB_SOURCES})
target_compile_options(hwy_contrib PRIVATE ${HWY_FLAGS}) libjxl.patch diff --git a/lib/jxl.cmake b/lib/jxl.cmake
index c0290ab..3c0c6c6 100644
--- a/lib/jxl.cmake
+++ b/lib/jxl.cmake
@@ -500,8 +500,9 @@ target_link_libraries(jxl PUBLIC ${JPEGXL_COVERAGE_FLAGS})
target_link_libraries(jxl PRIVATE ${JPEGXL_INTERNAL_SHARED_LIBS})
# Shared library include path contains only the "include/" paths.
target_include_directories(jxl PUBLIC
- "${CMAKE_CURRENT_SOURCE_DIR}/include"
- "${CMAKE_CURRENT_BINARY_DIR}/include")
+ "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
+ "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>"
+ "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
set_target_properties(jxl PROPERTIES
VERSION ${JPEGXL_LIBRARY_VERSION}
SOVERSION ${JPEGXL_LIBRARY_SOVERSION}
diff --git a/third_party/brotli b/third_party/brotli
--- a/third_party/brotli
+++ b/third_party/brotli
@@ -1 +1 @@
-Subproject commit 35ef5c554d888bef217d449346067de05e269b30
+Subproject commit 35ef5c554d888bef217d449346067de05e269b30-dirty
diff --git a/third_party/skcms.cmake b/third_party/skcms.cmake
index 61b1ca5..f518c10 100644
--- a/third_party/skcms.cmake
+++ b/third_party/skcms.cmake
@@ -32,10 +32,10 @@ if(JPEGXL_BUNDLE_SKCMS)
target_compile_options(skcms-obj PRIVATE -DJPEGXL_BUNDLE_SKCMS=1)
if(MSVC)
target_compile_options(skcms-obj
- PRIVATE /FI${CMAKE_SOURCE_DIR}/lib/jxl/enc_jxl_skcms.h)
+ PRIVATE /FI${PROJECT_SOURCE_DIR}/lib/jxl/enc_jxl_skcms.h)
else()
target_compile_options(skcms-obj
- PRIVATE -include${CMAKE_SOURCE_DIR}/lib/jxl/enc_jxl_skcms.h)
+ PRIVATE -include${PROJECT_SOURCE_DIR}/lib/jxl/enc_jxl_skcms.h)
endif()
endif()
libtiff.patch diff --git a/CMakeLists.txt b/CMakeLists.txt
index efe857df..5cc32d20 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -680,7 +680,7 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libtiff-4.pc
# Includes used by libtiff (and tests)
if(ZLIB_INCLUDE_DIRS)
- list(APPEND TIFF_INCLUDES ${ZLIB_INCLUDE_DIRS})
+ list(APPEND TIFF_INCLUDES $<BUILD_INTERFACE:${ZLIB_INCLUDE_DIRS}>)
endif()
if(DEFLATE_INCLUDE_DIR)
list(APPEND TIFF_INCLUDES ${DEFLATE_INCLUDE_DIR})
diff --git a/libtiff/CMakeLists.txt b/libtiff/CMakeLists.txt
index 080685db..0c1607ae 100644
--- a/libtiff/CMakeLists.txt
+++ b/libtiff/CMakeLists.txt
@@ -116,9 +116,9 @@ add_library(tiff ${tiff_SOURCES} ${tiff_HEADERS} ${nodist_tiff_HEADERS}
${tiff_port_SOURCES} libtiff.def)
target_include_directories(tiff
PUBLIC
- $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
- $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
- ${TIFF_INCLUDES}
+ "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>"
+ "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>"
+ "$<BUILD_INTERFACE:${TIFF_INCLUDES}>"
)
target_link_libraries(tiff ${TIFF_LIBRARY_DEPS})
set_target_properties(tiff PROPERTIES SOVERSION ${SO_COMPATVERSION}) Some of these patches might not be needed when we'ld use |
|
72b6b9a
to
bc942d7
Compare
When allowing system libraries on CI, the build succeeds: https://github.com/madebr/SDL_image/actions/runs/2300423858 |
CMakeLists.txt
Outdated
@@ -139,7 +139,7 @@ option(SUPPORT_XPM "Support loading XPM images" ON) | |||
option(SUPPORT_XV "Support loading XV images" ON) | |||
option(SUPPORT_WEBP "Support loading WEBP images" OFF) | |||
|
|||
option(BUILD_SHOWIMAGE "Build the showimage sample program" OFF) | |||
option(BUILD_PROGRAMS "Build the SDL2_image sample program" ON) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe rename the option to reflect that those are samples and not tools?
Sorry, I was poking around in CMakeLists.txt without this PR in mind. Can you rebase your changes, and I'll start working on the upstream patches? |
Also, please feel free to submit a similar makeover for SDL_ttf and SDL_mixer. I won't touch those CMakeLists.txt until you're done with them. |
I've merged your changes and flipped STB on by default, and disabled AVIF, JXL, and WEBP by default, to match default loaders built on other platforms. What needs to be done for the upstream changes you have listed above? |
For SDL_image, the following needs to be done:
The following libraries are dependencies of libjxl. I haven't checked thoroughly whether they are really needed, or whether they can be disabled.
I created a pull request for all issues. So apart from awaiting reviews & hoping for approval, nothing should be done (I think). |
@sezero, can you investigate what we need to do to update to v4.3.0?
Okay, libhighway and brotli are both needed for libjxl. We can wait a bit and see if those patches will be accepted. If not, we can fork them and update the version we pull from libsdl-org. |
Can't we just apply the patch shown above? |
For the purpose of CMake install, sure. |
What else purpose do we really need libtiff-4.3.0? |
Done! |
@madebr, are you planning on making similar changes for SDL_ttf and SDL_mixer? |
|
We need at least cmake 3.14 to support the generator expressions in |
OK, just bumped it to 3.14 in SDL_image too. |
don't merge yet
Known issues that need to be fixed before merging can occur:
e.g. for libpng my system packages provides:
/usr/lib64/libpng16.so
links tolibpng16.so.16.37.0
, it selects that one (and/usr/lib64/libpng16.16
is ignored).This pr improves (imho) the cmake build script by:
SDL2_image-config.cmake
file to enable cmake users to dofind_package(SDL2_image CONFIG)
and use aSDL2::SDL2_image
target.SDL2_image.pc
fileBUILD_PIC
option. (Adding PIC for compiling with cmake on Unix-like #187 was caused by libjpeg building a static library without PIC, which cannot be used inside a shared library)See #189 (comment) for current issues.
When building using system dependencies, the install prefix looks like:
When building+installing all dependencies, the install prefix looks like:
The prefix for a shared mingw build:
Tested on gcc@Linux and mingw@Linux.
Some feedback would be appreciated.
TODO:
FindSDL_image
? Or it that one only looking for 1.x?