setup.cmake 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. # Forcibly re-enable assertions, even if we're building in release
  2. # mode. This is a security project - assertions may be enforcing
  3. # security-critical constraints. A backstop #ifdef in defs.h should
  4. # give a #error if this manoeuvre doesn't do what it needs to.
  5. string(REPLACE "/DNDEBUG" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
  6. string(REPLACE "-DNDEBUG" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
  7. string(REPLACE "/DNDEBUG" "" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
  8. string(REPLACE "-DNDEBUG" "" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
  9. set(PUTTY_IPV6 ON
  10. CACHE BOOL "Build PuTTY with IPv6 support if possible")
  11. set(PUTTY_DEBUG OFF
  12. CACHE BOOL "Build PuTTY with debug() statements enabled")
  13. set(PUTTY_FUZZING OFF
  14. CACHE BOOL "Build PuTTY binaries suitable for fuzzing, NOT FOR REAL USE")
  15. set(PUTTY_COVERAGE OFF
  16. CACHE BOOL "Build PuTTY binaries suitable for code coverage analysis")
  17. set(PUTTY_COMPRESS_SCROLLBACK ON
  18. # This is always on in production versions of PuTTY, but downstreams
  19. # of the code have been known to find it a better tradeoff to
  20. # disable it. So there's a #ifdef in terminal.c, and a cmake option
  21. # to enable that ifdef just in case it needs testing or debugging.
  22. CACHE BOOL "Store terminal scrollback in compressed form")
  23. set(STRICT OFF
  24. CACHE BOOL "Enable extra compiler warnings and make them errors")
  25. include(FindGit)
  26. set(GENERATED_SOURCES_DIR ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY})
  27. set(GENERATED_LICENCE_H ${GENERATED_SOURCES_DIR}/licence.h)
  28. set(INTERMEDIATE_LICENCE_H ${GENERATED_LICENCE_H}.tmp)
  29. add_custom_command(OUTPUT ${INTERMEDIATE_LICENCE_H}
  30. COMMAND ${CMAKE_COMMAND}
  31. -DLICENCE_FILE=${CMAKE_SOURCE_DIR}/LICENCE
  32. -DOUTPUT_FILE=${INTERMEDIATE_LICENCE_H}
  33. -P ${CMAKE_SOURCE_DIR}/cmake/licence.cmake
  34. DEPENDS ${CMAKE_SOURCE_DIR}/cmake/licence.cmake ${CMAKE_SOURCE_DIR}/LICENCE)
  35. add_custom_target(generated_licence_h
  36. BYPRODUCTS ${GENERATED_LICENCE_H}
  37. COMMAND ${CMAKE_COMMAND} -E copy_if_different
  38. ${INTERMEDIATE_LICENCE_H} ${GENERATED_LICENCE_H}
  39. DEPENDS ${INTERMEDIATE_LICENCE_H}
  40. COMMENT "Updating licence.h")
  41. set(GENERATED_COMMIT_C ${GENERATED_SOURCES_DIR}/cmake_commit.c)
  42. set(INTERMEDIATE_COMMIT_C ${GENERATED_COMMIT_C}.tmp)
  43. add_custom_target(check_git_commit
  44. BYPRODUCTS ${INTERMEDIATE_COMMIT_C}
  45. COMMAND ${CMAKE_COMMAND}
  46. -DGIT_EXECUTABLE=${GIT_EXECUTABLE}
  47. -DOUTPUT_FILE=${INTERMEDIATE_COMMIT_C}
  48. -DOUTPUT_TYPE=header
  49. -P ${CMAKE_SOURCE_DIR}/cmake/gitcommit.cmake
  50. DEPENDS ${CMAKE_SOURCE_DIR}/cmake/gitcommit.cmake
  51. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  52. COMMENT "Checking current git commit")
  53. add_custom_target(cmake_commit_c
  54. BYPRODUCTS ${GENERATED_COMMIT_C}
  55. COMMAND ${CMAKE_COMMAND} -E copy_if_different
  56. ${INTERMEDIATE_COMMIT_C} ${GENERATED_COMMIT_C}
  57. DEPENDS check_git_commit ${INTERMEDIATE_COMMIT_C}
  58. COMMENT "Updating cmake_commit.c")
  59. if(CMAKE_VERSION VERSION_LESS 3.12)
  60. function(add_compile_definitions)
  61. foreach(i ${ARGN})
  62. add_compile_options(-D${i})
  63. endforeach()
  64. endfunction()
  65. endif()
  66. function(add_sources_from_current_dir target)
  67. set(sources)
  68. foreach(i ${ARGN})
  69. set(sources ${sources} ${CMAKE_CURRENT_SOURCE_DIR}/${i})
  70. endforeach()
  71. target_sources(${target} PRIVATE ${sources})
  72. endfunction()
  73. set(extra_dirs)
  74. if(CMAKE_SYSTEM_NAME MATCHES "Windows" OR WINELIB)
  75. set(platform windows)
  76. else()
  77. set(platform unix)
  78. endif()
  79. function(be_list TARGET NAME)
  80. cmake_parse_arguments(OPT "SSH;SERIAL;OTHERBACKENDS" "" "" "${ARGN}")
  81. add_library(${TARGET}-be-list OBJECT ${CMAKE_SOURCE_DIR}/be_list.c)
  82. foreach(setting SSH SERIAL OTHERBACKENDS)
  83. if(OPT_${setting})
  84. target_compile_definitions(${TARGET}-be-list PRIVATE ${setting}=1)
  85. else()
  86. target_compile_definitions(${TARGET}-be-list PRIVATE ${setting}=0)
  87. endif()
  88. endforeach()
  89. target_compile_definitions(${TARGET}-be-list PRIVATE APPNAME=${NAME})
  90. target_sources(${TARGET} PRIVATE $<TARGET_OBJECTS:${TARGET}-be-list>)
  91. endfunction()
  92. include(cmake/platforms/${platform}.cmake)
  93. include_directories(
  94. ${CMAKE_CURRENT_SOURCE_DIR}
  95. ${GENERATED_SOURCES_DIR}
  96. ${platform}
  97. ${extra_dirs})
  98. check_c_source_compiles("
  99. #define _ISOC11_SOURCE
  100. #include <stdlib.h>
  101. int main(int argc, char **argv) {
  102. void *p = aligned_alloc(128, 12345);
  103. free(p);
  104. }" HAVE_ALIGNED_ALLOC)
  105. if(PUTTY_DEBUG)
  106. add_compile_definitions(DEBUG)
  107. endif()
  108. if(PUTTY_FUZZING)
  109. add_compile_definitions(FUZZING)
  110. endif()
  111. if(NOT PUTTY_COMPRESS_SCROLLBACK)
  112. set(NO_SCROLLBACK_COMPRESSION ON)
  113. endif()
  114. if(PUTTY_COVERAGE)
  115. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage -g ")
  116. endif()