Skip to content

Commit

Permalink
fix openscenegraph for windows (#5694)
Browse files Browse the repository at this point in the history
* fix openscenegraph for windows

* fix patch

* fix osg link order

* fix libtiff cmake

* patch osg

* fix patch
  • Loading branch information
xq114 authored Nov 9, 2024
1 parent 94b75ce commit 6d99ed9
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 2 deletions.
121 changes: 121 additions & 0 deletions packages/l/libtiff/patches/4.7.0/cmath.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
diff --git a/cmake/FindCMath.cmake b/cmake/FindCMath.cmake
index ad92218..d3dc089 100644
--- a/cmake/FindCMath.cmake
+++ b/cmake/FindCMath.cmake
@@ -55,18 +55,11 @@ if(CMath_FOUND)
set(CMath_INCLUDE_DIRS)
endif()
if(NOT CMath_LIBRARIES)
+ if(NOT CMath_LIBRARY)
+ unset(CMath_LIBRARY)
+ endif()
if (CMath_LIBRARY)
set(CMath_LIBRARIES ${CMath_LIBRARY})
endif()
endif()
-
- if(NOT TARGET CMath::CMath)
- if(CMath_LIBRARIES)
- add_library(CMath::CMath UNKNOWN IMPORTED)
- set_target_properties(CMath::CMath PROPERTIES
- IMPORTED_LOCATION "${CMath_LIBRARY}")
- else()
- add_library(CMath::CMath INTERFACE IMPORTED)
- endif()
- endif()
endif()
diff --git a/contrib/dbs/CMakeLists.txt b/contrib/dbs/CMakeLists.txt
index 74b2a02..2ed96ac 100644
--- a/contrib/dbs/CMakeLists.txt
+++ b/contrib/dbs/CMakeLists.txt
@@ -26,13 +26,19 @@ add_executable(tiff-bi tiff-bi.c)
target_link_libraries(tiff-bi tiff tiff_port)

add_executable(tiff-grayscale tiff-grayscale.c)
-target_link_libraries(tiff-grayscale tiff tiff_port CMath::CMath)
+target_link_libraries(tiff-grayscale tiff tiff_port)
+if(CMath_LIBRARIES)
+ target_link_libraries(tiff-grayscale ${CMath_LIBRARIES})
+endif()

add_executable(tiff-palette tiff-palette.c)
target_link_libraries(tiff-palette tiff tiff_port)

add_executable(tiff-rgb tiff-rgb.c)
-target_link_libraries(tiff-rgb tiff tiff_port CMath::CMath)
+target_link_libraries(tiff-rgb tiff tiff_port)
+if(CMath_LIBRARIES)
+ target_link_libraries(tiff-rgb ${CMath_LIBRARIES})
+endif()

if(WEBP_SUPPORT AND EMSCRIPTEN)
# Emscripten is pretty finnicky about linker flags.
diff --git a/libtiff/CMakeLists.txt b/libtiff/CMakeLists.txt
index a8aa0c3..25914c9 100644
--- a/libtiff/CMakeLists.txt
+++ b/libtiff/CMakeLists.txt
@@ -184,9 +184,9 @@ if(WEBP_SUPPORT)
target_link_libraries(tiff PRIVATE WebP::webp)
string(APPEND tiff_requires_private " libwebp")
endif()
-if(CMath_LIBRARY)
- target_link_libraries(tiff PRIVATE CMath::CMath)
- list(APPEND tiff_libs_private_list "${CMath_LIBRARY}")
+if(CMath_LIBRARIES)
+ target_link_libraries(tiff PRIVATE ${CMath_LIBRARIES})
+ list(APPEND tiff_libs_private_list "${CMath_LIBRARIES}")
endif()

set(tiff_libs_private_list "${tiff_libs_private_list}" PARENT_SCOPE)
diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt
index 5bf93b1..f6c4e2f 100644
--- a/tools/CMakeLists.txt
+++ b/tools/CMakeLists.txt
@@ -48,7 +48,10 @@ target_link_libraries(ppm2tiff PRIVATE tiff tiff_port)

add_executable(raw2tiff ../placeholder.h)
target_sources(raw2tiff PRIVATE raw2tiff.c ${MSVC_RESOURCE_FILE})
-target_link_libraries(raw2tiff PRIVATE tiff tiff_port CMath::CMath)
+target_link_libraries(raw2tiff PRIVATE tiff tiff_port)
+if(CMath_LIBRARIES)
+ target_link_libraries(raw2tiff PRIVATE ${CMath_LIBRARIES})
+endif()

add_executable(rgb2ycbcr ../placeholder.h)
target_sources(rgb2ycbcr PRIVATE rgb2ycbcr.c ${MSVC_RESOURCE_FILE})
@@ -56,7 +59,10 @@ target_link_libraries(rgb2ycbcr PRIVATE tiff tiff_port)

add_executable(thumbnail ../placeholder.h)
target_sources(thumbnail PRIVATE thumbnail.c ${MSVC_RESOURCE_FILE})
-target_link_libraries(thumbnail PRIVATE tiff tiff_port CMath::CMath)
+target_link_libraries(thumbnail PRIVATE tiff tiff_port)
+if(CMath_LIBRARIES)
+ target_link_libraries(thumbnail PRIVATE ${CMath_LIBRARIES})
+endif()

add_executable(tiff2bw ../placeholder.h)
target_sources(tiff2bw PRIVATE tiff2bw.c ${MSVC_RESOURCE_FILE})
@@ -68,7 +74,10 @@ target_link_libraries(tiff2pdf PRIVATE tiff tiff_port)

add_executable(tiff2ps ../placeholder.h)
target_sources(tiff2ps PRIVATE tiff2ps.c ${MSVC_RESOURCE_FILE})
-target_link_libraries(tiff2ps PRIVATE tiff tiff_port CMath::CMath)
+target_link_libraries(tiff2ps PRIVATE tiff tiff_port)
+if(CMath_LIBRARIES)
+ target_link_libraries(tiff2ps PRIVATE ${CMath_LIBRARIES})
+endif()

add_executable(tiff2rgba ../placeholder.h)
target_sources(tiff2rgba PRIVATE tiff2rgba.c ${MSVC_RESOURCE_FILE})
@@ -84,7 +93,10 @@ target_link_libraries(tiffcp PRIVATE tiff tiff_port)

add_executable(tiffcrop ../placeholder.h)
target_sources(tiffcrop PRIVATE tiffcrop.c ${MSVC_RESOURCE_FILE})
-target_link_libraries(tiffcrop PRIVATE tiff tiff_port CMath::CMath)
+target_link_libraries(tiffcrop PRIVATE tiff tiff_port)
+if(CMath_LIBRARIES)
+ target_link_libraries(tiffcrop PRIVATE ${CMath_LIBRARIES})
+endif()

add_executable(tiffdither ../placeholder.h)
target_sources(tiffdither PRIVATE tiffdither.c ${MSVC_RESOURCE_FILE})
3 changes: 3 additions & 0 deletions packages/l/libtiff/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ package("libtiff")
add_versions("v4.6.0", "fdd1a2a35b20734a5232527a81d7365eb66e54732bfc44474a3124bcb85221c7")
add_versions("v4.7.0", "e1d49a419f812cb81626a0c4b2bf0f13c10710fc329284dc9b6dad75b75764bc")

-- https://gitlab.com/libtiff/libtiff/-/issues/625
add_patches("4.7.0", "patches/4.7.0/cmath.patch", "007685076f0bcee9b6f22f628b9a21c2331726215da4c863f63b24d66d2cae20")

add_configs("tools", {description = "build TIFF tools", default = false, type = "boolean"})
add_configs("zlib", {description = "use zlib (required for Deflate compression)", default = false, type = "boolean"})
add_configs("libdeflate", {description = "use libdeflate (optional for faster Deflate support, still requires zlib)", default = false, type = "boolean"})
Expand Down
13 changes: 13 additions & 0 deletions packages/o/openscenegraph/patches/3.6.5/msvc.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/src/osgPlugins/osga/OSGA_Archive.cpp b/src/osgPlugins/osga/OSGA_Archive.cpp
index b9f518a..19186a7 100644
--- a/src/osgPlugins/osga/OSGA_Archive.cpp
+++ b/src/osgPlugins/osga/OSGA_Archive.cpp
@@ -77,7 +77,7 @@ inline OSGA_Archive::pos_type ARCHIVE_POS( const std::streampos & pos )
#else // older Dinkumware (eg: one included in Win Server 2003 Platform SDK )
fpos_t position = pos.get_fpos_t();
#endif
- std::streamoff offset = pos.operator std::streamoff( ) - _FPOSOFF( position );
+ std::streamoff offset = 0;

return OSGA_Archive::pos_type( position + offset );
}
25 changes: 23 additions & 2 deletions packages/o/openscenegraph/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ package("openscenegraph")
"https://github.com/openscenegraph/OpenSceneGraph.git")
add_versions("3.6.5", "aea196550f02974d6d09291c5d83b51ca6a03b3767e234a8c0e21322927d1e12")

