Hex viewer
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 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. project (hex C)
  2. cmake_minimum_required (VERSION 2.8.5)
  3. # Moar warnings
  4. if ("${CMAKE_C_COMPILER_ID}" MATCHES "GNU" OR CMAKE_COMPILER_IS_GNUC)
  5. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
  6. set (CMAKE_C_FLAGS_DEBUG
  7. "${CMAKE_C_FLAGS_DEBUG} -Wall -Wextra -Wno-unused-function")
  8. endif ("${CMAKE_C_COMPILER_ID}" MATCHES "GNU" OR CMAKE_COMPILER_IS_GNUC)
  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 (Ncursesw REQUIRED)
  20. find_package (PkgConfig REQUIRED)
  21. find_package (Unistring REQUIRED)
  22. set (CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/liberty/cmake)
  23. include (AddThreads)
  24. find_package (Termo QUIET NO_MODULE)
  25. option (USE_SYSTEM_TERMO
  26. "Don't compile our own termo library, use the system one" ${Termo_FOUND})
  27. if (USE_SYSTEM_TERMO)
  28. if (NOT Termo_FOUND)
  29. message (FATAL_ERROR "System termo library not found")
  30. endif (NOT Termo_FOUND)
  31. else (USE_SYSTEM_TERMO)
  32. add_subdirectory (termo EXCLUDE_FROM_ALL)
  33. # We don't have many good choices when we don't want to install it and want
  34. # to support older versions of CMake; this is a relatively clean approach
  35. # (other possibilities: setting a variable in the parent scope, using a
  36. # cache variable, writing a special config file with build paths in it and
  37. # including it here, or setting a custom property on the targets).
  38. get_directory_property (Termo_INCLUDE_DIRS
  39. DIRECTORY termo INCLUDE_DIRECTORIES)
  40. set (Termo_LIBRARIES termo-static)
  41. endif (USE_SYSTEM_TERMO)
  42. include_directories (${UNISTRING_INCLUDE_DIRS}
  43. ${NCURSESW_INCLUDE_DIRS} ${Termo_INCLUDE_DIRS})
  44. # Configuration
  45. include (CheckFunctionExists)
  46. set (CMAKE_REQUIRED_LIBRARIES ${NCURSESW_LIBRARIES})
  47. CHECK_FUNCTION_EXISTS ("resizeterm" HAVE_RESIZETERM)
  48. # Generate a configuration file
  49. configure_file (${PROJECT_SOURCE_DIR}/config.h.in
  50. ${PROJECT_BINARY_DIR}/config.h)
  51. include_directories (${PROJECT_SOURCE_DIR} ${PROJECT_BINARY_DIR})
  52. # Build the main executable and link it
  53. add_executable (${PROJECT_NAME} ${PROJECT_NAME}.c)
  54. target_link_libraries (${PROJECT_NAME} ${UNISTRING_LIBRARIES}
  55. ${NCURSESW_LIBRARIES} termo-static)
  56. add_threads (${PROJECT_NAME})
  57. # Installation
  58. include (GNUInstallDirs)
  59. install (TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR})
  60. install (FILES LICENSE DESTINATION ${CMAKE_INSTALL_DOCDIR})
  61. # Generate documentation from program help
  62. find_program (HELP2MAN_EXECUTABLE help2man)
  63. if (NOT HELP2MAN_EXECUTABLE)
  64. message (FATAL_ERROR "help2man not found")
  65. endif (NOT HELP2MAN_EXECUTABLE)
  66. foreach (page ${PROJECT_NAME})
  67. set (page_output "${PROJECT_BINARY_DIR}/${page}.1")
  68. list (APPEND project_MAN_PAGES "${page_output}")
  69. add_custom_command (OUTPUT ${page_output}
  70. COMMAND ${HELP2MAN_EXECUTABLE} -N
  71. "${PROJECT_BINARY_DIR}/${page}" -o ${page_output}
  72. DEPENDS ${page}
  73. COMMENT "Generating man page for ${page}" VERBATIM)
  74. endforeach (page)
  75. add_custom_target (docs ALL DEPENDS ${project_MAN_PAGES})
  76. foreach (page ${project_MAN_PAGES})
  77. string (REGEX MATCH "\\.([0-9])$" manpage_suffix "${page}")
  78. install (FILES "${page}"
  79. DESTINATION "${CMAKE_INSTALL_MANDIR}/man${CMAKE_MATCH_1}")
  80. endforeach (page)
  81. # CPack
  82. set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "Hex viewer")
  83. set (CPACK_PACKAGE_VENDOR "Premysl Janouch")
  84. set (CPACK_PACKAGE_CONTACT "Přemysl Janouch <p.janouch@gmail.com>")
  85. set (CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
  86. set (CPACK_PACKAGE_VERSION_MAJOR ${project_VERSION_MAJOR})
  87. set (CPACK_PACKAGE_VERSION_MINOR ${project_VERSION_MINOR})
  88. set (CPACK_PACKAGE_VERSION_PATCH ${project_VERSION_PATCH})
  89. set (CPACK_GENERATOR "TGZ;ZIP")
  90. set (CPACK_PACKAGE_FILE_NAME
  91. "${PROJECT_NAME}-${project_VERSION}-${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}")
  92. set (CPACK_PACKAGE_INSTALL_DIRECTORY "${PROJECT_NAME}-${project_VERSION}")
  93. set (CPACK_SOURCE_GENERATOR "TGZ;ZIP")
  94. set (CPACK_SOURCE_IGNORE_FILES "/\\\\.git;/build;/CMakeLists.txt.user")
  95. set (CPACK_SOURCE_PACKAGE_FILE_NAME "${PROJECT_NAME}-${project_VERSION}")
  96. set (CPACK_SET_DESTDIR TRUE)
  97. include (CPack)