2012-03-05 09:38:22 -05:00
# This file is copyrighted under the BSD-license for buildsystem files of KDE
# copyright 2010, Patrick Spendrin <ps_ml@gmx.de>
project ( expat )
2017-12-14 03:57:54 -05:00
cmake_minimum_required ( VERSION 2.8.10 )
2012-03-05 09:38:22 -05:00
set ( PACKAGE_BUGREPORT "expat-bugs@libexpat.org" )
set ( PACKAGE_NAME "expat" )
2018-08-12 15:04:35 -04:00
set ( PACKAGE_VERSION "2.2.6" )
2012-03-05 09:38:22 -05:00
set ( PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}" )
set ( PACKAGE_TARNAME "${PACKAGE_NAME}" )
2017-12-14 03:57:54 -05:00
include ( GNUInstallDirs )
2017-08-07 04:39:28 -04:00
if ( WINCE )
set ( BUILD_tools_default OFF )
else ( )
set ( BUILD_tools_default ON )
endif ( )
if ( MSVC OR NOT BUILD_tools_default )
set ( BUILD_doc_default OFF )
else ( )
2018-02-28 09:07:21 -05:00
find_program ( DOCBOOK_TO_MAN NAMES docbook2x-man db2x_docbook2man docbook2man docbook-to-man )
2017-08-07 04:39:28 -04:00
if ( DOCBOOK_TO_MAN )
set ( BUILD_doc_default ON )
else ( )
set ( BUILD_doc_default OFF )
endif ( )
endif ( )
option ( BUILD_tools "build the xmlwf tool for expat library" ${ BUILD_tools_default } )
2012-03-05 09:38:22 -05:00
option ( BUILD_examples "build the examples for expat library" ON )
option ( BUILD_tests "build the tests for expat library" ON )
option ( BUILD_shared "build a shared expat library" ON )
2017-08-07 04:39:28 -04:00
option ( BUILD_doc "build man page for xmlwf" ${ BUILD_doc_default } )
2017-08-02 08:09:19 -04:00
option ( USE_libbsd "utilize libbsd (for arc4random_buf)" OFF )
2016-11-20 12:09:13 -05:00
option ( INSTALL "install expat files in cmake install target" ON )
2012-03-05 09:38:22 -05:00
2017-08-07 04:29:42 -04:00
if ( USE_libbsd )
find_library ( LIB_BSD NAMES bsd )
if ( NOT LIB_BSD )
message ( FATAL_ERROR "USE_libbsd option is enabled, but libbsd was not found" )
else ( )
set ( HAVE_LIBBSD TRUE )
endif ( )
endif ( )
2012-03-05 09:38:22 -05:00
# configuration options
set ( XML_CONTEXT_BYTES 1024 CACHE STRING "Define to specify how much context to retain around the current parse point" )
option ( XML_DTD "Define to make parameter entity parsing functionality available" ON )
option ( XML_NS "Define to make XML Namespaces functionality available" ON )
2017-12-04 17:31:10 -05:00
option ( WARNINGS_AS_ERRORS "Treat all compiler warnings as errors" OFF )
2017-08-05 08:59:53 -04:00
if ( NOT WIN32 )
option ( XML_DEV_URANDOM "Define to include code reading entropy from `/dev/urandom'." ON )
if ( XML_DEV_URANDOM )
2018-08-09 03:20:51 -04:00
set ( XML_DEV_URANDOM 1 )
else ( XML_DEV_URANDOM )
set ( XML_DEV_URANDOM 0 )
endif ( XML_DEV_URANDOM )
2017-08-05 08:59:53 -04:00
endif ( )
2018-08-09 03:33:48 -04:00
option ( XML_UNICODE "Use UTF-16 encoded chars (two bytes) instead of UTF-8" OFF )
option ( XML_UNICODE_WCHAR_T "Use wchar_t to represent UTF-16 instead of unsigned short" OFF )
2012-03-05 09:38:22 -05:00
if ( XML_DTD )
set ( XML_DTD 1 )
else ( XML_DTD )
set ( XML_DTD 0 )
endif ( XML_DTD )
if ( XML_NS )
set ( XML_NS 1 )
else ( XML_NS )
set ( XML_NS 0 )
endif ( XML_NS )
2018-08-09 03:33:48 -04:00
if ( XML_UNICODE )
set ( XML_UNICODE 1 )
else ( XML_UNICODE )
set ( XML_UNICODE 0 )
endif ( XML_UNICODE )
if ( XML_UNICODE_WCHAR_T )
set ( XML_UNICODE_WCHAR_T 1 )
else ( XML_UNICODE_WCHAR_T )
set ( XML_UNICODE_WCHAR_T 0 )
endif ( XML_UNICODE_WCHAR_T )
2018-08-10 02:41:16 -04:00
if ( XML_UNICODE_WCHAR_T AND NOT XML_UNICODE )
message ( SEND_ERROR "Option XML_UNICODE_WCHAR_T=ON may not be used without XML_UNICODE=ON." )
set ( XML_UNICODE 1 )
endif ( XML_UNICODE_WCHAR_T AND NOT XML_UNICODE )
if ( BUILD_tools AND ( XML_UNICODE AND NOT XML_UNICODE_WCHAR_T ) )
message ( SEND_ERROR "The xmlwf tool can not be built with option XML_UNICODE_WCHAR_T=OFF and XML_UNICODE=ON. Either set XML_UNICODE_WCHAR_T=ON or BUILD_tools=OFF." )
endif ( )
2012-03-05 09:38:22 -05:00
if ( BUILD_tests )
enable_testing ( )
endif ( BUILD_tests )
2016-10-26 13:55:47 -04:00
include ( ${ CMAKE_CURRENT_LIST_DIR } /ConfigureChecks.cmake )
2012-03-05 09:38:22 -05:00
2017-08-07 04:30:21 -04:00
set ( EXTRA_COMPILE_FLAGS )
2017-08-02 07:13:53 -04:00
if ( FLAG_NO_STRICT_ALIASING )
2017-08-07 04:30:21 -04:00
set ( EXTRA_COMPILE_FLAGS "${EXTRA_COMPILE_FLAGS} -fno-strict-aliasing" )
2017-08-02 07:13:53 -04:00
endif ( )
2017-12-04 17:31:10 -05:00
if ( WARNINGS_AS_ERRORS )
if ( MSVC )
add_definitions ( /WX )
else ( MSVC )
set ( EXTRA_COMPILE_FLAGS "${EXTRA_COMPILE_FLAGS} -Werror" )
endif ( MSVC )
endif ( WARNINGS_AS_ERRORS )
2017-08-07 04:30:21 -04:00
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_COMPILE_FLAGS}" )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_COMPILE_FLAGS}" )
2016-08-12 09:45:05 -04:00
2018-01-07 18:51:48 -05:00
set ( MSVC_USE_STATIC_CRT OFF CACHE BOOL "Use /MT flag (static CRT) when compiling in MSVC" )
2018-01-07 17:49:47 -05:00
if ( MSVC )
if ( MSVC_USE_STATIC_CRT )
message ( "-- Using static CRT ${MSVC_USE_STATIC_CRT}" )
2018-01-07 18:51:48 -05: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
)
2018-01-07 17:49:47 -05:00
string ( REPLACE "/MD" "/MT" ${ flag_var } "${${flag_var}}" )
endforeach ( )
endif ( )
endif ( )
2016-11-02 08:11:07 -04:00
include_directories ( ${ CMAKE_CURRENT_BINARY_DIR } ${ CMAKE_CURRENT_SOURCE_DIR } /lib )
2012-03-05 09:38:22 -05:00
if ( MSVC )
add_definitions ( -D_CRT_SECURE_NO_WARNINGS -wd4996 )
endif ( MSVC )
2016-03-28 12:08:58 -04:00
if ( WIN32 )
2016-05-14 12:56:36 -04:00
set ( CMAKE_DEBUG_POSTFIX "d" CACHE STRING "Add a suffix, usually d on Windows" )
2016-03-28 12:08:58 -04:00
endif ( WIN32 )
2012-03-05 09:38:22 -05:00
set ( expat_SRCS
2017-07-26 08:47:37 -04:00
l i b / l o a d l i b r a r y . c
2012-03-05 09:38:22 -05:00
l i b / x m l p a r s e . c
l i b / x m l r o l e . c
2016-11-20 12:10:01 -05:00
l i b / x m l t o k . c
l i b / x m l t o k _ i m p l . c
2012-03-05 09:38:22 -05:00
l i b / x m l t o k _ n s . c
)
if ( BUILD_shared )
set ( _SHARED SHARED )
2016-03-12 11:09:47 -05:00
if ( WIN32 )
set ( expat_SRCS ${ expat_SRCS } lib/libexpat.def )
endif ( WIN32 )
2012-03-05 09:38:22 -05:00
else ( BUILD_shared )
set ( _SHARED STATIC )
2016-03-12 11:12:25 -05:00
if ( WIN32 )
add_definitions ( -DXML_STATIC )
endif ( WIN32 )
2012-03-05 09:38:22 -05:00
endif ( BUILD_shared )
add_library ( expat ${ _SHARED } ${ expat_SRCS } )
2017-08-02 08:09:19 -04:00
if ( USE_libbsd )
2017-08-07 04:29:42 -04:00
target_link_libraries ( expat ${ LIB_BSD } )
2017-08-02 08:09:19 -04:00
endif ( )
2016-06-05 09:41:12 -04:00
set ( LIBCURRENT 7 ) # sync
2018-08-12 14:56:32 -04:00
set ( LIBREVISION 8 ) # with
2016-06-05 09:41:12 -04:00
set ( LIBAGE 6 ) # configure.ac!
math ( EXPR LIBCURRENT_MINUS_AGE "${LIBCURRENT} - ${LIBAGE}" )
2016-06-20 12:47:11 -04:00
if ( NOT WIN32 )
set_property ( TARGET expat PROPERTY VERSION ${ LIBCURRENT_MINUS_AGE } . ${ LIBAGE } . ${ LIBREVISION } )
set_property ( TARGET expat PROPERTY SOVERSION ${ LIBCURRENT_MINUS_AGE } )
set_property ( TARGET expat PROPERTY NO_SONAME ${ NO_SONAME } )
endif ( NOT WIN32 )
2012-03-05 09:38:22 -05:00
2016-10-26 15:48:34 -04:00
macro ( expat_install )
2016-11-20 12:09:13 -05:00
if ( INSTALL )
2016-10-26 15:48:34 -04:00
install ( ${ ARGN } )
endif ( )
endmacro ( )
2017-12-14 03:57:54 -05:00
expat_install ( TARGETS expat RUNTIME DESTINATION ${ CMAKE_INSTALL_BINDIR }
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 } )
2012-03-05 09:38:22 -05:00
set ( prefix ${ CMAKE_INSTALL_PREFIX } )
2017-12-13 06:44:00 -05:00
set ( exec_prefix "\${prefix}" )
set ( libdir "\${exec_prefix}/lib" )
2012-03-05 09:38:22 -05:00
set ( includedir "\${prefix}/include" )
2017-12-13 06:44:00 -05:00
configure_file ( expat.pc.in ${ CMAKE_CURRENT_BINARY_DIR } /expat.pc @ONLY )
2012-03-05 09:38:22 -05:00
2017-12-14 03:57:54 -05:00
expat_install ( FILES lib/expat.h lib/expat_external.h DESTINATION ${ CMAKE_INSTALL_INCLUDEDIR } )
expat_install ( FILES ${ CMAKE_CURRENT_BINARY_DIR } /expat.pc DESTINATION ${ CMAKE_INSTALL_LIBDIR } /pkgconfig )
2012-03-05 09:38:22 -05:00
2017-08-07 04:39:28 -04:00
if ( BUILD_tools )
2012-03-05 09:38:22 -05: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 } )
2016-03-02 10:36:32 -05:00
set_property ( TARGET xmlwf PROPERTY RUNTIME_OUTPUT_DIRECTORY xmlwf )
2012-03-05 09:38:22 -05:00
target_link_libraries ( xmlwf expat )
2017-12-14 03:57:54 -05:00
expat_install ( TARGETS xmlwf DESTINATION ${ CMAKE_INSTALL_BINDIR } )
2017-08-07 04:39:28 -04:00
if ( BUILD_doc )
2017-10-04 11:11:01 -04:00
add_custom_command ( TARGET expat PRE_BUILD COMMAND "${DOCBOOK_TO_MAN}" "${PROJECT_SOURCE_DIR}/doc/xmlwf.xml" && mv "XMLWF.1" "${PROJECT_SOURCE_DIR}/doc/xmlwf.1" )
2017-12-14 03:57:54 -05:00
expat_install ( FILES "${PROJECT_SOURCE_DIR}/doc/xmlwf.1" DESTINATION ${ CMAKE_INSTALL_MANDIR } /man1 )
2016-08-15 12:07:34 -04:00
endif ( )
2017-08-07 04:39:28 -04:00
endif ( )
2012-03-05 09:38:22 -05:00
if ( BUILD_examples )
add_executable ( elements examples/elements.c )
2016-03-02 10:36:32 -05:00
set_property ( TARGET elements PROPERTY RUNTIME_OUTPUT_DIRECTORY examples )
2012-03-05 09:38:22 -05:00
target_link_libraries ( elements expat )
add_executable ( outline examples/outline.c )
2016-03-02 10:36:32 -05:00
set_property ( TARGET outline PROPERTY RUNTIME_OUTPUT_DIRECTORY examples )
2012-03-05 09:38:22 -05:00
target_link_libraries ( outline expat )
endif ( BUILD_examples )
if ( BUILD_tests )
## these are unittests that can be run on any platform
2017-08-29 16:59:36 -04:00
add_executable ( runtests tests/runtests.c tests/chardata.c tests/structdata.c tests/minicheck.c tests/memcheck.c )
2016-03-02 10:36:32 -05:00
set_property ( TARGET runtests PROPERTY RUNTIME_OUTPUT_DIRECTORY tests )
2012-03-05 09:38:22 -05:00
target_link_libraries ( runtests expat )
2016-03-02 10:36:32 -05:00
add_test ( runtests tests/runtests )
2012-03-05 09:38:22 -05:00
2017-08-29 16:59:36 -04:00
add_executable ( runtestspp tests/runtestspp.cpp tests/chardata.c tests/structdata.c tests/minicheck.c tests/memcheck.c )
2016-03-02 10:36:32 -05:00
set_property ( TARGET runtestspp PROPERTY RUNTIME_OUTPUT_DIRECTORY tests )
2012-03-05 09:38:22 -05:00
target_link_libraries ( runtestspp expat )
2016-03-02 10:36:32 -05:00
add_test ( runtestspp tests/runtestspp )
2012-03-05 09:38:22 -05:00
endif ( BUILD_tests )