CMake: Introduce option EXPAT_CHAR_TYPE=(char|ushort|wchar_t)

This commit is contained in:
Sebastian Pipping 2019-09-04 21:05:31 +02:00
parent 4a09fc9024
commit 27ec307136
7 changed files with 49 additions and 42 deletions

View File

@ -36,7 +36,7 @@ matrix:
- os: linux
env: MODE=qa-sh CC=i686-w64-mingw32-gcc CXX=i686-w64-mingw32-g++ LD=i686-w64-mingw32-ld QA_PROCESSOR=gcov CMAKE_ARGS="-DCMAKE_SYSTEM_NAME=Windows -DWIN32=ON -DMINGW=ON -DEXPAT_ATTR_INFO=ON"
- os: linux
env: MODE=qa-sh CC=i686-w64-mingw32-gcc CXX=i686-w64-mingw32-g++ LD=i686-w64-mingw32-ld QA_PROCESSOR=gcov CMAKE_ARGS="-DCMAKE_SYSTEM_NAME=Windows -DWIN32=ON -DMINGW=ON -DEXPAT_ATTR_INFO=ON -DEXPAT_UNICODE=ON -DEXPAT_UNICODE_WCHAR_T=ON"
env: MODE=qa-sh CC=i686-w64-mingw32-gcc CXX=i686-w64-mingw32-g++ LD=i686-w64-mingw32-ld QA_PROCESSOR=gcov CMAKE_ARGS="-DCMAKE_SYSTEM_NAME=Windows -DWIN32=ON -DMINGW=ON -DEXPAT_ATTR_INFO=ON -DEXPAT_CHAR_TYPE=wchar_t"
addons:
homebrew:

View File

@ -60,7 +60,7 @@ environment:
# Visual Studio 2010 Win32 XML_UNICODE_WCHAR_T
- GENERATOR: Visual Studio 10 2010
PLATFORM: Win32
CMAKE_ARGS: -DEXPAT_UNICODE=ON -DEXPAT_UNICODE_WCHAR_T=ON
CMAKE_ARGS: -DEXPAT_CHAR_TYPE=wchar_t
EXPAT_DLL: expatwd.dll
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013
@ -73,7 +73,7 @@ environment:
# Visual Studio 2010 x64 XML_UNICODE_WCHAR_T
- GENERATOR: Visual Studio 10 2010 Win64
PLATFORM: x64
CMAKE_ARGS: -DEXPAT_UNICODE=ON -DEXPAT_UNICODE_WCHAR_T=ON
CMAKE_ARGS: -DEXPAT_CHAR_TYPE=wchar_t
EXPAT_DLL: expatwd.dll
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013
@ -86,7 +86,7 @@ environment:
# Visual Studio 2012 Win32 XML_UNICODE_WCHAR_T
- GENERATOR: Visual Studio 11 2012
PLATFORM: Win32
CMAKE_ARGS: -DEXPAT_UNICODE=ON -DEXPAT_UNICODE_WCHAR_T=ON
CMAKE_ARGS: -DEXPAT_CHAR_TYPE=wchar_t
EXPAT_DLL: expatwd.dll
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013
@ -99,7 +99,7 @@ environment:
# Visual Studio 2012 x64 XML_UNICODE_WCHAR_T
- GENERATOR: Visual Studio 11 2012 Win64
PLATFORM: x64
CMAKE_ARGS: -DEXPAT_UNICODE=ON -DEXPAT_UNICODE_WCHAR_T=ON
CMAKE_ARGS: -DEXPAT_CHAR_TYPE=wchar_t
EXPAT_DLL: expatwd.dll
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013
@ -112,7 +112,7 @@ environment:
# Visual Studio 2013 Win32 XML_UNICODE_WCHAR_T
- GENERATOR: Visual Studio 12 2013
PLATFORM: Win32
CMAKE_ARGS: -DEXPAT_UNICODE=ON -DEXPAT_UNICODE_WCHAR_T=ON
CMAKE_ARGS: -DEXPAT_CHAR_TYPE=wchar_t
EXPAT_DLL: expatwd.dll
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013
@ -125,7 +125,7 @@ environment:
# Visual Studio 2013 x64 XML_UNICODE_WCHAR_T
- GENERATOR: Visual Studio 12 2013 Win64
PLATFORM: x64
CMAKE_ARGS: -DEXPAT_UNICODE=ON -DEXPAT_UNICODE_WCHAR_T=ON
CMAKE_ARGS: -DEXPAT_CHAR_TYPE=wchar_t
EXPAT_DLL: expatwd.dll
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013
@ -138,7 +138,7 @@ environment:
# Visual Studio 2015 Win32 XML_UNICODE_WCHAR_T
- GENERATOR: Visual Studio 14 2015
PLATFORM: Win32
CMAKE_ARGS: -DEXPAT_UNICODE=ON -DEXPAT_UNICODE_WCHAR_T=ON
CMAKE_ARGS: -DEXPAT_CHAR_TYPE=wchar_t
EXPAT_DLL: expatwd.dll
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
@ -151,7 +151,7 @@ environment:
# Visual Studio 2015 x64 XML_UNICODE_WCHAR_T
- GENERATOR: Visual Studio 14 2015 Win64
PLATFORM: x64
CMAKE_ARGS: -DEXPAT_UNICODE=ON -DEXPAT_UNICODE_WCHAR_T=ON
CMAKE_ARGS: -DEXPAT_CHAR_TYPE=wchar_t
EXPAT_DLL: expatwd.dll
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
@ -164,7 +164,7 @@ environment:
# Visual Studio 2017 Win32 XML_UNICODE_WCHAR_T
- GENERATOR: Visual Studio 15 2017
PLATFORM: Win32
CMAKE_ARGS: -DEXPAT_UNICODE=ON -DEXPAT_UNICODE_WCHAR_T=ON
CMAKE_ARGS: -DEXPAT_CHAR_TYPE=wchar_t
EXPAT_DLL: expatwd.dll
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
@ -177,7 +177,7 @@ environment:
# Visual Studio 2017 x64 XML_UNICODE_WCHAR_T
- GENERATOR: Visual Studio 15 2017 Win64
PLATFORM: x64
CMAKE_ARGS: -DEXPAT_UNICODE=ON -DEXPAT_UNICODE_WCHAR_T=ON
CMAKE_ARGS: -DEXPAT_CHAR_TYPE=wchar_t
EXPAT_DLL: expatwd.dll
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017

