2019-08-10 17:50:29 -04:00
# This file is copyrighted under the BSD-license for buildsystem files of KDE
# copyright 2010, Patrick Spendrin <ps_ml@gmx.de>
2019-08-17 08:49:22 -04:00
cmake_minimum_required ( VERSION 3.1.3 )
2019-08-12 14:33:16 -04:00
2019-08-12 14:41:27 -04:00
project ( expat
V E R S I O N
2019-09-13 15:49:44 -04:00
2 . 2 . 9
2019-08-12 14:42:06 -04:00
L A N G U A G E S
C
2019-08-12 14:41:27 -04:00
)
2019-08-10 17:50:29 -04:00
set ( PACKAGE_BUGREPORT "expat-bugs@libexpat.org" )
set ( PACKAGE_NAME "expat" )
2019-08-12 14:41:27 -04:00
set ( PACKAGE_VERSION "${PROJECT_VERSION}" )
2019-08-10 17:50:29 -04:00
set ( PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}" )
set ( PACKAGE_TARNAME "${PACKAGE_NAME}" )
2019-08-29 17:47:01 -04:00
include ( CMakePackageConfigHelpers )
2019-08-10 17:50:29 -04:00
include ( GNUInstallDirs )
2019-08-11 17:44:09 -04:00
#
# Configuration defaults
#
2019-08-10 17:50:29 -04:00
if ( WINCE )
2019-08-30 14:59:41 -04:00
set ( _EXPAT_BUILD_TOOLS_DEFAULT OFF )
2019-08-10 17:50:29 -04:00
else ( )
2019-08-30 14:59:41 -04:00
set ( _EXPAT_BUILD_TOOLS_DEFAULT ON )
2019-08-10 17:50:29 -04:00
endif ( )
2019-08-30 14:59:41 -04:00
if ( MSVC OR NOT _EXPAT_BUILD_TOOLS_DEFAULT )
2019-08-30 15:10:18 -04:00
set ( _EXPAT_BUILD_DOCS_DEFAULT OFF )
2019-08-10 17:50:29 -04:00
else ( )
find_program ( DOCBOOK_TO_MAN NAMES docbook2x-man db2x_docbook2man docbook2man docbook-to-man )
if ( DOCBOOK_TO_MAN )
2019-08-30 15:10:18 -04:00
set ( _EXPAT_BUILD_DOCS_DEFAULT ON )
2019-08-10 17:50:29 -04:00
else ( )
2019-08-30 15:10:18 -04:00
set ( _EXPAT_BUILD_DOCS_DEFAULT OFF )
2019-08-10 17:50:29 -04:00
endif ( )
endif ( )
2019-08-11 17:39:22 -04:00
#
# Configuration
#
2019-08-30 15:00:48 -04:00
option ( EXPAT_BUILD_TOOLS "build the xmlwf tool for expat library" ${ _EXPAT_BUILD_TOOLS_DEFAULT } )
2019-08-30 15:07:48 -04:00
option ( EXPAT_BUILD_EXAMPLES "build the examples for expat library" ON )
2019-08-30 15:08:35 -04:00
option ( EXPAT_BUILD_TESTS "build the tests for expat library" ON )
2019-08-30 15:35:48 -04:00
option ( EXPAT_SHARED_LIBS "build a shared expat library" ON )
2019-08-30 15:12:42 -04:00
option ( EXPAT_BUILD_DOCS "build man page for xmlwf" ${ _EXPAT_BUILD_DOCS_DEFAULT } )
2019-08-30 15:13:41 -04:00
option ( EXPAT_BUILD_FUZZERS "build fuzzers for the expat library" OFF )
2019-11-18 14:49:11 -05:00
option ( EXPAT_OSSFUZZ_BUILD "build fuzzers via ossfuzz for the expat library" OFF )
2019-10-09 16:43:46 -04:00
if ( UNIX OR _EXPAT_HELP )
option ( EXPAT_WITH_LIBBSD "utilize libbsd (for arc4random_buf)" OFF )
endif ( )
2019-08-30 15:32:01 -04:00
option ( EXPAT_ENABLE_INSTALL "install expat files in cmake install target" ON )
2019-08-30 16:06:10 -04:00
set ( EXPAT_CONTEXT_BYTES 1024 CACHE STRING "Define to specify how much context to retain around the current parse point" )
2019-08-30 16:31:56 -04:00
mark_as_advanced ( EXPAT_CONTEXT_BYTES )
2019-08-30 16:06:10 -04:00
option ( EXPAT_DTD "Define to make parameter entity parsing functionality available" ON )
2019-08-30 16:31:56 -04:00
mark_as_advanced ( EXPAT_DTD )
2019-08-30 16:06:10 -04:00
option ( EXPAT_NS "Define to make XML Namespaces functionality available" ON )
2019-08-30 16:31:56 -04:00
mark_as_advanced ( EXPAT_NS )
2019-08-30 15:20:55 -04:00
option ( EXPAT_WARNINGS_AS_ERRORS "Treat all compiler warnings as errors" OFF )
2019-10-09 16:43:46 -04:00
if ( UNIX OR _EXPAT_HELP )
2019-08-30 16:06:10 -04:00
option ( EXPAT_DEV_URANDOM "Define to include code reading entropy from `/dev/urandom'." ON )
2019-08-30 15:22:17 -04:00
set ( EXPAT_WITH_GETRANDOM "AUTO" CACHE STRING
2019-08-11 17:39:22 -04:00
" M a k e u s e o f g e t r a n d o m function ( ON|OFF|AUTO ) [ d e f a u l t = A U T O ] " )
2019-08-30 15:22:51 -04:00
set ( EXPAT_WITH_SYS_GETRANDOM "AUTO" CACHE STRING
2019-08-11 17:39:22 -04:00
" M a k e u s e o f s y s c a l l SYS_getrandom ( ON|OFF|AUTO ) [ d e f a u l t = A U T O ] " )
2019-08-30 16:31:56 -04:00
mark_as_advanced ( EXPAT_DEV_URANDOM )
2019-08-11 17:39:22 -04:00
endif ( )
2019-09-04 15:05:31 -04:00
set ( EXPAT_CHAR_TYPE "char" CACHE STRING "Character type to use (char|ushort|wchar_t) [default=char]" )
2019-08-30 16:06:10 -04:00
option ( EXPAT_ATTR_INFO "Define to allow retrieving the byte offsets for attribute names and values" OFF )
2019-08-30 16:31:56 -04:00
mark_as_advanced ( EXPAT_ATTR_INFO )
2019-08-30 16:06:10 -04:00
option ( EXPAT_LARGE_SIZE "Make XML_GetCurrent* functions return <(unsigned) long long> rather than <(unsigned) long>" OFF )
2019-08-30 16:31:56 -04:00
mark_as_advanced ( EXPAT_LARGE_SIZE )
2019-08-30 16:06:10 -04:00
option ( EXPAT_MIN_SIZE "Get a smaller (but slower) parser (in particular avoid multiple copies of the tokenizer)" OFF )
2019-08-30 16:31:56 -04:00
mark_as_advanced ( EXPAT_MIN_SIZE )
2019-08-30 16:28:30 -04:00
if ( MSVC OR _EXPAT_HELP )
2019-08-30 15:24:29 -04:00
set ( EXPAT_MSVC_STATIC_CRT OFF CACHE BOOL "Use /MT flag (static CRT) when compiling in MSVC" )
2019-08-11 17:39:22 -04:00
endif ( )
2019-08-10 17:50:29 -04:00
2019-08-11 17:44:09 -04:00
#
# Environment checks
#
2019-08-30 15:18:19 -04:00
if ( EXPAT_WITH_LIBBSD )
2019-08-10 17:50:29 -04:00
find_library ( LIB_BSD NAMES bsd )
if ( NOT LIB_BSD )
2019-08-30 15:18:19 -04:00
message ( SEND_ERROR "EXPAT_WITH_LIBBSD option is enabled, but libbsd was not found" )
2019-08-10 17:50:29 -04:00
else ( )
set ( HAVE_LIBBSD TRUE )
endif ( )
endif ( )
2019-08-30 16:06:10 -04:00
macro ( _expat_copy_bool_int source_ref dest_ref )
if ( ${ source_ref } )
set ( ${ dest_ref } 1 )
2019-08-29 18:23:39 -04:00
else ( )
2019-08-30 16:06:10 -04:00
set ( ${ dest_ref } 0 )
2019-08-29 18:23:39 -04:00
endif ( )
endmacro ( )
2019-08-30 16:06:10 -04:00
if ( EXPAT_LARGE_SIZE )
2019-08-29 18:47:54 -04:00
add_definitions ( -DXML_LARGE_SIZE )
endif ( )
2019-08-30 16:06:10 -04:00
if ( EXPAT_MIN_SIZE )
2019-08-30 09:55:38 -04:00
add_definitions ( -DXML_MIN_SIZE )
endif ( )
2019-09-04 15:05:31 -04:00
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 )
2019-10-09 17:10:28 -04:00
if ( EXPAT_BUILD_EXAMPLES )
message ( SEND_ERROR "Examples can not be built with option -DEXPAT_CHAR_TYPE=ushort. Please pass -DEXPAT_CHAR_TYPE=(char|wchar_t) or -DEXPAT_BUILD_EXAMPLES=OFF." )
endif ( )
if ( EXPAT_BUILD_TESTS )
message ( SEND_ERROR "The testsuite can not be built with option -DEXPAT_CHAR_TYPE=ushort. Please pass -DEXPAT_CHAR_TYPE=(char|wchar_t) or -DEXPAT_BUILD_TESTS=OFF." )
endif ( )
2019-09-04 15:05:31 -04:00
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 )
2019-10-11 17:22:49 -04:00
if ( NOT WIN32 )
string ( FIND "${CMAKE_C_FLAGS}" "-fshort-wchar" _expat_short_wchar_found )
if ( ${ _expat_short_wchar_found } EQUAL "-1" )
message ( SEND_ERROR "Configuration -DEXPAT_CHAR_TYPE=wchar_t requires -DCMAKE_{C,CXX}_FLAGS=-fshort-wchar (which was not found) and libc compiled with -fshort-wchar, too." )
endif ( )
if ( EXPAT_BUILD_TOOLS )
message ( SEND_ERROR "The xmlwf tool can not be built with option -DEXPAT_CHAR_TYPE=wchar_t outside of Windows. Please pass -DEXPAT_CHAR_TYPE=char or -DEXPAT_BUILD_TOOLS=OFF." )
endif ( )
endif ( )
2019-09-04 15:05:31 -04:00
else ( )
message ( SEND_ERROR "Option -DEXPAT_CHAR_TYPE=(char|ushort|wchar_t) cannot be \" ${ EXPAT_CHAR_TYPE } \".")
2019-08-10 17:50:29 -04:00
endif ( )
2019-09-04 15:05:31 -04:00
if ( _EXPAT_UNICODE )
2019-09-04 15:20:48 -04:00
add_definitions ( -DXML_UNICODE ) # for unsigned short
2019-09-04 15:05:31 -04:00
if ( _EXPAT_UNICODE_WCHAR_T )
2019-09-02 17:48:25 -04:00
add_definitions ( -DXML_UNICODE_WCHAR_T ) # for wchar_t
endif ( )
endif ( )
2019-08-10 17:50:29 -04:00
include ( ${ CMAKE_CURRENT_LIST_DIR } /ConfigureChecks.cmake )
macro ( evaluate_detection_results use_ref have_ref thing_lower thing_title )
if ( ${ use_ref } AND NOT ( ${ use_ref } STREQUAL "AUTO" ) AND NOT ${ have_ref } )
message ( SEND_ERROR
" U s e o f $ { t h i n g _ l o w e r } w a s e n f o r c e d b y $ { u s e _ r e f } = O N b u t i t c o u l d n o t b e f o u n d . " )
elseif ( NOT ${ use_ref } AND ${ have_ref } )
message ( "${thing_title} was found but it will not be used due to ${use_ref}=OFF." )
set ( ${ have_ref } 0 )
endif ( )
endmacro ( )
if ( NOT WIN32 )
2019-08-30 15:22:17 -04:00
evaluate_detection_results ( EXPAT_WITH_GETRANDOM HAVE_GETRANDOM "function getrandom" "Function getrandom" )
2019-08-30 15:22:51 -04:00
evaluate_detection_results ( EXPAT_WITH_SYS_GETRANDOM HAVE_SYSCALL_GETRANDOM "syscall SYS_getrandom" "Syscall SYS_getrandom" )
2019-08-10 17:50:29 -04:00
endif ( )
2019-08-30 16:06:10 -04:00
_expat_copy_bool_int ( EXPAT_ATTR_INFO XML_ATTR_INFO )
_expat_copy_bool_int ( EXPAT_DTD XML_DTD )
_expat_copy_bool_int ( EXPAT_LARGE_SIZE XML_LARGE_SIZE )
_expat_copy_bool_int ( EXPAT_MIN_SIZE XML_MIN_SIZE )
_expat_copy_bool_int ( EXPAT_NS XML_NS )
if ( NOT WIN32 )
_expat_copy_bool_int ( EXPAT_DEV_URANDOM XML_DEV_URANDOM )
endif ( )
set ( XML_CONTEXT_BYTES ${ EXPAT_CONTEXT_BYTES } )
2019-08-29 17:08:35 -04:00
macro ( expat_install )
2019-08-30 15:32:01 -04:00
if ( EXPAT_ENABLE_INSTALL )
2019-08-29 17:08:35 -04:00
install ( ${ ARGN } )
endif ( )
endmacro ( )
2019-08-10 17:50:29 -04:00
configure_file ( expat_config.h.cmake "${CMAKE_CURRENT_BINARY_DIR}/expat_config.h" )
add_definitions ( -DHAVE_EXPAT_CONFIG_H )
2019-08-29 17:09:26 -04:00
expat_install ( FILES "${CMAKE_CURRENT_BINARY_DIR}/expat_config.h" DESTINATION ${ CMAKE_INSTALL_INCLUDEDIR } )
2019-08-10 17:50:29 -04:00
set ( EXTRA_COMPILE_FLAGS )
if ( FLAG_NO_STRICT_ALIASING )
set ( EXTRA_COMPILE_FLAGS "${EXTRA_COMPILE_FLAGS} -fno-strict-aliasing" )
endif ( )
if ( FLAG_VISIBILITY )
add_definitions ( -DXML_ENABLE_VISIBILITY=1 )
set ( EXTRA_COMPILE_FLAGS "${EXTRA_COMPILE_FLAGS} -fvisibility=hidden" )
endif ( FLAG_VISIBILITY )
2019-08-30 15:20:55 -04:00
if ( EXPAT_WARNINGS_AS_ERRORS )
2019-08-10 17:50:29 -04:00
if ( MSVC )
add_definitions ( /WX )
else ( MSVC )
set ( EXTRA_COMPILE_FLAGS "${EXTRA_COMPILE_FLAGS} -Werror" )
endif ( MSVC )
2019-08-30 15:20:55 -04:00
endif ( EXPAT_WARNINGS_AS_ERRORS )
2019-08-10 17:50:29 -04:00
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_COMPILE_FLAGS}" )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_COMPILE_FLAGS}" )
if ( MSVC )
2019-08-30 15:24:29 -04:00
if ( EXPAT_MSVC_STATIC_CRT )
message ( "-- Using static CRT ${EXPAT_MSVC_STATIC_CRT}" )
2019-08-10 17:50:29 -04:00
foreach ( flag_var
C M A K E _ C X X _ F L A G S _ D E B U G
C M A K E _ C X X _ F L A G S _ R E L E A S E
C M A K E _ C X X _ F L A G S _ M I N S I Z E R E L
C M A K E _ C X X _ F L A G S _ R E L W I T H D E B I N F O
C M A K E _ C _ F L A G S _ D E B U G
C M A K E _ C _ F L A G S _ R E L E A S E
C M A K E _ C _ F L A G S _ M I N S I Z E R E L
C M A K E _ C _ F L A G S _ R E L W I T H D E B I N F O
)
string ( REPLACE "/MD" "/MT" ${ flag_var } "${${flag_var}}" )
endforeach ( )
endif ( )
endif ( )
include_directories ( ${ CMAKE_CURRENT_BINARY_DIR } ${ CMAKE_CURRENT_SOURCE_DIR } /lib )
if ( MSVC )
add_definitions ( -D_CRT_SECURE_NO_WARNINGS -wd4996 )
endif ( MSVC )
if ( WIN32 )
2019-09-04 15:05:31 -04:00
if ( _EXPAT_UNICODE_WCHAR_T )
2019-08-15 16:33:22 -04:00
set ( _POSTFIX_WIDE "w" )
endif ( )
2019-09-04 15:29:46 -04:00
if ( MSVC AND NOT EXPAT_SHARED_LIBS )
2019-08-30 15:24:29 -04:00
if ( EXPAT_MSVC_STATIC_CRT )
2019-08-28 19:59:14 -04:00
set ( _POSTFIX_CRT "MT" )
else ( )
set ( _POSTFIX_CRT "MD" )
endif ( )
endif ( )
2019-08-15 16:33:22 -04:00
foreach ( postfix_var
C M A K E _ D E B U G _ P O S T F I X
C M A K E _ R E L E A S E _ P O S T F I X
C M A K E _ M I N S I Z E R E L _ P O S T F I X
C M A K E _ R E L W I T H D E B I N F O _ P O S T F I X
)
if ( postfix_var STREQUAL "CMAKE_DEBUG_POSTFIX" )
set ( _POSTFIX_DEBUG "d" )
else ( )
set ( _POSTFIX_DEBUG "" )
endif ( )
2019-09-21 12:14:37 -04:00
set ( ${ postfix_var } "${_POSTFIX_WIDE}${_POSTFIX_DEBUG}${_POSTFIX_CRT}" CACHE STRING "Windows binary postfix, e.g. libexpat<postfix=[w][d][MD|MT]>.lib" )
2019-08-15 16:33:22 -04:00
endforeach ( )
2019-08-10 17:50:29 -04:00
endif ( WIN32 )
2019-08-11 17:44:09 -04:00
#
# C library
#
2019-08-10 17:50:29 -04:00
set ( expat_SRCS
l i b / x m l p a r s e . c
l i b / x m l r o l e . c
l i b / x m l t o k . c
2019-09-02 14:46:04 -04:00
# NOTE: ISO C forbids an empty translation unit
# lib/xmltok_impl.c
# lib/xmltok_ns.c
2019-08-10 17:50:29 -04:00
)
2019-08-30 15:35:48 -04:00
if ( EXPAT_SHARED_LIBS )
2019-08-10 17:50:29 -04:00
set ( _SHARED SHARED )
if ( MSVC )
set ( expat_SRCS ${ expat_SRCS } lib/libexpat.def )
endif ( MSVC )
2019-08-30 15:35:48 -04:00
else ( EXPAT_SHARED_LIBS )
2019-08-10 17:50:29 -04:00
set ( _SHARED STATIC )
if ( WIN32 )
add_definitions ( -DXML_STATIC )
endif ( WIN32 )
2019-08-30 15:35:48 -04:00
endif ( EXPAT_SHARED_LIBS )
2019-08-10 17:50:29 -04:00
2019-09-21 12:14:37 -04:00
# Avoid colliding with Expat.dll of Perl's XML::Parser::Expat
if ( WIN32 AND NOT MINGW )
2019-10-09 17:14:21 -04:00
set ( _EXPAT_TARGET libexpat ) # CMAKE_*_POSTFIX applies, see above
2019-09-21 12:14:37 -04:00
else ( )
2019-10-09 17:14:21 -04:00
if ( _EXPAT_UNICODE )
set ( _EXPAT_TARGET expatw )
else ( )
set ( _EXPAT_TARGET expat )
endif ( )
2019-09-21 12:14:37 -04:00
endif ( )
add_library ( ${ _EXPAT_TARGET } ${ _SHARED } ${ expat_SRCS } )
2019-08-30 15:18:19 -04:00
if ( EXPAT_WITH_LIBBSD )
2019-09-21 12:14:37 -04:00
target_link_libraries ( ${ _EXPAT_TARGET } ${ LIB_BSD } )
2019-08-10 17:50:29 -04:00
endif ( )
2019-09-13 15:44:39 -04:00
set ( LIBCURRENT 7 ) # sync
2019-09-25 15:26:10 -04:00
set ( LIBREVISION 11 ) # with
2019-09-13 15:44:39 -04:00
set ( LIBAGE 6 ) # configure.ac!
2019-08-10 17:50:29 -04:00
math ( EXPR LIBCURRENT_MINUS_AGE "${LIBCURRENT} - ${LIBAGE}" )
if ( NOT WIN32 )
2019-09-21 12:14:37 -04:00
set_property ( TARGET ${ _EXPAT_TARGET } PROPERTY VERSION ${ LIBCURRENT_MINUS_AGE } . ${ LIBAGE } . ${ LIBREVISION } )
set_property ( TARGET ${ _EXPAT_TARGET } PROPERTY SOVERSION ${ LIBCURRENT_MINUS_AGE } )
set_property ( TARGET ${ _EXPAT_TARGET } PROPERTY NO_SONAME ${ NO_SONAME } )
2019-08-10 17:50:29 -04:00
endif ( NOT WIN32 )
2019-09-21 12:14:37 -04:00
expat_install ( TARGETS ${ _EXPAT_TARGET } EXPORT expat
2019-08-29 17:47:01 -04:00
R U N T I M E D E S T I N A T I O N $ { C M A K E _ I N S T A L L _ B I N D I R }
2019-08-10 17:50:29 -04:00
L I B R A R Y D E S T I N A T I O N $ { C M A K E _ I N S T A L L _ L I B D I R }
A R C H I V E D E S T I N A T I O N $ { C M A K E _ I N S T A L L _ L I B D I R } )
2019-08-11 17:56:23 -04:00
expat_install ( FILES lib/expat.h lib/expat_external.h DESTINATION ${ CMAKE_INSTALL_INCLUDEDIR } )
2019-08-11 17:44:09 -04:00
#
# pkg-config file
#
2019-09-01 18:32:08 -04:00
if ( NOT MSVC )
set ( prefix ${ CMAKE_INSTALL_PREFIX } )
set ( exec_prefix "\${prefix}" )
set ( libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}" )
set ( includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}" )
2019-10-09 17:14:21 -04:00
configure_file ( expat.pc.in ${ CMAKE_CURRENT_BINARY_DIR } / ${ _EXPAT_TARGET } .pc @ONLY )
expat_install ( FILES ${ CMAKE_CURRENT_BINARY_DIR } / ${ _EXPAT_TARGET } .pc DESTINATION ${ CMAKE_INSTALL_LIBDIR } /pkgconfig )
2019-09-01 18:32:08 -04:00
endif ( )
2019-08-10 17:50:29 -04:00
2019-08-11 17:44:09 -04:00
#
# C command line tool xmlwf
#
2019-08-30 15:00:48 -04:00
if ( EXPAT_BUILD_TOOLS )
2019-08-10 17:50:29 -04:00
set ( xmlwf_SRCS
x m l w f / x m l w f . c
x m l w f / x m l f i l e . c
x m l w f / c o d e p a g e . c
x m l w f / r e a d f i l e m a p . c
)
add_executable ( xmlwf ${ xmlwf_SRCS } )
set_property ( TARGET xmlwf PROPERTY RUNTIME_OUTPUT_DIRECTORY xmlwf )
2019-09-21 12:14:37 -04:00
target_link_libraries ( xmlwf ${ _EXPAT_TARGET } )
2019-08-10 17:50:29 -04:00
expat_install ( TARGETS xmlwf DESTINATION ${ CMAKE_INSTALL_BINDIR } )
2019-09-02 18:10:57 -04:00
2019-09-04 15:05:31 -04:00
if ( MINGW AND _EXPAT_UNICODE_WCHAR_T )
2019-09-02 18:10:57 -04:00
# https://gcc.gnu.org/onlinedocs/gcc/x86-Windows-Options.html
set_target_properties ( xmlwf PROPERTIES LINK_FLAGS -municode )
endif ( )
2019-08-30 15:12:42 -04:00
if ( EXPAT_BUILD_DOCS )
2019-08-10 17:50:29 -04:00
file ( MAKE_DIRECTORY ${ PROJECT_BINARY_DIR } /doc )
2019-09-21 12:14:37 -04:00
add_custom_command ( TARGET ${ _EXPAT_TARGET } PRE_BUILD COMMAND "${DOCBOOK_TO_MAN}" "${PROJECT_SOURCE_DIR}/doc/xmlwf.xml" && mv "XMLWF.1" "${PROJECT_BINARY_DIR}/doc/xmlwf.1" )
2019-08-10 17:50:29 -04:00
expat_install ( FILES "${PROJECT_BINARY_DIR}/doc/xmlwf.1" DESTINATION ${ CMAKE_INSTALL_MANDIR } /man1 )
2019-10-12 11:57:39 -04:00
elseif ( EXISTS ${ PROJECT_SOURCE_DIR } /doc/xmlwf.1 )
expat_install ( FILES "${PROJECT_SOURCE_DIR}/doc/xmlwf.1" DESTINATION ${ CMAKE_INSTALL_MANDIR } /man1 )
2019-09-01 16:50:24 -04:00
endif ( )
2019-08-10 17:50:29 -04:00
endif ( )
2019-08-11 17:44:09 -04:00
#
# C code examples
#
2019-08-30 15:07:48 -04:00
if ( EXPAT_BUILD_EXAMPLES )
2019-08-10 17:50:29 -04:00
add_executable ( elements examples/elements.c )
set_property ( TARGET elements PROPERTY RUNTIME_OUTPUT_DIRECTORY examples )
2019-09-21 12:14:37 -04:00
target_link_libraries ( elements ${ _EXPAT_TARGET } )
2019-08-10 17:50:29 -04:00
add_executable ( outline examples/outline.c )
set_property ( TARGET outline PROPERTY RUNTIME_OUTPUT_DIRECTORY examples )
2019-09-21 12:14:37 -04:00
target_link_libraries ( outline ${ _EXPAT_TARGET } )
2019-08-30 15:07:48 -04:00
endif ( EXPAT_BUILD_EXAMPLES )
2019-08-10 17:50:29 -04:00
2019-08-11 17:44:09 -04:00
#
# C/C++ test runners
#
2019-08-30 15:08:35 -04:00
if ( EXPAT_BUILD_TESTS )
2019-08-10 17:50:29 -04:00
## these are unittests that can be run on any platform
2019-08-12 14:42:06 -04:00
enable_language ( CXX )
2019-08-12 14:31:47 -04:00
enable_testing ( )
2019-08-11 16:46:44 -04:00
set ( test_SRCS
t e s t s / c h a r d a t a . c
t e s t s / m e m c h e c k . c
t e s t s / m i n i c h e c k . c
t e s t s / s t r u c t d a t a . c
)
2019-09-01 16:49:54 -04:00
if ( NOT MSVC )
if ( MINGW )
set ( host whatever-mingw32 ) # for nothing but run.sh
endif ( )
configure_file ( ${ CMAKE_CURRENT_SOURCE_DIR } /run.sh.in run.sh @ONLY )
endif ( )
function ( expat_add_test _name _file )
if ( MSVC )
add_test ( NAME ${ _name } COMMAND ${ _file } )
else ( )
add_test ( NAME ${ _name } COMMAND bash run.sh ${ _file } )
endif ( )
endfunction ( )
2019-08-11 16:46:44 -04:00
add_executable ( runtests tests/runtests.c ${ test_SRCS } )
2019-08-10 17:50:29 -04:00
set_property ( TARGET runtests PROPERTY RUNTIME_OUTPUT_DIRECTORY tests )
2019-09-21 12:14:37 -04:00
target_link_libraries ( runtests ${ _EXPAT_TARGET } )
2019-09-01 16:49:54 -04:00
expat_add_test ( runtests $< TARGET_FILE:runtests > )
2019-08-10 17:50:29 -04:00
2019-08-11 16:46:44 -04:00
add_executable ( runtestspp tests/runtestspp.cpp ${ test_SRCS } )
2019-08-10 17:50:29 -04:00
set_property ( TARGET runtestspp PROPERTY RUNTIME_OUTPUT_DIRECTORY tests )
2019-09-21 12:14:37 -04:00
target_link_libraries ( runtestspp ${ _EXPAT_TARGET } )
2019-09-01 16:49:54 -04:00
expat_add_test ( runtestspp $< TARGET_FILE:runtestspp > )
2019-08-30 15:08:35 -04:00
endif ( EXPAT_BUILD_TESTS )
2019-08-11 17:28:39 -04:00
2019-08-30 15:13:41 -04:00
if ( EXPAT_BUILD_FUZZERS )
2019-08-28 11:51:31 -04:00
if ( NOT "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" )
2019-08-28 06:57:57 -04:00
message ( SEND_ERROR
2019-08-28 18:58:26 -04:00
" B u i l d i n g f u z z t a r g e t s w i t h o u t Clang ( but ${ CMAKE_C_COMPILER_ID } ) "
2019-08-28 19:00:43 -04:00
" i s n o t s u p p o r t e d . P l e a s e s e t "
" - D C M A K E _ C _ C O M P I L E R = c l a n g - D C M A K E _ C X X _ C O M P I L E R = c l a n g + + . " )
2019-08-28 06:57:57 -04:00
endif ( )
2019-11-18 14:49:11 -05:00
string ( FIND "${CMAKE_C_FLAGS}" "-fsanitize" sanitizer_present )
2019-08-28 06:57:57 -04:00
if ( ${ sanitizer_present } EQUAL "-1" )
message ( WARNING
" T h e r e w a s n o s a n i t i z e r p r e s e n t w h e n b u i l d i n g t h e f u z z t a r g e t s . "
" T h i s i s l i k e l y i n e r r o r - c o n s i d e r a d d i n g "
" - D C M A K E _ C _ F L A G S = ' - f s a n i t i z e = < s a n i t i z e r > ' a n d "
2019-08-28 19:00:43 -04:00
" - D C M A K E _ C X X _ F L A G S = ' - f s a n i t i z e = < s a n i t i z e r > ' a n d "
2019-09-03 15:44:47 -04:00
" - D C M A K E _ S T A T I C _ L I N K E R _ F L A G S = ' - f s a n i t i z e = < s a n i t i z e r > ' a n d "
2019-08-28 06:57:57 -04:00
" - D C M A K E _ E X E _ L I N K E R _ F L A G S = ' - f s a n i t i z e = < s a n i t i z e r > ' t o y o u r c m a k e "
" e x e c u t i o n . " )
endif ( )
2019-11-18 14:49:11 -05:00
if ( EXPAT_OSSFUZZ_BUILD AND NOT DEFINED ENV{LIB_FUZZING_ENGINE} )
message ( SEND_ERROR
" O S S - F u z z b u i l d s r e q u i r e t h e e n v i r o n m e n t v a r i a b l e "
" L I B _ F U Z Z I N G _ E N G I N E t o b e s e t . I f y o u a r e s e e i n g t h i s "
" w a r n i n g , i t p o i n t s t o a d e e p e r p r o b l e m i n t h e o s s f u z z "
" b u i l d s e t u p . " )
endif ( EXPAT_OSSFUZZ_BUILD AND NOT DEFINED ENV{LIB_FUZZING_ENGINE} )
2019-08-28 06:57:57 -04:00
set ( encoding_types UTF-16 UTF-8 ISO-8859-1 US-ASCII UTF-16BE UTF-16LE )
set ( fuzz_targets xml_parse_fuzzer xml_parsebuffer_fuzzer )
2019-09-03 15:44:47 -04:00
add_library ( fuzzpat STATIC ${ expat_SRCS } )
2019-11-18 14:49:11 -05:00
if ( NOT EXPAT_OSSFUZZ_BUILD )
target_compile_options ( fuzzpat PRIVATE -fsanitize=fuzzer-no-link )
endif ( NOT EXPAT_OSSFUZZ_BUILD )
2019-09-03 15:44:47 -04:00
2019-08-28 06:57:57 -04:00
foreach ( fuzz_target ${ fuzz_targets } )
foreach ( encoding_type ${ encoding_types } )
set ( target_name ${ fuzz_target } _ ${ encoding_type } )
2019-09-03 15:44:47 -04:00
add_executable ( ${ target_name } fuzz/ ${ fuzz_target } .c )
target_link_libraries ( ${ target_name } fuzzpat )
2019-08-28 06:57:57 -04:00
target_compile_definitions ( ${ target_name }
P R I V A T E E N C O D I N G _ F O R _ F U Z Z I N G = $ { e n c o d i n g _ t y p e } )
2019-11-18 14:49:11 -05:00
if ( NOT EXPAT_OSSFUZZ_BUILD )
target_compile_options ( ${ target_name } PRIVATE -fsanitize=fuzzer-no-link )
endif ( NOT EXPAT_OSSFUZZ_BUILD )
2019-08-28 12:08:44 -04:00
# NOTE: Avoiding target_link_options here only because it needs CMake >=3.13
2019-11-18 14:49:11 -05:00
if ( EXPAT_OSSFUZZ_BUILD )
set_target_properties ( ${ target_name } PROPERTIES LINK_FLAGS $ENV{ LIB_FUZZING_ENGINE } )
set_target_properties ( ${ target_name } PROPERTIES LINKER_LANGUAGE "CXX" )
else ( )
set_target_properties ( ${ target_name } PROPERTIES LINK_FLAGS -fsanitize=fuzzer )
2019-11-29 07:29:45 -05:00
endif ( EXPAT_OSSFUZZ_BUILD )
2019-08-28 06:57:57 -04:00
set_property (
T A R G E T $ { t a r g e t _ n a m e } P R O P E R T Y R U N T I M E _ O U T P U T _ D I R E C T O R Y f u z z )
endforeach ( )
endforeach ( )
2019-11-18 14:49:11 -05:00
else ( )
if ( EXPAT_OSSFUZZ_BUILD )
message ( SEND_ERROR
" A t t e m p t i n g t o p e r f o r m a n o s s f u z z b u i l d w i t h o u t t u r n i n g o n t h e f u z z e r b u i l d . "
" T h i s i s l i k e l y i n e r r o r - c o n s i d e r a d d i n g "
" - D E X P A T _ B U I L D _ F U Z Z E R S = O N t o y o u r c m a k e e x e c u t i o n . " )
endif ( EXPAT_OSSFUZZ_BUILD )
2019-08-30 15:13:41 -04:00
endif ( EXPAT_BUILD_FUZZERS )
2019-08-28 06:57:57 -04:00
2019-09-01 16:51:18 -04:00
#
# Custom target "run-xmltest"
#
if ( EXPAT_BUILD_TOOLS AND NOT MSVC )
add_custom_target (
x m l t s - z i p - d o w n l o a d e d
C O M M A N D
s h - c ' t e s t - f x m l t s . z i p | | w g e t - - o u t p u t - d o c u m e n t = x m l t s . z i p h t t p s : / / w w w . w 3 . o r g / X M L / T e s t / x m l t s 2 0 0 8 0 8 2 7 . z i p '
B Y P R O D U C T S
t e s t s / x m l t s . z i p
W O R K I N G _ D I R E C T O R Y
t e s t s / )
add_custom_target (
x m l t s - z i p - e x t r a c t e d
C O M M A N D
s h - c ' t e s t - d x m l c o n f | | u n z i p - q x m l t s . z i p '
B Y P R O D U C T S
t e s t s / x m l c o n f
W O R K I N G _ D I R E C T O R Y
t e s t s / )
add_dependencies ( xmlts-zip-extracted xmlts-zip-downloaded )
add_custom_target (
x m l t e s t - s h - b e e n - r u n
C O M M A N D
s h - c ' $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / t e s t s / x m l t e s t . s h " b a s h $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / r u n . s h $ < T A R G E T _ F I L E : x m l w f > " 2 > & 1 | t e e t e s t s / x m l t e s t . l o g '
B Y P R O D U C T S
t e s t s / x m l t e s t . l o g )
add_dependencies ( xmltest-sh-been-run xmlts-zip-extracted xmlwf )
add_custom_target (
x m l t e s t - l o g - f i x e d
C O M M A N D
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / f i x - x m l t e s t - l o g . s h t e s t s / x m l t e s t . l o g
D E P E N D S
t e s t s / x m l t e s t . l o g )
add_dependencies ( xmltest-log-fixed xmltest-sh-been-run )
add_custom_target (
x m l t e s t - l o g - v e r i f i e d
C O M M A N D
d i f f - u $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / t e s t s / x m l t e s t . l o g . e x p e c t e d t e s t s / x m l t e s t . l o g )
add_dependencies ( xmltest-log-verified xmltest-log-fixed )
add_custom_target ( run-xmltest )
add_dependencies ( run-xmltest xmltest-log-verified )
endif ( )
2019-08-29 17:19:44 -04:00
#
# Documentation
#
configure_file ( Changes changelog COPYONLY )
expat_install (
F I L E S
A U T H O R S
$ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / c h a n g e l o g
D E S T I N A T I O N
$ { C M A K E _ I N S T A L L _ D O C D I R } )
2019-08-29 17:47:01 -04:00
#
# CMake files for find_package(expat [..] CONFIG [..])
#
configure_package_config_file (
c m a k e / e x p a t - c o n f i g . c m a k e . i n
c m a k e / e x p a t - c o n f i g . c m a k e
I N S T A L L _ D E S T I N A T I O N
$ { C M A K E _ I N S T A L L _ L I B D I R } / c m a k e / e x p a t - $ { P R O J E C T _ V E R S I O N } /
)
write_basic_package_version_file (
c m a k e / e x p a t - c o n f i g - v e r s i o n . c m a k e
C O M P A T I B I L I T Y S a m e M a j o r V e r s i o n # i.e. semver
)
export (
T A R G E T S
2019-09-21 12:14:37 -04:00
$ { _ E X P A T _ T A R G E T }
2019-08-29 17:47:01 -04:00
F I L E
c m a k e / e x p a t - t a r g e t s . c m a k e # not going to be installed
)
expat_install (
F I L E S
$ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / c m a k e / e x p a t - c o n f i g . c m a k e
$ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / c m a k e / e x p a t - c o n f i g - v e r s i o n . c m a k e
D E S T I N A T I O N
$ { C M A K E _ I N S T A L L _ L I B D I R } / c m a k e / e x p a t - $ { P R O J E C T _ V E R S I O N } /
)
expat_install (
E X P O R T
e x p a t
D E S T I N A T I O N
$ { C M A K E _ I N S T A L L _ L I B D I R } / c m a k e / e x p a t - $ { P R O J E C T _ V E R S I O N } /
N A M E S P A C E
e x p a t : :
)
2019-08-11 17:28:39 -04:00
#
# Summary
#
2019-09-04 15:05:31 -04:00
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)" )
2019-08-11 17:28:39 -04:00
else ( )
2019-09-04 15:05:31 -04:00
set ( _EXPAT_CHAR_TYPE_SUMMARY "wchar_t (UTF-32) // not implemented" )
2019-08-11 17:28:39 -04:00
endif ( )
else ( )
2019-09-04 15:05:31 -04:00
set ( _EXPAT_CHAR_TYPE_SUMMARY "ERROR" )
2019-08-11 17:28:39 -04:00
endif ( )
2019-08-15 16:33:22 -04:00
string ( TOUPPER "${CMAKE_BUILD_TYPE}" _EXPAT_BUILD_TYPE_UPPER )
2019-08-11 17:28:39 -04:00
message ( STATUS "===========================================================================" )
message ( STATUS "" )
message ( STATUS "Configuration" )
message ( STATUS " Prefix ..................... ${CMAKE_INSTALL_PREFIX}" )
2019-08-17 08:31:16 -04:00
message ( STATUS " Build type ................. ${CMAKE_BUILD_TYPE}" )
2019-08-30 15:35:48 -04:00
message ( STATUS " Shared libraries ........... ${EXPAT_SHARED_LIBS}" )
2019-09-04 15:29:46 -04:00
if ( MSVC )
2019-08-30 15:24:29 -04:00
message ( STATUS " Static CRT ................. ${EXPAT_MSVC_STATIC_CRT}" )
2019-08-11 17:28:39 -04:00
endif ( )
2019-09-04 15:05:31 -04:00
message ( STATUS " Character type ............. ${_EXPAT_CHAR_TYPE_SUMMARY}" )
2019-08-15 16:33:22 -04:00
if ( WIN32 )
message ( STATUS " Binary postfix ............. ${CMAKE_${_EXPAT_BUILD_TYPE_UPPER}_POSTFIX}" )
endif ( )
2019-08-11 17:28:39 -04:00
message ( STATUS "" )
2019-08-30 15:12:42 -04:00
message ( STATUS " Build documentation ........ ${EXPAT_BUILD_DOCS}" )
2019-08-30 15:07:48 -04:00
message ( STATUS " Build examples ............. ${EXPAT_BUILD_EXAMPLES}" )
2019-08-30 15:13:41 -04:00
message ( STATUS " Build fuzzers .............. ${EXPAT_BUILD_FUZZERS}" )
2019-08-30 15:08:35 -04:00
message ( STATUS " Build tests ................ ${EXPAT_BUILD_TESTS}" )
2019-08-30 15:00:48 -04:00
message ( STATUS " Build tools (xmlwf) ........ ${EXPAT_BUILD_TOOLS}" )
2019-08-30 15:32:01 -04:00
message ( STATUS " Install files .............. ${EXPAT_ENABLE_INSTALL}" )
2019-08-11 17:28:39 -04:00
message ( STATUS "" )
message ( STATUS " Features" )
2019-08-30 16:31:56 -04:00
message ( STATUS " // Advanced options, changes not advised" )
2019-08-30 16:06:10 -04:00
message ( STATUS " Attributes info .......... ${EXPAT_ATTR_INFO}" )
message ( STATUS " Context bytes ............ ${EXPAT_CONTEXT_BYTES}" )
message ( STATUS " DTD support .............. ${EXPAT_DTD}" )
message ( STATUS " Large size ............... ${EXPAT_LARGE_SIZE}" )
2019-08-30 16:16:21 -04:00
message ( STATUS " Minimum size ............. ${EXPAT_MIN_SIZE}" )
2019-08-30 16:06:10 -04:00
message ( STATUS " Namespace support ........ ${EXPAT_NS}" )
2019-08-11 17:28:39 -04:00
message ( STATUS "" )
message ( STATUS " Entropy sources" )
if ( WIN32 )
message ( STATUS " rand_s ................... ON" )
else ( )
message ( STATUS " getrandom ................ ${HAVE_GETRANDOM}" )
message ( STATUS " syscall SYS_getrandom .... ${HAVE_SYSCALL_GETRANDOM}" )
2019-08-30 15:18:19 -04:00
message ( STATUS " libbsd ................... ${EXPAT_WITH_LIBBSD}" )
2019-08-30 16:06:10 -04:00
message ( STATUS " /dev/random .............. ${EXPAT_DEV_URANDOM}" )
2019-08-11 17:28:39 -04:00
endif ( )
message ( STATUS "" )
if ( CMAKE_GENERATOR STREQUAL "Unix Makefiles" )
message ( STATUS "Continue with" )
message ( STATUS " make" )
2019-08-30 15:08:35 -04:00
if ( EXPAT_BUILD_TESTS )
2019-08-11 17:28:39 -04:00
message ( STATUS " make test" )
endif ( )
2019-08-30 15:32:01 -04:00
if ( EXPAT_ENABLE_INSTALL )
2019-08-11 17:28:39 -04:00
message ( STATUS " sudo make install" )
endif ( )
message ( STATUS "" )
endif ( )
message ( STATUS "===========================================================================" )