unix.cmake 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. set(PUZZLES_GTK_VERSION "ANY"
  2. CACHE STRING "Which major version of GTK to build with")
  3. set_property(CACHE PUZZLES_GTK_VERSION
  4. PROPERTY STRINGS ANY 3 2)
  5. set(STRICT OFF
  6. CACHE BOOL "Enable extra compiler warnings and make them errors")
  7. set(NAME_PREFIX ""
  8. CACHE STRING "Prefix to prepend to puzzle binary names to avoid clashes \
  9. in a crowded bin directory, e.g. \"sgt-\"")
  10. find_package(PkgConfig REQUIRED)
  11. find_program(HALIBUT halibut)
  12. if(NOT HALIBUT)
  13. message(WARNING "HTML documentation cannot be built (did not find halibut)")
  14. endif()
  15. set(PUZZLES_GTK_FOUND FALSE)
  16. macro(try_gtk_package VER PACKAGENAME)
  17. if(NOT PUZZLES_GTK_FOUND AND
  18. (PUZZLES_GTK_VERSION STREQUAL ANY OR
  19. PUZZLES_GTK_VERSION STREQUAL ${VER}))
  20. pkg_check_modules(GTK ${PACKAGENAME})
  21. if(GTK_FOUND)
  22. set(PUZZLES_GTK_FOUND TRUE)
  23. endif()
  24. endif()
  25. endmacro()
  26. try_gtk_package(3 gtk+-3.0)
  27. try_gtk_package(2 gtk+-2.0)
  28. if(NOT PUZZLES_GTK_FOUND)
  29. message(FATAL_ERROR "Unable to find any usable version of GTK.")
  30. endif()
  31. include_directories(${GTK_INCLUDE_DIRS})
  32. link_directories(${GTK_LIBRARY_DIRS})
  33. set(platform_common_sources gtk.c printing.c)
  34. set(platform_gui_libs ${GTK_LIBRARIES})
  35. set(platform_libs -lm)
  36. set(build_icons TRUE)
  37. if(CMAKE_CROSSCOMPILING)
  38. # The puzzle icons are built by compiling and running a preliminary
  39. # set of puzzle binaries. We can't do that if the binaries won't run
  40. # on the build host.
  41. set(build_icons FALSE)
  42. endif()
  43. if(STRICT AND (CMAKE_C_COMPILER_ID MATCHES "GNU" OR
  44. CMAKE_C_COMPILER_ID MATCHES "Clang"))
  45. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wwrite-strings -Wmissing-prototypes -std=c99 -pedantic -Werror")
  46. endif()
  47. if(STRICT AND (CMAKE_C_COMPILER_ID MATCHES "Clang"))
  48. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-variable-declarations")
  49. endif()
  50. add_compile_definitions(HELP_DIR="${CMAKE_INSTALL_PREFIX}/share/sgt-puzzles/help")
  51. function(get_platform_puzzle_extra_source_files OUTVAR NAME)
  52. if(build_icons AND EXISTS ${CMAKE_SOURCE_DIR}/icons/${NAME}.sav)
  53. # If we have the equipment to rebuild the puzzles' icon images
  54. # from scratch, do so. Then changes in the puzzle display code
  55. # will cause the icon to auto-update.
  56. build_icon(${NAME})
  57. set(c_icon_file ${CMAKE_BINARY_DIR}/icons/${NAME}-icon.c)
  58. elseif(EXISTS ${CMAKE_SOURCE_DIR}/icons/${NAME}-icon.c)
  59. # Failing that, use a pre-built icon file in the 'icons'
  60. # subdirectory, if there is one. (They don't exist in git, but the
  61. # distribution tarball will have pre-built them and put them in
  62. # there, so that users building from that can still have icons
  63. # even if they don't have the wherewithal to rebuild them.)
  64. set(c_icon_file ${CMAKE_SOURCE_DIR}/icons/${NAME}-icon.c)
  65. else()
  66. # Failing even that, include no-icon.c to satisfy the link-time
  67. # dependencies. The puzzles will build without nice icons.
  68. set(c_icon_file ${CMAKE_SOURCE_DIR}/no-icon.c)
  69. endif()
  70. set(${OUTVAR} ${c_icon_file} PARENT_SCOPE)
  71. endfunction()
  72. function(set_platform_gui_target_properties TARGET)
  73. endfunction()
  74. function(set_platform_puzzle_target_properties NAME TARGET)
  75. get_target_property(official ${TARGET} official)
  76. get_target_property(exename ${TARGET} exename)
  77. get_target_property(displayname ${TARGET} displayname)
  78. get_target_property(description ${TARGET} description)
  79. set(binary_name ${NAME_PREFIX}${NAME})
  80. set_target_properties(${TARGET} PROPERTIES
  81. OUTPUT_NAME ${binary_name})
  82. if(${official})
  83. if(CMAKE_VERSION VERSION_LESS 3.14)
  84. # CMake 3.13 and earlier required an explicit install destination.
  85. install(TARGETS ${TARGET} RUNTIME DESTINATION bin)
  86. else()
  87. # 3.14 and above selects a sensible default, which we should avoid
  88. # overriding here so that end users can override it using
  89. # CMAKE_INSTALL_BINDIR.
  90. install(TARGETS ${TARGET})
  91. endif()
  92. configure_file(${CMAKE_SOURCE_DIR}/puzzle.desktop.in ${binary_name}.desktop)
  93. foreach(icon_size ${all_icon_sizes})
  94. install(
  95. FILES ${CMAKE_CURRENT_BINARY_DIR}/icons/${NAME}-${icon_size}d24.png
  96. DESTINATION share/icons/hicolor/${icon_size}x${icon_size}/apps
  97. OPTIONAL
  98. RENAME ${binary_name}.png)
  99. endforeach()
  100. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${binary_name}.desktop
  101. DESTINATION share/applications)
  102. endif()
  103. endfunction()
  104. function(build_platform_extras)
  105. if(HALIBUT)
  106. set(help_dir ${CMAKE_CURRENT_BINARY_DIR}/help)
  107. add_custom_command(OUTPUT ${help_dir}/en
  108. COMMAND ${CMAKE_COMMAND} -E make_directory ${help_dir}/en)
  109. add_custom_command(OUTPUT ${help_dir}/en/index.html
  110. COMMAND ${HALIBUT} --html ${CMAKE_CURRENT_SOURCE_DIR}/puzzles.but
  111. DEPENDS
  112. ${help_dir}/en
  113. ${CMAKE_CURRENT_SOURCE_DIR}/puzzles.but
  114. WORKING_DIRECTORY ${help_dir}/en)
  115. add_custom_target(unix_help ALL
  116. DEPENDS ${help_dir}/en/index.html)
  117. install(DIRECTORY ${help_dir}
  118. DESTINATION share/sgt-puzzles)
  119. endif()
  120. endfunction()