CMakeLists.txt 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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.3")
  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/loadlibrary.c
  48. lib/xmlparse.c
  49. lib/xmlrole.c
  50. lib/xmltok.c
  51. lib/xmltok_impl.c
  52. lib/xmltok_ns.c
  53. )
  54. if(BUILD_shared)
  55. set(_SHARED SHARED)
  56. if(WIN32)
  57. set(expat_SRCS ${expat_SRCS} lib/libexpat.def)
  58. endif(WIN32)
  59. else(BUILD_shared)
  60. set(_SHARED STATIC)
  61. if(WIN32)
  62. add_definitions(-DXML_STATIC)
  63. endif(WIN32)
  64. endif(BUILD_shared)
  65. add_library(expat ${_SHARED} ${expat_SRCS})
  66. set(LIBCURRENT 7) # sync
  67. set(LIBREVISION 5) # with
  68. set(LIBAGE 6) # configure.ac!
  69. math(EXPR LIBCURRENT_MINUS_AGE "${LIBCURRENT} - ${LIBAGE}")
  70. if(NOT WIN32)
  71. set_property(TARGET expat PROPERTY VERSION ${LIBCURRENT_MINUS_AGE}.${LIBAGE}.${LIBREVISION})
  72. set_property(TARGET expat PROPERTY SOVERSION ${LIBCURRENT_MINUS_AGE})
  73. set_property(TARGET expat PROPERTY NO_SONAME ${NO_SONAME})
  74. endif(NOT WIN32)
  75. macro(expat_install)
  76. if(INSTALL)
  77. install(${ARGN})
  78. endif()
  79. endmacro()
  80. expat_install(TARGETS expat RUNTIME DESTINATION bin
  81. LIBRARY DESTINATION lib
  82. ARCHIVE DESTINATION lib)
  83. set(prefix ${CMAKE_INSTALL_PREFIX})
  84. set(exec_prefix "\${prefix}/bin")
  85. set(libdir "\${prefix}/lib")
  86. set(includedir "\${prefix}/include")
  87. configure_file(expat.pc.in ${CMAKE_CURRENT_BINARY_DIR}/expat.pc)
  88. expat_install(FILES lib/expat.h lib/expat_external.h DESTINATION include)
  89. expat_install(FILES ${CMAKE_CURRENT_BINARY_DIR}/expat.pc DESTINATION lib/pkgconfig)
  90. if(BUILD_tools AND NOT WINCE)
  91. set(xmlwf_SRCS
  92. xmlwf/xmlwf.c
  93. xmlwf/xmlfile.c
  94. xmlwf/codepage.c
  95. xmlwf/readfilemap.c
  96. )
  97. add_executable(xmlwf ${xmlwf_SRCS})
  98. set_property(TARGET xmlwf PROPERTY RUNTIME_OUTPUT_DIRECTORY xmlwf)
  99. target_link_libraries(xmlwf expat)
  100. expat_install(TARGETS xmlwf DESTINATION bin)
  101. if(BUILD_doc AND NOT MSVC)
  102. if(CMAKE_GENERATOR STREQUAL "Unix Makefiles")
  103. set(make_command "$(MAKE)")
  104. else()
  105. set(make_command "make")
  106. endif()
  107. add_custom_command(TARGET expat PRE_BUILD COMMAND "${make_command}" -C "${PROJECT_SOURCE_DIR}/doc" xmlwf.1)
  108. expat_install(FILES "${PROJECT_SOURCE_DIR}/doc/xmlwf.1" DESTINATION share/man/man1)
  109. endif()
  110. endif(BUILD_tools AND NOT WINCE)
  111. if(BUILD_examples)
  112. add_executable(elements examples/elements.c)
  113. set_property(TARGET elements PROPERTY RUNTIME_OUTPUT_DIRECTORY examples)
  114. target_link_libraries(elements expat)
  115. add_executable(outline examples/outline.c)
  116. set_property(TARGET outline PROPERTY RUNTIME_OUTPUT_DIRECTORY examples)
  117. target_link_libraries(outline expat)
  118. endif(BUILD_examples)
  119. if(BUILD_tests)
  120. ## these are unittests that can be run on any platform
  121. add_executable(runtests tests/runtests.c tests/chardata.c tests/minicheck.c tests/memcheck.c)
  122. set_property(TARGET runtests PROPERTY RUNTIME_OUTPUT_DIRECTORY tests)
  123. target_link_libraries(runtests expat)
  124. add_test(runtests tests/runtests)
  125. add_executable(runtestspp tests/runtestspp.cpp tests/chardata.c tests/minicheck.c tests/memcheck.c)
  126. set_property(TARGET runtestspp PROPERTY RUNTIME_OUTPUT_DIRECTORY tests)
  127. target_link_libraries(runtestspp expat)
  128. add_test(runtestspp tests/runtestspp)
  129. endif(BUILD_tests)