Skip to content

Commit

Permalink
libxslt: migrate to CMake
Browse files Browse the repository at this point in the history
  • Loading branch information
triplef committed Oct 25, 2024
1 parent b24ccb5 commit 20ac790
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 76 deletions.
30 changes: 28 additions & 2 deletions patches/libxml2-windows-icu.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 723e2344..c513872e 100644
index f99fd368..4ca6d21a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -102,7 +102,7 @@ if(LIBXML2_WITH_ICONV)
Expand Down Expand Up @@ -32,7 +32,7 @@ index 723e2344..c513872e 100644
SOVERSION ${LIBXML_MAJOR_VERSION}
)
diff --git a/encoding.c b/encoding.c
index 04c24e42..74305989 100644
index 14ffafdd..afb027e3 100644
--- a/encoding.c
+++ b/encoding.c
@@ -45,7 +45,7 @@
Expand All @@ -44,3 +44,29 @@ index 04c24e42..74305989 100644
/* Size of pivot buffer, same as icu/source/common/ucnv.cpp CHUNK_SIZE */
#define ICU_PIVOT_BUF_SIZE 1024
typedef struct _uconv_t uconv_t;
diff --git a/libxml2-config.cmake.cmake.in b/libxml2-config.cmake.cmake.in
index aead949b..cf2f3228 100644
--- a/libxml2-config.cmake.cmake.in
+++ b/libxml2-config.cmake.cmake.in
@@ -123,7 +123,7 @@ if(NOT LIBXML2_SHARED)
endif()

if(LIBXML2_WITH_ICU)
- find_dependency(ICU COMPONENTS data i18n uc)
+ find_dependency(ICU COMPONENTS i18n uc)
list(APPEND LIBXML2_LIBRARIES ${ICU_LIBRARIES})
if(NOT ICU_FOUND)
set(${CMAKE_FIND_PACKAGE_NAME}_FOUND FALSE)
diff --git a/libxml2-config.cmake.in b/libxml2-config.cmake.in
index 6799fd25..2e71d65d 100644
--- a/libxml2-config.cmake.in
+++ b/libxml2-config.cmake.in
@@ -75,7 +75,7 @@ if(LIBXML2_WITH_THREADS)
endif()

if(LIBXML2_WITH_ICU)
- find_dependency(ICU COMPONENTS data i18n uc)
+ find_dependency(ICU COMPONENTS i18n uc)
list(APPEND LIBXML2_LIBRARIES ${ICU_LIBRARIES})
list(APPEND LIBXML2_INTERFACE_LINK_LIBRARIES "\$<LINK_ONLY:ICU::data>;\$<LINK_ONLY:ICU::i18n>;\$<LINK_ONLY:ICU::uc>")
if(NOT ICU_FOUND)
26 changes: 26 additions & 0 deletions patches/libxslt-fix-config-include.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
diff --git a/libexslt/libexslt.h b/libexslt/libexslt.h
index af68f7d4..5b1ace7f 100644
--- a/libexslt/libexslt.h
+++ b/libexslt/libexslt.h
@@ -9,7 +9,7 @@
#ifndef __XSLT_LIBEXSLT_H__
#define __XSLT_LIBEXSLT_H__

-#if defined(_WIN32) && !defined (__MINGW32__)
+#if defined(_WIN32) && !defined (__MINGW32__) && 0
#include <win32config.h>
#else
#include "config.h"
diff --git a/libxslt/libxslt.h b/libxslt/libxslt.h
index f81066c0..3344c570 100644
--- a/libxslt/libxslt.h
+++ b/libxslt/libxslt.h
@@ -23,7 +23,7 @@
#endif
#endif

