CMakeLists.txt 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. # This file is copyrighted under the BSD-license for buildsystem files of KDE
  2. # copyright 2010, Patrick Spendrin <[email protected]>
  3. project(expat)
  4. cmake_minimum_required(VERSION 2.6)
  5. set(PACKAGE_BUGREPORT "[email protected]")
  6. set(PACKAGE_NAME "expat")
  7. set(PACKAGE_VERSION "2.2.2")
  8. set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
  9. set(PACKAGE_TARNAME "${PACKAGE_NAME}")
  10. option(BUILD_tools "build the xmlwf tool for expat library" ON)
  11. option(BUILD_examples "build the examples for expat library" ON)
  12. option(BUILD_tests "build the tests for expat library" ON)
  13. option(BUILD_shared "build a shared expat library" ON)
  14. option(BUILD_doc "build man page for xmlwf" ON)
  15. option(INSTALL "install expat files in cmake install target" ON)
  16. # configuration options
  17. set(XML_CONTEXT_BYTES 1024 CACHE STRING "Define to specify how much context to retain around the current parse point")
  18. option(XML_DTD "Define to make parameter entity parsing functionality available" ON)
  19. option(XML_NS "Define to make XML Namespaces functionality available" ON)
  20. if(XML_DTD)
  21. set(XML_DTD 1)
  22. else(XML_DTD)
  23. set(XML_DTD 0)
  24. endif(XML_DTD)
  25. if(XML_NS)
  26. set(XML_NS 1)
  27. else(XML_NS)
  28. set(XML_NS 0)
  29. endif(XML_NS)
  30. if(BUILD_tests)
  31. enable_testing()
  32. endif(BUILD_tests)
  33. include(${CMAKE_CURRENT_LIST_DIR}/ConfigureChecks.cmake)
  34. set(EXTRA_LINK_AND_COMPILE_FLAGS "-fno-strict-aliasing")
  35. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_LINK_AND_COMPILE_FLAGS}")
  36. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_LINK_AND_COMPILE_FLAGS}")
  37. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${EXTRA_LINK_AND_COMPILE_FLAGS}")
  38. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${EXTRA_LINK_AND_COMPILE_FLAGS}")
  39. include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/lib)
  40. if(MSVC)
  41. add_definitions(-D_CRT_SECURE_NO_WARNINGS -wd4996)
  42. endif(MSVC)
  43. if(WIN32)
  44. set(CMAKE_DEBUG_POSTFIX "d" CACHE STRING "Add a suffix, usually d on Windows")
  45. endif(WIN32)
  46. set(expat_SRCS
  47. lib/xmlparse.c
  48. lib/xmlrole.c
  49. lib/xmltok.c
  50. lib/xmltok_impl.c
  51. lib/xmltok_ns.c
  52. )
  53. if(BUILD_shared)
  54. set(_SHARED SHARED)
  55. if(WIN32)
  56. set(expat_SRCS ${expat_SRCS} lib/libexpat.def)
  57. endif(WIN32)
  58. else(BUILD_shared)
  59. set(_SHARED STATIC)
  60. if(WIN32)
  61. add_definitions(-DXML_STATIC)
  62. endif(WIN32)
  63. endif(BUILD_shared)
  64. add_library(expat ${_SHARED} ${expat_SRCS})
  65. set(LIBCURRENT 7) # sync
  66. set(LIBREVISION 4) # with
  67. set(LIBAGE 6) # configure.ac!
  68. math(EXPR LIBCURRENT_MINUS_AGE "${LIBCURRENT} - ${LIBAGE}")
  69. if(NOT WIN32)
  70. set_property(TARGET expat PROPERTY VERSION ${LIBCURRENT_MINUS_AGE}.${LIBAGE}.${LIBREVISION})
  71. set_property(TARGET expat PROPERTY SOVERSION ${LIBCURRENT_MINUS_AGE})
  72. set_property(TARGET expat PROPERTY NO_SONAME ${NO_SONAME})
  73. endif(NOT WIN32)
  74. macro(expat_install)
  75. if(INSTALL)
  76. install(${ARGN})
  77. endif()
  78. endmacro()
  79. expat_install(TARGETS expat RUNTIME DESTINATION bin
  80. LIBRARY DESTINATION lib
  81. ARCHIVE DESTINATION lib)
  82. set(prefix ${CMAKE_INSTALL_PREFIX})
  83. set(exec_prefix "\${prefix}/bin")
  84. set(libdir "\${prefix}/lib")
  85. set(includedir "\${prefix}/include")
  86. configure_file(expat.pc.in ${CMAKE_CURRENT_BINARY_DIR}/expat.pc)
  87. expat_install(FILES lib/expat.h lib/expat_external.h DESTINATION include)
  88. expat_install(FILES ${CMAKE_CURRENT_BINARY_DIR}/expat.pc DESTINATION lib/pkgconfig)
  89. if(BUILD_tools AND NOT WINCE)
  90. set(xmlwf_SRCS
  91. xmlwf/xmlwf.c
  92. xmlwf/xmlfile.c
  93. xmlwf/codepage.c
  94. xmlwf/readfilemap.c
  95. )
  96. add_executable(xmlwf ${xmlwf_SRCS})
  97. set_property(TARGET xmlwf PROPERTY RUNTIME_OUTPUT_DIRECTORY xmlwf)
  98. target_link_libraries(xmlwf expat)
  99. expat_install(TARGETS xmlwf DESTINATION bin)
  100. if(BUILD_doc AND NOT MSVC)
  101. if(CMAKE_GENERATOR STREQUAL "Unix Makefiles")
  102. set(make_command "$(MAKE)")
  103. else()
  104. set(make_command "make")
  105. endif()
  106. add_custom_command(TARGET expat PRE_BUILD COMMAND "${make_command}" -C "${PROJECT_SOURCE_DIR}/doc" xmlwf.1)
  107. expat_install(FILES "${PROJECT_SOURCE_DIR}/doc/xmlwf.1" DESTINATION share/man/man1)
  108. endif()
  109. endif(BUILD_tools AND NOT WINCE)
  110. if(BUILD_examples)
  111. add_executable(elements examples/elements.c)
  112. set_property(TARGET elements PROPERTY RUNTIME_OUTPUT_DIRECTORY examples)
  113. target_link_libraries(elements expat)
  114. add_executable(outline examples/outline.c)
  115. set_property(TARGET outline PROPERTY RUNTIME_OUTPUT_DIRECTORY examples)
  116. target_link_libraries(outline expat)
  117. endif(BUILD_examples)
  118. if(BUILD_tests)
  119. ## these are unittests that can be run on any platform
  120. add_executable(runtests tests/runtests.c tests/chardata.c tests/minicheck.c tests/memcheck.c)
  121. set_property(TARGET runtests PROPERTY RUNTIME_OUTPUT_DIRECTORY tests)
  122. target_link_libraries(runtests expat)
  123. add_test(runtests tests/runtests)
  124. add_executable(runtestspp tests/runtestspp.cpp tests/chardata.c tests/minicheck.c tests/memcheck.c)
  125. set_property(TARGET runtestspp PROPERTY RUNTIME_OUTPUT_DIRECTORY tests)
  126. target_link_libraries(runtestspp expat)
  127. add_test(runtestspp tests/runtestspp)
  128. endif(BUILD_tests)