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.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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_GNUCC)
  5. set (wdisabled "-Wno-unused-function -Wno-implicit-fallthrough")
  6. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -Wall -Wextra ${wdisabled}")
  7. endif ()
  8. # Version
  9. set (project_VERSION_MAJOR "0")
  10. set (project_VERSION_MINOR "1")
  11. set (project_VERSION_PATCH "0")
  12. set (project_VERSION "${project_VERSION_MAJOR}")
  13. set (project_VERSION "${project_VERSION}.${project_VERSION_MINOR}")
  14. set (project_VERSION "${project_VERSION}.${project_VERSION_PATCH}")
  15. # For custom modules
  16. set (CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/liberty/cmake)
  17. # Dependencies
  18. find_package (Ncursesw REQUIRED)
  19. find_package (PkgConfig REQUIRED)
  20. find_package (Unistring REQUIRED)
  21. include (AddThreads)
  22. find_package (Termo QUIET NO_MODULE)
  23. option (USE_SYSTEM_TERMO
  24. "Don't compile our own termo library, use the system one" ${Termo_FOUND})
  25. if (USE_SYSTEM_TERMO)
  26. if (NOT Termo_FOUND)
  27. message (FATAL_ERROR "System termo library not found")
  28. endif (NOT Termo_FOUND)
  29. else ()
  30. add_subdirectory (termo EXCLUDE_FROM_ALL)
  31. # We don't have many good choices when we don't want to install it and want
  32. # to support older versions of CMake; this is a relatively clean approach
  33. # (other possibilities: setting a variable in the parent scope, using a
  34. # cache variable, writing a special config file with build paths in it and
  35. # including it here, or setting a custom property on the targets).
  36. get_directory_property (Termo_INCLUDE_DIRS
  37. DIRECTORY termo INCLUDE_DIRECTORIES)
  38. set (Termo_LIBRARIES termo-static)
  39. endif ()
  40. set (project_libraries ${UNISTRING_LIBRARIES}
  41. ${NCURSESW_LIBRARIES} termo-static)
  42. pkg_search_module (lua lua53 lua5.3 lua-5.3 lua>=5.3)
  43. option (WITH_LUA "Enable support for Lua plugins" ${lua_FOUND})
  44. if (WITH_LUA)
  45. if (NOT lua_FOUND)
  46. message (FATAL_ERROR "Lua library not found")
  47. endif ()
  48. list (APPEND project_libraries ${lua_LIBRARIES})
  49. include_directories (${lua_INCLUDE_DIRS})
  50. link_directories (${lua_LIBRARY_DIRS})
  51. include (CheckTypeSize)
  52. set (CMAKE_REQUIRED_LIBRARIES ${lua_LIBRARIES})
  53. set (CMAKE_REQUIRED_INCLUDES ${lua_INCLUDE_DIRS})
  54. set (CMAKE_EXTRA_INCLUDE_FILES "lua.h")
  55. CHECK_TYPE_SIZE (lua_Integer LUA_INTEGER)
  56. if (NOT HAVE_LUA_INTEGER OR LUA_INTEGER LESS 8)
  57. message (FATAL_ERROR "Lua must have at least 64-bit integers")
  58. endif ()
  59. endif ()
  60. include_directories (${UNISTRING_INCLUDE_DIRS}
  61. ${NCURSESW_INCLUDE_DIRS} ${Termo_INCLUDE_DIRS})
  62. # Configuration
  63. include (CheckFunctionExists)
  64. set (CMAKE_REQUIRED_LIBRARIES ${NCURSESW_LIBRARIES})
  65. CHECK_FUNCTION_EXISTS ("resizeterm" HAVE_RESIZETERM)
  66. # Generate a configuration file
  67. set (HAVE_LUA "${WITH_LUA}")
  68. configure_file (${PROJECT_SOURCE_DIR}/config.h.in
  69. ${PROJECT_BINARY_DIR}/config.h)
  70. include_directories (${PROJECT_SOURCE_DIR} ${PROJECT_BINARY_DIR})
  71. # Build the main executable and link it
  72. add_executable (${PROJECT_NAME} ${PROJECT_NAME}.c)
  73. target_link_libraries (${PROJECT_NAME} ${project_libraries})
  74. add_threads (${PROJECT_NAME})
  75. # Installation
  76. include (GNUInstallDirs)
  77. install (TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR})
  78. install (FILES LICENSE DESTINATION ${CMAKE_INSTALL_DOCDIR})
  79. # Generate documentation from program help
  80. find_program (HELP2MAN_EXECUTABLE help2man)
  81. if (NOT HELP2MAN_EXECUTABLE)
  82. message (FATAL_ERROR "help2man not found")
  83. endif ()
  84. foreach (page ${PROJECT_NAME})
  85. set (page_output "${PROJECT_BINARY_DIR}/${page}.1")
  86. list (APPEND project_MAN_PAGES "${page_output}")
  87. add_custom_command (OUTPUT ${page_output}
  88. COMMAND ${HELP2MAN_EXECUTABLE} -N
  89. "${PROJECT_BINARY_DIR}/${page}" -o ${page_output}
  90. DEPENDS ${page}
  91. COMMENT "Generating man page for ${page}" VERBATIM)
  92. endforeach ()
  93. add_custom_target (docs ALL DEPENDS ${project_MAN_PAGES})
  94. foreach (page ${project_MAN_PAGES})
  95. string (REGEX MATCH "\\.([0-9])$" manpage_suffix "${page}")
  96. install (FILES "${page}"
  97. DESTINATION "${CMAKE_INSTALL_MANDIR}/man${CMAKE_MATCH_1}")
  98. endforeach ()
  99. # CPack
  100. set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "Hex viewer")
  101. set (CPACK_PACKAGE_VENDOR "Premysl Janouch")
  102. set (CPACK_PACKAGE_CONTACT "Přemysl Janouch <p@janouch.name>")
  103. set (CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
  104. set (CPACK_PACKAGE_VERSION_MAJOR ${project_VERSION_MAJOR})
  105. set (CPACK_PACKAGE_VERSION_MINOR ${project_VERSION_MINOR})
  106. set (CPACK_PACKAGE_VERSION_PATCH ${project_VERSION_PATCH})
  107. set (CPACK_GENERATOR "TGZ;ZIP")
  108. set (CPACK_PACKAGE_FILE_NAME
  109. "${PROJECT_NAME}-${project_VERSION}-${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}")
  110. set (CPACK_PACKAGE_INSTALL_DIRECTORY "${PROJECT_NAME}-${project_VERSION}")
  111. set (CPACK_SOURCE_GENERATOR "TGZ;ZIP")
  112. set (CPACK_SOURCE_IGNORE_FILES "/\\\\.git;/build;/CMakeLists.txt.user")
  113. set (CPACK_SOURCE_PACKAGE_FILE_NAME "${PROJECT_NAME}-${project_VERSION}")
  114. set (CPACK_SET_DESTDIR TRUE)
  115. include (CPack)