-#if defined(_WIN32) && !defined (__MINGW32__)
+#if defined(_WIN32) && !defined (__MINGW32__) && 0
#include <win32config.h>
#else
#include "config.h"
20 changes: 20 additions & 0 deletions patches/libxslt-fix-library-name.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index fb352475..dd306465 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -242,7 +242,6 @@ set_target_properties(
IMPORT_PREFIX lib
OUTPUT_NAME xslt
POSITION_INDEPENDENT_CODE ON
- PREFIX lib
VERSION ${PROJECT_VERSION}
SOVERSION ${LIBXSLT_MAJOR_VERSION}
)
@@ -335,7 +334,6 @@ set_target_properties(
IMPORT_PREFIX lib
OUTPUT_NAME exslt
POSITION_INDEPENDENT_CODE ON
- PREFIX lib
VERSION ${LIBEXSLT_VERSION}
SOVERSION ${LIBEXSLT_MAJOR_VERSION}
)
15 changes: 15 additions & 0 deletions patches/libxslt-fix-pkgconfig.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index fb352475..1d8270f1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -526,6 +524,10 @@ set(EXSLT_INCLUDEDIR "-I\${includedir}")
set(EXSLT_LIBDIR "-L\${libdir}")
set(EXSLT_PRIVATE_LIBS "${XSLT_PRIVATE_LIBS} ${LIBGCRYPT_LIBS} ${LIBM}")

+if(NOT LIBXSLT_SHARED)
+ set(LIBXSLT_CFLAGS -DLIBXSLT_STATIC)
+endif()
+
file(RELATIVE_PATH PACKAGE_RELATIVE_PATH "${CMAKE_INSTALL_FULL_LIBDIR}/pkgconfig" "${CMAKE_INSTALL_PREFIX}")
string(REGEX REPLACE "/$" "" PACKAGE_RELATIVE_PATH "${PACKAGE_RELATIVE_PATH}")

5 changes: 3 additions & 2 deletions phases/16-libxml2.bat
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ ninja || exit /b 1

echo.
echo ### Installing

:: libxml2-export.cmake is generated while installing libxml2
ninja install || exit /b 1

