StarDict terminal UI
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CMakeLists.txt 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. project (sdtui C)
  2. cmake_minimum_required (VERSION 2.8.5)
  3. # Moar warnings
  4. if ("${CMAKE_C_COMPILER_ID}" MATCHES "GNU" OR CMAKE_COMPILER_IS_GNUCC)
  5. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
  6. set (CMAKE_C_FLAGS_DEBUG
  7. "${CMAKE_C_FLAGS_DEBUG} -Wall -Wextra -Wno-missing-field-initializers")
  8. endif ("${CMAKE_C_COMPILER_ID}" MATCHES "GNU" OR CMAKE_COMPILER_IS_GNUCC)
  9. # Version
  10. set (project_VERSION_MAJOR "0")
  11. set (project_VERSION_MINOR "1")
  12. set (project_VERSION_PATCH "0")
  13. set (project_VERSION "${project_VERSION_MAJOR}")
  14. set (project_VERSION "${project_VERSION}.${project_VERSION_MINOR}")
  15. set (project_VERSION "${project_VERSION}.${project_VERSION_PATCH}")
  16. # For custom modules
  17. set (CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
  18. # Dependencies
  19. find_package (ZLIB REQUIRED)
  20. find_package (Ncursesw REQUIRED)
  21. find_package (PkgConfig REQUIRED)
  22. pkg_check_modules (dependencies REQUIRED glib-2.0 gio-2.0 pango)
  23. pkg_check_modules (icu icu-uc icu-i18n)
  24. if (NOT icu_FOUND)
  25. find_program (icu_CONFIG_EXECUTABLE icu-config)
  26. if (NOT icu_CONFIG_EXECUTABLE)
  27. message (FATAL_ERROR "ICU not found")
  28. endif (NOT icu_CONFIG_EXECUTABLE)
  29. execute_process (COMMAND ${icu_CONFIG_EXECUTABLE} --cppflags
  30. OUTPUT_VARIABLE icu_CPPFLAGS OUTPUT_STRIP_TRAILING_WHITESPACE)
  31. separate_arguments (icu_CPPFLAGS)
  32. # target_link_libraries() handles linker flags as well
  33. execute_process (COMMAND ${icu_CONFIG_EXECUTABLE} --ldflags
  34. OUTPUT_VARIABLE icu_LIBRARIES OUTPUT_STRIP_TRAILING_WHITESPACE)
  35. separate_arguments (icu_LIBRARIES)
  36. # Filter out include directories from the preprocessor flags
  37. set (icu_INCLUDE_DIRS)
  38. foreach (flag ${icu_CPPFLAGS})
  39. if (flag MATCHES "^-I(.*)")
  40. list (APPEND icu_INCLUDE_DIRS "${CMAKE_MATCH_1}")
  41. endif (flag MATCHES "^-I(.*)")
  42. endforeach (flag)
  43. # This should suffice most of the time, don't care about the rest
  44. endif (NOT icu_FOUND)
  45. find_package (Termo QUIET NO_MODULE)
  46. option (USE_SYSTEM_TERMO
  47. "Don't compile our own termo library, use the system one" ${Termo_FOUND})
  48. if (USE_SYSTEM_TERMO)
  49. if (NOT Termo_FOUND)
  50. message (FATAL_ERROR "System termo library not found")
  51. endif (NOT Termo_FOUND)
  52. else (USE_SYSTEM_TERMO)
  53. # We don't want the library to install, even though EXCLUDE_FROM_ALL
  54. # sabotages CTest -- those unbuilt tests need to be excluded in CTest runs
  55. add_subdirectory (termo EXCLUDE_FROM_ALL)
  56. # We don't have many good choices; this is a relatively clean approach
  57. # (other possibilities: setting a variable in the parent scope, using
  58. # a cache variable, writing a special config file with build paths in it
  59. # and including it here, or setting a custom property on the targets)
  60. get_directory_property (Termo_INCLUDE_DIRS
  61. DIRECTORY termo INCLUDE_DIRECTORIES)
  62. set (Termo_LIBRARIES termo-static)
  63. endif (USE_SYSTEM_TERMO)
  64. pkg_check_modules (xcb xcb xcb-xfixes)
  65. option (WITH_X11 "Compile with X11 selection support using XCB" ${xcb_FOUND})
  66. if (WITH_X11)
  67. if (NOT xcb_FOUND)
  68. message (FATAL_ERROR "XCB not found")
  69. endif (NOT xcb_FOUND)
  70. list (APPEND dependencies_INCLUDE_DIRS ${xcb_INCLUDE_DIRS})
  71. list (APPEND dependencies_LIBRARY_DIRS ${xcb_LIBRARY_DIRS})
  72. list (APPEND dependencies_LIBRARIES ${xcb_LIBRARIES})
  73. endif (WITH_X11)
  74. link_directories (${dependencies_LIBRARY_DIRS})
  75. include_directories (${ZLIB_INCLUDE_DIRS} ${icu_INCLUDE_DIRS}
  76. ${dependencies_INCLUDE_DIRS} ${NCURSESW_INCLUDE_DIRS}
  77. ${Termo_INCLUDE_DIRS})
  78. # Configuration
  79. include (CheckFunctionExists)
  80. set (CMAKE_REQUIRED_LIBRARIES ${NCURSESW_LIBRARIES})
  81. CHECK_FUNCTION_EXISTS ("resizeterm" HAVE_RESIZETERM)
  82. # Localization
  83. find_package (Gettext REQUIRED)
  84. file (GLOB project_PO_FILES ${PROJECT_SOURCE_DIR}/po/*.po)
  85. GETTEXT_CREATE_TRANSLATIONS (
  86. ${PROJECT_SOURCE_DIR}/po/${PROJECT_NAME}.pot
  87. ALL ${project_PO_FILES})
  88. # Documentation
  89. find_program (XSLTPROC_EXECUTABLE xsltproc)
  90. if (NOT XSLTPROC_EXECUTABLE)
  91. message (FATAL_ERROR "xsltproc not found")
  92. endif (NOT XSLTPROC_EXECUTABLE)
  93. set (project_MAN_PAGES "${PROJECT_NAME}.1")
  94. foreach (page ${project_MAN_PAGES})
  95. set (page_output "${PROJECT_BINARY_DIR}/${page}")
  96. list (APPEND project_MAN_PAGES_OUTPUT "${page_output}")
  97. add_custom_command (OUTPUT ${page_output}
  98. COMMAND ${XSLTPROC_EXECUTABLE}
  99. --nonet
  100. --param make.year.ranges 1
  101. --param make.single.year.ranges 1
  102. --param man.charmap.use.subset 0
  103. --param man.authors.section.enabled 0
  104. http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl
  105. "${PROJECT_SOURCE_DIR}/docs/${page}.xml"
  106. DEPENDS "docs/${page}.xml"
  107. COMMENT "Generating man page for ${page}" VERBATIM)
  108. endforeach (page)
  109. add_custom_target (docs ALL DEPENDS ${project_MAN_PAGES_OUTPUT})
  110. # Project source files
  111. set (project_common_sources
  112. src/dictzip-input-stream.c
  113. src/generator.c
  114. src/stardict.c
  115. src/utils.c)
  116. set (project_common_headers
  117. ${PROJECT_BINARY_DIR}/config.h
  118. src/dictzip-input-stream.h
  119. src/stardict.h
  120. src/stardict-private.h
  121. src/generator.h
  122. src/utils.h)
  123. # Project libraries
  124. set (project_common_libraries ${ZLIB_LIBRARIES} ${icu_LIBRARIES}
  125. ${dependencies_LIBRARIES} ${NCURSESW_LIBRARIES} termo-static)
  126. # Create a common project library so that source files are only compiled once
  127. if (${CMAKE_VERSION} VERSION_GREATER "2.8.7")
  128. add_library (stardict OBJECT
  129. ${project_common_sources}
  130. ${project_common_headers})
  131. set (project_common_sources $<TARGET_OBJECTS:stardict>)
  132. else (${CMAKE_VERSION} VERSION_GREATER "2.8.7")
  133. add_library (stardict STATIC
  134. ${project_common_sources}
  135. ${project_common_headers})
  136. target_link_libraries (stardict ${project_common_libraries})
  137. list (APPEND project_common_libraries stardict)
  138. set (project_common_sources)
  139. endif (${CMAKE_VERSION} VERSION_GREATER "2.8.7")
  140. # Generate a configuration file
  141. configure_file (${PROJECT_SOURCE_DIR}/config.h.in
  142. ${PROJECT_BINARY_DIR}/config.h)
  143. include_directories (${PROJECT_SOURCE_DIR} ${PROJECT_BINARY_DIR})
  144. # Primary target source files
  145. set (project_sources
  146. src/${PROJECT_NAME}.c)
  147. set (project_headers
  148. ${project_common_headers})
  149. # Build the main executable and link it
  150. add_executable (${PROJECT_NAME}
  151. ${project_sources} ${project_headers} ${project_common_sources})
  152. target_link_libraries (${PROJECT_NAME} ${project_common_libraries})
  153. # Tools
  154. add_executable (query-tool EXCLUDE_FROM_ALL
  155. src/query-tool.c ${project_common_sources})
  156. target_link_libraries (query-tool ${project_common_libraries})
  157. add_executable (add-pronunciation EXCLUDE_FROM_ALL
  158. src/add-pronunciation.c ${project_common_sources})
  159. target_link_libraries (add-pronunciation ${project_common_libraries})
  160. add_custom_target (tools DEPENDS add-pronunciation query-tool)
  161. # The files to be installed
  162. include (GNUInstallDirs)
  163. install (TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR})
  164. install (FILES LICENSE DESTINATION ${CMAKE_INSTALL_DOCDIR})
  165. foreach (page ${project_MAN_PAGES_OUTPUT})
  166. string (REGEX MATCH "\\.([0-9])$" manpage_suffix "${page}")
  167. install (FILES "${page}"
  168. DESTINATION "${CMAKE_INSTALL_MANDIR}/man${CMAKE_MATCH_1}")
  169. endforeach (page)
  170. # Do some unit tests
  171. option (BUILD_TESTING "Build tests" OFF)
  172. set (project_tests stardict)
  173. if (BUILD_TESTING)
  174. enable_testing ()
  175. foreach (name ${project_tests})
  176. add_executable (test-${name}
  177. src/test-${name}.c ${project_common_sources})
  178. target_link_libraries (test-${name} ${project_common_libraries})
  179. add_test (test-${name} test-${name})
  180. endforeach (name)
  181. endif (BUILD_TESTING)
  182. # CPack
  183. set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "StarDict terminal UI")
  184. set (CPACK_PACKAGE_VENDOR "Premysl Janouch")
  185. set (CPACK_PACKAGE_CONTACT "Přemysl Janouch <p@janouch.name>")
  186. set (CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
  187. set (CPACK_PACKAGE_VERSION_MAJOR ${project_VERSION_MAJOR})
  188. set (CPACK_PACKAGE_VERSION_MINOR ${project_VERSION_MINOR})
  189. set (CPACK_PACKAGE_VERSION_PATCH ${project_VERSION_PATCH})
  190. set (CPACK_GENERATOR "TGZ;ZIP")
  191. set (CPACK_PACKAGE_FILE_NAME
  192. "${PROJECT_NAME}-${project_VERSION}-${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}")
  193. set (CPACK_PACKAGE_INSTALL_DIRECTORY "${PROJECT_NAME}-${project_VERSION}")
  194. set (CPACK_SOURCE_GENERATOR "TGZ;ZIP")
  195. set (CPACK_SOURCE_IGNORE_FILES "/\\\\.git;/build;/CMakeLists.txt.user")
  196. set (CPACK_SOURCE_PACKAGE_FILE_NAME "${PROJECT_NAME}-${project_VERSION}")
  197. include (CPack)