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