:: remove installed documentation
rmdir /S /Q "%INSTALL_PREFIX%\share\doc\libxml2"
45 changes: 19 additions & 26 deletions phases/17-libxslt.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,31 @@ for /f "usebackq delims=" %%i in (`call %BASH% '../scripts/get-latest-github-rel
:: load environment and prepare project
call "%~dp0\..\scripts\common.bat" prepare_project || exit /b 1

cd "%SRCROOT%\%PROJECT%\win32" || exit /b 1
set BUILD_DIR="%SRCROOT%\%PROJECT%\build-%ARCH%-%BUILD_TYPE%"
if exist "%BUILD_DIR%" (rmdir /S /Q "%BUILD_DIR%" || exit /b 1)
mkdir "%BUILD_DIR%" || exit /b 1
cd "%BUILD_DIR%" || exit /b 1

SET UM_INCLUDE_DIR="%WindowsSdkDir%include\%WindowsSdkVersion%um"

echo.
echo ### Running configure
set CONFIGURE_OPTS=
if "%BUILD_TYPE%" == "Debug" (
set "CONFIGURE_OPTS=cruntime=/MDd debug=yes"
)
cscript configure.js ^
compiler=msvc ^
crypto=no xslt_debug=no ^
%CONFIGURE_OPTS% ^
"prefix=%INSTALL_PREFIX%" ^
"include=%INSTALL_PREFIX%\include" ^
"include=%INSTALL_PREFIX%\include\libxml2" ^
"lib=%INSTALL_PREFIX%\lib" ^
"sodir=%INSTALL_PREFIX%\lib" ^
echo ### Running cmake
cmake .. %CMAKE_OPTIONS% ^
-D BUILD_SHARED_LIBS=NO ^
-D LIBXSLT_WITH_PYTHON=NO ^
-D LIBXSLT_WITH_TESTS=NO ^
-D LIBXSLT_WITH_PROGRAMS=NO ^
-D CMAKE_STATIC_LIBRARY_PREFIX= ^
-D ICU_INCLUDE_DIR=%UM_INCLUDE_DIR% ^
|| exit /b 1

echo.
echo ### Building
:: we only build the static libraries
nmake /f Makefile.msvc libxslta libexslta || exit /b 1
ninja || exit /b 1

echo.
echo ### Installing
:: rename libxslt_a.lib to xslt.lib to allow linking using -lxslt
:: (the wildcard suffix is required to suppress the "file or directory" prompt)
xcopy /Y /F "bin.msvc\libxslt_a.lib" "%INSTALL_PREFIX%\lib\xslt.lib*" || exit /b 1
xcopy /Y /F "bin.msvc\libexslt_a.lib" "%INSTALL_PREFIX%\lib\exslt.lib*" || exit /b 1
xcopy /Y /F /S "%SRCROOT%\%PROJECT%\libxslt\*.h" "%INSTALL_PREFIX%\include\libxslt\" || exit /b 1
xcopy /Y /F /S "%SRCROOT%\%PROJECT%\libexslt\*.h" "%INSTALL_PREFIX%\include\libexslt\" || exit /b 1

:: write pkgconfig file
call "%~dp0\..\scripts\common.bat" write_pkgconfig libxslt %TAG% "-DLIBXSLT_STATIC" "-lxslt" "-lxml2" || exit /b 1
ninja install || exit /b 1

:: remove installed documentation
rmdir /S /Q "%INSTALL_PREFIX%\share\doc\libxslt"
46 changes: 0 additions & 46 deletions scripts/common.bat
Original file line number Diff line number Diff line change
Expand Up @@ -111,49 +111,3 @@ exit /b %errorlevel%
:set_git_remote
set GIT_REMOTE=%1
goto :eof

:write_pkgconfig
set PKGCONFIG_NAME=%~1
set PKGCONFIG_VERSION=%~2
set PKGCONFIG_CFLAGS=%~3
set PKGCONFIG_LIBS=%~4
set PKGCONFIG_LIBS_PRIVATE=%~5
set PKGCONFIG_REQUIRES=%~6

:: trim version prefix
call :trim_pkgconfig_version || exit /b 1

:: use forward slashes for prefix path
set PKGCONFIG_PREFIX=%INSTALL_PREFIX:\=/%

if not exist "%INSTALL_PREFIX%\lib\pkgconfig" (mkdir "%INSTALL_PREFIX%\lib\pkgconfig" || exit /b 1)

echo Writing pkgconfig file...
(
echo prefix=%PKGCONFIG_PREFIX%
echo exec_prefix=${prefix}
echo libdir=${exec_prefix}/lib
echo includedir=${prefix}/include
echo.
echo Name: %PKGCONFIG_NAME%
echo Version: %PKGCONFIG_VERSION%
echo Description: %PKGCONFIG_NAME%
echo Requires: %PKGCONFIG_REQUIRES%
echo.
echo Cflags: -I${includedir} %PKGCONFIG_CFLAGS%
echo Libs: -L${libdir} %PKGCONFIG_LIBS%
echo Libs.private: %PKGCONFIG_LIBS_PRIVATE%
) > %INSTALL_PREFIX%\lib\pkgconfig\%PKGCONFIG_NAME%.pc
goto :eof

:: trims prefix like "v" or "release-" from PKGCONFIG_VERSION
:: and converts underscore version number delimiters to periods
:trim_pkgconfig_version
echo %PKGCONFIG_VERSION:~0,1% | findstr /r [a-z_-] > nul
if %errorlevel% == 0 (
set PKGCONFIG_VERSION=%PKGCONFIG_VERSION:~1%
call :trim_pkgconfig_version || exit /b 1
) else (
set PKGCONFIG_VERSION=%PKGCONFIG_VERSION:_=.%
)
exit /b 0

0 comments on commit 20ac790

Please sign in to comment.