add_patches("3.6.5", "patches/3.6.5/msvc.patch", "57b2cc3e5017f7932c5d758346ef0ede8be70f3265276fd8e04534367474eb55")

add_configs("tools", {description = "Enable to build OSG Applications.", default = false, type = "boolean"})

local configdeps = {fontconfig = "fontconfig",
Expand All @@ -23,6 +25,18 @@ package("openscenegraph")
add_configs(config, {description = "Enable the " .. config .. " plugin.", default = false, type = "boolean"})
end

set_policy("platform.longpaths", true)

on_check("windows", function (package)
import("core.tool.toolchain")

local msvc = package:toolchain("msvc")
if msvc and package:is_arch("arm.*") then
local vs = msvc:config("vs")
assert(vs and tonumber(vs) >= 2022, "package(openscenegraph/arm): need vs >= 2022")
end
end)

add_deps("cmake")
add_deps("libjpeg-turbo", "libpng", "giflib", "libtiff")
if is_plat("linux") then
Expand All @@ -40,19 +54,26 @@ package("openscenegraph")
end)

on_install("windows", "linux", "macosx", function (package)
local configs = {"-DBUILD_OSG_EXAMPLES=OFF"}
io.replace("CMakeLists.txt", "FIND_PACKAGE(TIFF)", "FIND_PACKAGE(TIFF CONFIG)", {plain = true})
io.replace("src/osgPlugins/cfg/CMakeLists.txt", "-Wno-deprecated-register", "-Wno-deprecated-register -Wno-register", {plain = true})
io.replace("src/osgPlugins/tiff/CMakeLists.txt", "TARGET_LIBRARIES_VARS TIFF_LIBRARY", "TARGET_EXTERNAL_LIBRARIES TIFF::tiff", {plain = true})
local configs = {"-DBUILD_OSG_EXAMPLES=OFF", "-DOSG_MSVC_VERSIONED_DLL=OFF", "-DOSG_AGGRESSIVE_WARNINGS=OFF"}
local disabled_packages = {"ilmbase", "Inventor", "OpenCascade", "FBX", "GDAL", "GTA", "CURL", "LibVNCServer", "GStreamer", "SDL", "Poppler", "RSVG", "GtkGl", "Asio", "ZeroConf", "LIBLAS"}
for _, pkg in ipairs(disabled_packages) do
table.insert(configs, "-DCMAKE_DISABLE_FIND_PACKAGE_" .. pkg .. "=ON")
end
table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
table.insert(configs, "-DDYNAMIC_OPENSCENEGRAPH=" .. (package:config("shared") and "ON" or "OFF"))
table.insert(configs, "-DDYNAMIC_OPENTHREADS=" .. (package:config("shared") and "ON" or "OFF"))
table.insert(configs, "-DBUILD_OSG_APPLICATIONS=" .. (package:config("tools") and "ON" or "OFF"))
for config, dep in pairs(configdeps) do
table.insert(configs, "-DCMAKE_DISABLE_FIND_PACKAGE_" .. dep .. "=" .. (package:config(config) and "OFF" or "ON"))
end
import("package.tools.cmake").install(package, configs)
local suffix = package:is_debug() and "d" or ""
for _, lib in ipairs({"osg", "osgGA", "osgUtil", "osgDB", "osgText", "osgWidget", "osgTerrain", "osgFX", "osgViewer", "osgVolume", "osgManipulator", "osgAnimation", "osgParticle", "osgShadow", "osgPresentation", "osgSim", "OpenThreads"}) do
package:add("links", lib .. suffix)
end
end)

on_test(function (package)
Expand Down

0 comments on commit 6d99ed9

Please sign in to comment.