View File

@ -64,8 +64,7 @@ if(NOT WIN32 OR _EXPAT_HELP)
"Make use of syscall SYS_getrandom (ON|OFF|AUTO) [default=AUTO]")
mark_as_advanced(EXPAT_DEV_URANDOM)
endif()
option(EXPAT_UNICODE "Use UTF-16 encoded chars (two bytes) instead of UTF-8" OFF)
option(EXPAT_UNICODE_WCHAR_T "Use wchar_t to represent UTF-16 instead of unsigned short" OFF)
set(EXPAT_CHAR_TYPE "char" CACHE STRING "Character type to use (char|ushort|wchar_t) [default=char]")
option(EXPAT_ATTR_INFO "Define to allow retrieving the byte offsets for attribute names and values" OFF)
mark_as_advanced(EXPAT_ATTR_INFO)
option(EXPAT_LARGE_SIZE "Make XML_GetCurrent* functions return <(unsigned) long long> rather than <(unsigned) long>" OFF)
@ -104,17 +103,24 @@ if(EXPAT_MIN_SIZE)
add_definitions(-DXML_MIN_SIZE)
endif()
if(EXPAT_UNICODE_WCHAR_T AND NOT EXPAT_UNICODE)
message(SEND_ERROR "Option EXPAT_UNICODE_WCHAR_T=ON may not be used without EXPAT_UNICODE=ON.")
set(EXPAT_UNICODE ON)
endif(EXPAT_UNICODE_WCHAR_T AND NOT EXPAT_UNICODE)
if(EXPAT_BUILD_TOOLS AND (EXPAT_UNICODE AND NOT EXPAT_UNICODE_WCHAR_T))
message(SEND_ERROR "The xmlwf tool can not be built with option EXPAT_UNICODE_WCHAR_T=OFF and EXPAT_UNICODE=ON. Either set EXPAT_UNICODE_WCHAR_T=ON or EXPAT_BUILD_TOOLS=OFF.")
if(EXPAT_CHAR_TYPE STREQUAL "char")
set(_EXPAT_UNICODE OFF)
set(_EXPAT_UNICODE_WCHAR_T OFF)
elseif(EXPAT_CHAR_TYPE STREQUAL "ushort")
set(_EXPAT_UNICODE ON)
set(_EXPAT_UNICODE_WCHAR_T OFF)
if(EXPAT_BUILD_TOOLS)
message(SEND_ERROR "The xmlwf tool can not be built with option -DEXPAT_CHAR_TYPE=ushort. Please pass -DEXPAT_CHAR_TYPE=(char|wchar_t) or -DEXPAT_BUILD_TOOLS=OFF.")
endif()
elseif(EXPAT_CHAR_TYPE STREQUAL "wchar_t")
set(_EXPAT_UNICODE ON)
set(_EXPAT_UNICODE_WCHAR_T ON)
else()
message(SEND_ERROR "Option -DEXPAT_CHAR_TYPE=(char|ushort|wchar_t) cannot be \"${EXPAT_CHAR_TYPE}\".")
endif()
if(EXPAT_UNICODE)
if(EXPAT_UNICODE_WCHAR_T)
if(_EXPAT_UNICODE)
if(_EXPAT_UNICODE_WCHAR_T)
add_definitions(-DXML_UNICODE_WCHAR_T) # for wchar_t
else()
add_definitions(-DXML_UNICODE) # for unsigned short
@ -200,7 +206,7 @@ if(MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS -wd4996)
endif(MSVC)
if(WIN32)
if(EXPAT_UNICODE_WCHAR_T)
if(_EXPAT_UNICODE_WCHAR_T)
set(_POSTFIX_WIDE "w")
endif()
@ -303,7 +309,7 @@ if(EXPAT_BUILD_TOOLS)
target_link_libraries(xmlwf expat)
expat_install(TARGETS xmlwf DESTINATION ${CMAKE_INSTALL_BINDIR})
if(MINGW AND EXPAT_UNICODE_WCHAR_T)
if(MINGW AND _EXPAT_UNICODE_WCHAR_T)
# https://gcc.gnu.org/onlinedocs/gcc/x86-Windows-Options.html
set_target_properties(xmlwf PROPERTIES LINK_FLAGS -municode)
endif()
@ -509,14 +515,18 @@ expat_install(
#
# Summary
#
if(EXPAT_UNICODE)
if(EXPAT_UNICODE_WCHAR_T)
set(_EXPAT_CHAR_TYPE "wchar_t")
if(EXPAT_CHAR_TYPE STREQUAL "char")
set(_EXPAT_CHAR_TYPE_SUMMARY "char (UTF-8)")
elseif(EXPAT_CHAR_TYPE STREQUAL "ushort")
set(_EXPAT_CHAR_TYPE_SUMMARY "ushort (unsigned short, UTF-16)")
elseif(EXPAT_CHAR_TYPE STREQUAL "wchar_t")
if(WIN32)
set(_EXPAT_CHAR_TYPE_SUMMARY "wchar_t (UTF-16)")
else()
set(_EXPAT_CHAR_TYPE "unsigned short")
set(_EXPAT_CHAR_TYPE_SUMMARY "wchar_t (UTF-32) // not implemented")
endif()
else()
set(_EXPAT_CHAR_TYPE "char")
set(_EXPAT_CHAR_TYPE_SUMMARY "ERROR")
endif()
string(TOUPPER "${CMAKE_BUILD_TYPE}" _EXPAT_BUILD_TYPE_UPPER)
@ -529,7 +539,7 @@ message(STATUS " Shared libraries ........... ${EXPAT_SHARED_LIBS}")
if(WIN32)
message(STATUS " Static CRT ................. ${EXPAT_MSVC_STATIC_CRT}")
endif()
message(STATUS " Character type ............. ${_EXPAT_CHAR_TYPE}")
message(STATUS " Character type ............. ${_EXPAT_CHAR_TYPE_SUMMARY}")
if(WIN32)
message(STATUS " Binary postfix ............. ${CMAKE_${_EXPAT_BUILD_TYPE_UPPER}_POSTFIX}")
endif()

View File

@ -45,8 +45,8 @@ Release x.x.x xxx xxx xx xxxx
- XML_DEV_URANDOM -> EXPAT_DEV_URANDOM
- XML_DTD -> EXPAT_DTD
- XML_NS -> EXPAT_NS
- XML_UNICODE -> EXPAT_UNICODE
- XML_UNICODE_WCHAR_T -> EXPAT_UNICODE_WCHAR_T
- XML_UNICODE -> EXPAT_CHAR_TYPE=ushort (!)
- XML_UNICODE_WCHAR_T -> EXPAT_CHAR_TYPE=wchar_t (!)
#244 #264 CMake: Add argument -DEXPAT_ATTR_INFO=(ON|OFF),
default OFF
#326 CMake: Add argument -DEXPAT_LARGE_SIZE=(ON|OFF),

View File

@ -162,6 +162,9 @@ EXPAT_BUILD_TESTS:BOOL=ON
// build the xmlwf tool for expat library
EXPAT_BUILD_TOOLS:BOOL=ON
// Character type to use (char|ushort|wchar_t) [default=char]
EXPAT_CHAR_TYPE:STRING=char
// install expat files in cmake install target
EXPAT_ENABLE_INSTALL:BOOL=ON
@ -171,12 +174,6 @@ EXPAT_MSVC_STATIC_CRT:BOOL=OFF
// build a shared expat library
EXPAT_SHARED_LIBS:BOOL=ON
// Use UTF-16 encoded chars (two bytes) instead of UTF-8
EXPAT_UNICODE:BOOL=OFF
// Use wchar_t to represent UTF-16 instead of unsigned short
EXPAT_UNICODE_WCHAR_T:BOOL=OFF
// Treat all compiler warnings as errors
EXPAT_WARNINGS_AS_ERRORS:BOOL=OFF

View File

@ -53,8 +53,8 @@ _register_component(dtd @EXPAT_DTD@)
_register_component(large_size @EXPAT_LARGE_SIZE@)
_register_component(min_size @EXPAT_MIN_SIZE@)
_register_component(ns @EXPAT_NS@)
_register_component(unicode @EXPAT_UNICODE@)
_register_component(unicode_wchar_t @EXPAT_UNICODE_WCHAR_T@)
_register_component(unicode @_EXPAT_UNICODE@)
_register_component(unicode_wchar_t @_EXPAT_UNICODE_WCHAR_T@)
check_required_components(expat)

View File

@ -63,7 +63,7 @@ COPY build_static_char\xmlwf\%CONFIGURATION%\xmlwf.exe %BINDIR%\ || EXIT /b 1
MD build_shared_wchar_t || EXIT /b 1
CD build_shared_wchar_t || EXIT /b 1
cmake -G"%GENERATOR%" -DCMAKE_BUILD_TYPE=%CONFIGURATION% -DEXPAT_MSVC_STATIC_CRT=ON -DEXPAT_BUILD_EXAMPLES=OFF -DEXPAT_BUILD_TESTS=OFF -DEXPAT_BUILD_TOOLS=OFF -DEXPAT_UNICODE=ON -DEXPAT_UNICODE_WCHAR_T=ON .. || EXIT /b 1
cmake -G"%GENERATOR%" -DCMAKE_BUILD_TYPE=%CONFIGURATION% -DEXPAT_MSVC_STATIC_CRT=ON -DEXPAT_BUILD_EXAMPLES=OFF -DEXPAT_BUILD_TESTS=OFF -DEXPAT_BUILD_TOOLS=OFF -DEXPAT_CHAR_TYPE=wchar_t .. || EXIT /b 1
msbuild /m expat.sln || EXIT /b 1
DIR %CONFIGURATION% || EXIT /b 1
CD .. || EXIT /b 1
@ -73,7 +73,7 @@ COPY build_shared_wchar_t\%CONFIGURATION%\expatw.lib %BINDIR%\ || EXIT /b 1
MD build_static_wchar_t || EXIT /b 1
CD build_static_wchar_t || EXIT /b 1
cmake -G"%GENERATOR%" -DCMAKE_BUILD_TYPE=%CONFIGURATION% -DEXPAT_MSVC_STATIC_CRT=ON -DEXPAT_BUILD_EXAMPLES=OFF -DEXPAT_BUILD_TESTS=OFF -DEXPAT_BUILD_TOOLS=OFF -DEXPAT_SHARED_LIBS=OFF -DEXPAT_UNICODE=ON -DEXPAT_UNICODE_WCHAR_T=ON .. || EXIT /b 1
cmake -G"%GENERATOR%" -DCMAKE_BUILD_TYPE=%CONFIGURATION% -DEXPAT_MSVC_STATIC_CRT=ON -DEXPAT_BUILD_EXAMPLES=OFF -DEXPAT_BUILD_TESTS=OFF -DEXPAT_BUILD_TOOLS=OFF -DEXPAT_SHARED_LIBS=OFF -DEXPAT_CHAR_TYPE=wchar_t .. || EXIT /b 1
msbuild /m expat.sln || EXIT /b 1
DIR %CONFIGURATION% || EXIT /b 1
CD .. || EXIT /b 1