• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# This file is copyrighted under the BSD-license for buildsystem files of KDE
2# copyright 2010, Patrick Spendrin <ps_ml@gmx.de>
3
4project(expat)
5
6cmake_minimum_required(VERSION 2.6)
7set(PACKAGE_BUGREPORT "expat-bugs@libexpat.org")
8set(PACKAGE_NAME "expat")
9set(PACKAGE_VERSION "2.2.5")
10set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
11set(PACKAGE_TARNAME "${PACKAGE_NAME}")
12
13if(WINCE)
14    set(BUILD_tools_default OFF)
15else()
16    set(BUILD_tools_default ON)
17endif()
18if(MSVC OR NOT BUILD_tools_default)
19    set(BUILD_doc_default OFF)
20else()
21    find_program(DOCBOOK_TO_MAN NAMES docbook2x-man docbook2man docbook-to-man)
22    if(DOCBOOK_TO_MAN)
23        set(BUILD_doc_default ON)
24    else()
25        set(BUILD_doc_default OFF)
26    endif()
27endif()
28
29option(BUILD_tools "build the xmlwf tool for expat library" ${BUILD_tools_default})
30option(BUILD_examples "build the examples for expat library" ON)
31option(BUILD_tests "build the tests for expat library" ON)
32option(BUILD_shared "build a shared expat library" ON)
33option(BUILD_doc "build man page for xmlwf" ${BUILD_doc_default})
34option(USE_libbsd "utilize libbsd (for arc4random_buf)" OFF)
35option(INSTALL "install expat files in cmake install target" ON)
36
37if(USE_libbsd)
38    find_library(LIB_BSD NAMES bsd)
39    if(NOT LIB_BSD)
40        message(FATAL_ERROR "USE_libbsd option is enabled, but libbsd was not found")
41    else()
42        set(HAVE_LIBBSD TRUE)
43    endif()
44endif()
45
46# configuration options
47set(XML_CONTEXT_BYTES 1024 CACHE STRING "Define to specify how much context to retain around the current parse point")
48option(XML_DTD "Define to make parameter entity parsing functionality available" ON)
49option(XML_NS "Define to make XML Namespaces functionality available" ON)
50if(NOT WIN32)
51    option(XML_DEV_URANDOM "Define to include code reading entropy from `/dev/urandom'." ON)
52    if(XML_DEV_URANDOM)
53        add_definitions(-DXML_DEV_URANDOM)
54    endif()
55endif()
56
57if(XML_DTD)
58    set(XML_DTD 1)
59else(XML_DTD)
60    set(XML_DTD 0)
61endif(XML_DTD)
62if(XML_NS)
63    set(XML_NS 1)
64else(XML_NS)
65    set(XML_NS 0)
66endif(XML_NS)
67
68if(BUILD_tests)
69    enable_testing()
70endif(BUILD_tests)
71
72include(${CMAKE_CURRENT_LIST_DIR}/ConfigureChecks.cmake)
73
74set(EXTRA_COMPILE_FLAGS)
75if(FLAG_NO_STRICT_ALIASING)
76    set(EXTRA_COMPILE_FLAGS "${EXTRA_COMPILE_FLAGS} -fno-strict-aliasing")
77endif()
78set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_COMPILE_FLAGS}")
79set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_COMPILE_FLAGS}")
80
81include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/lib)
82if(MSVC)
83    add_definitions(-D_CRT_SECURE_NO_WARNINGS -wd4996)
84endif(MSVC)
85if(WIN32)
86    set(CMAKE_DEBUG_POSTFIX "d" CACHE STRING "Add a suffix, usually d on Windows")
87endif(WIN32)
88
89set(expat_SRCS
90    lib/loadlibrary.c
91    lib/xmlparse.c
92    lib/xmlrole.c
93    lib/xmltok.c
94    lib/xmltok_impl.c
95    lib/xmltok_ns.c
96)
97
98if(BUILD_shared)
99    set(_SHARED SHARED)
100    if(WIN32)
101        set(expat_SRCS ${expat_SRCS} lib/libexpat.def)
102    endif(WIN32)
103else(BUILD_shared)
104    set(_SHARED STATIC)
105    if(WIN32)
106        add_definitions(-DXML_STATIC)
107    endif(WIN32)
108endif(BUILD_shared)
109
110add_library(expat ${_SHARED} ${expat_SRCS})
111if(USE_libbsd)
112    target_link_libraries(expat ${LIB_BSD})
113endif()
114
115set(LIBCURRENT 7)   # sync
116set(LIBREVISION 7)  # with
117set(LIBAGE 6)       # configure.ac!
118math(EXPR LIBCURRENT_MINUS_AGE "${LIBCURRENT} - ${LIBAGE}")
119
120if(NOT WIN32)
121    set_property(TARGET expat PROPERTY VERSION ${LIBCURRENT_MINUS_AGE}.${LIBAGE}.${LIBREVISION})
122    set_property(TARGET expat PROPERTY SOVERSION ${LIBCURRENT_MINUS_AGE})
123    set_property(TARGET expat PROPERTY NO_SONAME ${NO_SONAME})
124endif(NOT WIN32)
125
126macro(expat_install)
127    if(INSTALL)
128        install(${ARGN})
129    endif()
130endmacro()
131
132expat_install(TARGETS expat RUNTIME DESTINATION bin
133                      LIBRARY DESTINATION lib
134                      ARCHIVE DESTINATION lib)
135
136set(prefix ${CMAKE_INSTALL_PREFIX})
137set(exec_prefix "\${prefix}/bin")
138set(libdir "\${prefix}/lib")
139set(includedir "\${prefix}/include")
140configure_file(expat.pc.in ${CMAKE_CURRENT_BINARY_DIR}/expat.pc)
141
142expat_install(FILES lib/expat.h lib/expat_external.h DESTINATION include)
143expat_install(FILES ${CMAKE_CURRENT_BINARY_DIR}/expat.pc DESTINATION lib/pkgconfig)
144
145if(BUILD_tools)
146    set(xmlwf_SRCS
147        xmlwf/xmlwf.c
148        xmlwf/xmlfile.c
149        xmlwf/codepage.c
150        xmlwf/readfilemap.c
151    )
152
153    add_executable(xmlwf ${xmlwf_SRCS})
154    set_property(TARGET xmlwf PROPERTY RUNTIME_OUTPUT_DIRECTORY xmlwf)
155    target_link_libraries(xmlwf expat)
156    expat_install(TARGETS xmlwf DESTINATION bin)
157    if(BUILD_doc)
158        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")
159        expat_install(FILES "${PROJECT_SOURCE_DIR}/doc/xmlwf.1" DESTINATION share/man/man1)
160    endif()
161endif()
162
163if(BUILD_examples)
164    add_executable(elements examples/elements.c)
165    set_property(TARGET elements PROPERTY RUNTIME_OUTPUT_DIRECTORY examples)
166    target_link_libraries(elements expat)
167
168    add_executable(outline examples/outline.c)
169    set_property(TARGET outline PROPERTY RUNTIME_OUTPUT_DIRECTORY examples)
170    target_link_libraries(outline expat)
171endif(BUILD_examples)
172
173if(BUILD_tests)
174    ## these are unittests that can be run on any platform
175    add_executable(runtests tests/runtests.c tests/chardata.c tests/structdata.c tests/minicheck.c tests/memcheck.c)
176    set_property(TARGET runtests PROPERTY RUNTIME_OUTPUT_DIRECTORY tests)
177    target_link_libraries(runtests expat)
178    add_test(runtests tests/runtests)
179
180    add_executable(runtestspp tests/runtestspp.cpp tests/chardata.c tests/structdata.c tests/minicheck.c tests/memcheck.c)
181    set_property(TARGET runtestspp PROPERTY RUNTIME_OUTPUT_DIRECTORY tests)
182    target_link_libraries(runtestspp expat)
183    add_test(runtestspp tests/runtestspp)
184endif(BUILD_tests)
185