mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-02 03:52:49 -05:00
Replace mkfiles.pl with a CMake build system.
This brings various concrete advantages over the previous system: - consistent support for out-of-tree builds on all platforms - more thorough support for Visual Studio IDE project files - support for Ninja-based builds, which is particularly useful on Windows where the alternative nmake has no parallel option - a really simple set of build instructions that work the same way on all the major platforms (look how much shorter README is!) - better decoupling of the project configuration from the toolchain configuration, so that my Windows cross-building doesn't need (much) special treatment in CMakeLists.txt - configure-time tests on Windows as well as Linux, so that a lot of ad-hoc #ifdefs second-guessing a particular feature's presence from the compiler version can now be replaced by tests of the feature itself Also some longer-term software-engineering advantages: - other people have actually heard of CMake, so they'll be able to produce patches to the new build setup more easily - unlike the old mkfiles.pl, CMake is not my personal problem to maintain - most importantly, mkfiles.pl was just a horrible pile of unmaintainable cruft, which even I found it painful to make changes to or to use, and desperately needed throwing in the bin. I've already thrown away all the variants of it I had in other projects of mine, and was only delaying this one so we could make the 0.75 release branch first. This change comes with a noticeable build-level restructuring. The previous Recipe worked by compiling every object file exactly once, and then making each executable by linking a precisely specified subset of the same object files. But in CMake, that's not the natural way to work - if you write the obvious command that puts the same source file into two executable targets, CMake generates a makefile that compiles it once per target. That can be an advantage, because it gives you the freedom to compile it differently in each case (e.g. with a #define telling it which program it's part of). But in a project that has many executable targets and had carefully contrived to _never_ need to build any module more than once, all it does is bloat the build time pointlessly! To avoid slowing down the build by a large factor, I've put most of the modules of the code base into a collection of static libraries organised vaguely thematically (SSH, other backends, crypto, network, ...). That means all those modules can still be compiled just once each, because once each library is built it's reused unchanged for all the executable targets. One upside of this library-based structure is that now I don't have to manually specify exactly which objects go into which programs any more - it's enough to specify which libraries are needed, and the linker will figure out the fine detail automatically. So there's less maintenance to do in CMakeLists.txt when the source code changes. But that reorganisation also adds fragility, because of the trad Unix linker semantics of walking along the library list once each, so that cyclic references between your libraries will provoke link errors. The current setup builds successfully, but I suspect it only just manages it. (In particular, I've found that MinGW is the most finicky on this score of the Windows compilers I've tried building with. So I've included a MinGW test build in the new-look Buildscr, because otherwise I think there'd be a significant risk of introducing MinGW-only build failures due to library search order, which wasn't a risk in the previous library-free build organisation.) In the longer term I hope to be able to reduce the risk of that, via gradual reorganisation (in particular, breaking up too-monolithic modules, to reduce the risk of knock-on references when you included a module for function A and it also contains function B with an unsatisfied dependency you didn't really need). Ideally I want to reach a state in which the libraries all have sensibly described purposes, a clearly documented (partial) order in which they're permitted to depend on each other, and a specification of what stubs you have to put where if you're leaving one of them out (e.g. nocrypto) and what callbacks you have to define in your non-library objects to satisfy dependencies from things low in the stack (e.g. out_of_memory()). One thing that's gone completely missing in this migration, unfortunately, is the unfinished MacOS port linked against Quartz GTK. That's because it turned out that I can't currently build it myself, on my own Mac: my previous installation of GTK had bit-rotted as a side effect of an Xcode upgrade, and I haven't yet been able to persuade jhbuild to make me a new one. So I can't even build the MacOS port with the _old_ makefiles, and hence, I have no way of checking that the new ones also work. I hope to bring that port back to life at some point, but I don't want it to block the rest of this change.
This commit is contained in:
35
cmake/cmake.h.in
Normal file
35
cmake/cmake.h.in
Normal file
@ -0,0 +1,35 @@
|
||||
#cmakedefine NO_IPV6
|
||||
#cmakedefine NO_GSSAPI
|
||||
#cmakedefine STATIC_GSSAPI
|
||||
|
||||
#cmakedefine NO_MULTIMON
|
||||
|
||||
#cmakedefine01 HAVE_WINRESRC_H
|
||||
#cmakedefine01 HAVE_WINRES_H
|
||||
#cmakedefine01 HAVE_WIN_H
|
||||
#cmakedefine01 HAVE_NO_STDINT_H
|
||||
#cmakedefine01 HAVE_GCP_RESULTSW
|
||||
#cmakedefine01 HAVE_ADDDLLDIRECTORY
|
||||
#cmakedefine01 HAVE_GETNAMEDPIPECLIENTPROCESSID
|
||||
#cmakedefine01 HAVE_SETDEFAULTDLLDIRECTORIES
|
||||
#cmakedefine01 HAVE_STRTOUMAX
|
||||
|
||||
#cmakedefine NOT_X_WINDOWS
|
||||
|
||||
#cmakedefine01 HAVE_FUTIMES
|
||||
#cmakedefine01 HAVE_GETADDRINFO
|
||||
#cmakedefine01 HAVE_POSIX_OPENPT
|
||||
#cmakedefine01 HAVE_PTSNAME
|
||||
#cmakedefine01 HAVE_SETRESUID
|
||||
#cmakedefine01 HAVE_STRSIGNAL
|
||||
#cmakedefine01 HAVE_UPDWTMPX
|
||||
#cmakedefine01 HAVE_FSTATAT
|
||||
#cmakedefine01 HAVE_DIRFD
|
||||
#cmakedefine01 HAVE_SETPWENT
|
||||
#cmakedefine01 HAVE_ENDPWENT
|
||||
#cmakedefine01 HAVE_GETAUXVAL
|
||||
#cmakedefine01 HAVE_CLOCK_MONOTONIC
|
||||
#cmakedefine01 HAVE_CLOCK_GETTIME
|
||||
#cmakedefine01 HAVE_SO_PEERCRED
|
||||
#cmakedefine01 HAVE_PANGO_FONT_FAMILY_IS_MONOSPACE
|
||||
#cmakedefine01 HAVE_PANGO_FONT_MAP_LIST_FAMILIES
|
48
cmake/gitcommit.cmake
Normal file
48
cmake/gitcommit.cmake
Normal file
@ -0,0 +1,48 @@
|
||||
# Pure cmake script to write out cmake_commit.h
|
||||
|
||||
set(DEFAULT_COMMIT "unavailable")
|
||||
set(commit "${DEFAULT_COMMIT}")
|
||||
|
||||
execute_process(
|
||||
COMMAND ${GIT_EXECUTABLE} -C ${TOPLEVEL_SOURCE_DIR}
|
||||
rev-parse --show-toplevel
|
||||
OUTPUT_VARIABLE git_worktree
|
||||
ERROR_VARIABLE stderr
|
||||
RESULT_VARIABLE status)
|
||||
string(REGEX REPLACE "\n$" "" git_worktree "${git_worktree}")
|
||||
|
||||
if(status EQUAL 0)
|
||||
if(git_worktree STREQUAL TOPLEVEL_SOURCE_DIR)
|
||||
execute_process(
|
||||
COMMAND ${GIT_EXECUTABLE} -C ${TOPLEVEL_SOURCE_DIR}
|
||||
rev-parse HEAD
|
||||
OUTPUT_VARIABLE git_commit
|
||||
ERROR_VARIABLE stderr
|
||||
RESULT_VARIABLE status)
|
||||
if(status EQUAL 0)
|
||||
string(REGEX REPLACE "\n$" "" commit "${git_commit}")
|
||||
else()
|
||||
if(commit STREQUAL "unavailable")
|
||||
message("Unable to determine git commit: 'git rev-parse HEAD' returned status ${status} and error output:\n${stderr}\n")
|
||||
endif()
|
||||
endif()
|
||||
else()
|
||||
if(commit STREQUAL "unavailable")
|
||||
message("Unable to determine git commit: top-level source dir ${TOPLEVEL_SOURCE_DIR} is not the root of a repository")
|
||||
endif()
|
||||
endif()
|
||||
else()
|
||||
if(commit STREQUAL "unavailable")
|
||||
message("Unable to determine git commit: 'git rev-parse --show-toplevel' returned status ${status} and error output:\n${stderr}\n")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
file(WRITE "${OUTPUT_FILE}" "\
|
||||
/*
|
||||
* cmake_commit.h - string literal giving the source git commit, if known.
|
||||
*
|
||||
* Generated by cmake/gitcommit.cmake.
|
||||
*/
|
||||
|
||||
const char commitid[] = \"${commit}\";
|
||||
")
|
85
cmake/gtk.cmake
Normal file
85
cmake/gtk.cmake
Normal file
@ -0,0 +1,85 @@
|
||||
# Look for GTK, of any version.
|
||||
|
||||
set(PUTTY_GTK_VERSION "ANY"
|
||||
CACHE STRING "Which major version of GTK to build with")
|
||||
set_property(CACHE PUTTY_GTK_VERSION
|
||||
PROPERTY STRINGS ANY 3 2 1)
|
||||
|
||||
set(GTK_FOUND FALSE)
|
||||
|
||||
macro(try_pkg_config_gtk VER PACKAGENAME)
|
||||
if(NOT GTK_FOUND AND
|
||||
(PUTTY_GTK_VERSION STREQUAL ANY OR PUTTY_GTK_VERSION STREQUAL ${VER}))
|
||||
find_package(PkgConfig)
|
||||
pkg_check_modules(GTK ${PACKAGENAME})
|
||||
endif()
|
||||
endmacro()
|
||||
try_pkg_config_gtk(3 gtk+-3.0)
|
||||
try_pkg_config_gtk(2 gtk+-2.0)
|
||||
|
||||
if(NOT GTK_FOUND AND
|
||||
(PUTTY_GTK_VERSION STREQUAL ANY OR PUTTY_GTK_VERSION STREQUAL 1))
|
||||
message("-- Checking for GTK1 (via gtk-config)")
|
||||
find_program(GTK_CONFIG gtk-config)
|
||||
if(GTK_CONFIG)
|
||||
execute_process(COMMAND ${GTK_CONFIG} --cflags
|
||||
OUTPUT_VARIABLE gtk_config_cflags
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
RESULT_VARIABLE gtk_config_cflags_result)
|
||||
execute_process(COMMAND ${GTK_CONFIG} --libs
|
||||
OUTPUT_VARIABLE gtk_config_libs
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
RESULT_VARIABLE gtk_config_libs_result)
|
||||
|
||||
if(gtk_config_cflags_result EQUAL 0 AND gtk_config_libs_result EQUAL 0)
|
||||
|
||||
set(GTK_INCLUDE_DIRS)
|
||||
set(GTK_LIBRARY_DIRS)
|
||||
set(GTK_LIBRARIES)
|
||||
|
||||
separate_arguments(gtk_config_cflags NATIVE_COMMAND
|
||||
${gtk_config_cflags})
|
||||
foreach(opt ${gtk_config_cflags})
|
||||
string(REGEX MATCH "^-I" ok ${opt})
|
||||
if(ok)
|
||||
string(REGEX REPLACE "^-I" "" optval ${opt})
|
||||
list(APPEND GTK_INCLUDE_DIRS ${optval})
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
separate_arguments(gtk_config_libs NATIVE_COMMAND
|
||||
${gtk_config_libs})
|
||||
foreach(opt ${gtk_config_libs})
|
||||
string(REGEX MATCH "^-l" ok ${opt})
|
||||
if(ok)
|
||||
list(APPEND GTK_LIBRARIES ${opt})
|
||||
endif()
|
||||
string(REGEX MATCH "^-L" ok ${opt})
|
||||
if(ok)
|
||||
string(REGEX REPLACE "^-L" "" optval ${opt})
|
||||
list(APPEND GTK_LIBRARY_DIRS ${optval})
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
message("-- Found GTK1")
|
||||
set(GTK_FOUND TRUE)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(GTK_FOUND)
|
||||
# Check for some particular Pango functions.
|
||||
function(pango_check_subscope)
|
||||
set(CMAKE_REQUIRED_INCLUDES ${GTK_INCLUDE_DIRS})
|
||||
set(CMAKE_REQUIRED_LIBRARIES ${GTK_LIBRARIES})
|
||||
check_symbol_exists(pango_font_family_is_monospace "pango/pango.h"
|
||||
HAVE_PANGO_FONT_FAMILY_IS_MONOSPACE)
|
||||
check_symbol_exists(pango_font_map_list_families "pango/pango.h"
|
||||
HAVE_PANGO_FONT_MAP_LIST_FAMILIES)
|
||||
set(HAVE_PANGO_FONT_FAMILY_IS_MONOSPACE
|
||||
${HAVE_PANGO_FONT_FAMILY_IS_MONOSPACE} PARENT_SCOPE)
|
||||
set(HAVE_PANGO_FONT_MAP_LIST_FAMILIES
|
||||
${HAVE_PANGO_FONT_MAP_LIST_FAMILIES} PARENT_SCOPE)
|
||||
endfunction()
|
||||
pango_check_subscope()
|
||||
endif()
|
39
cmake/licence.cmake
Normal file
39
cmake/licence.cmake
Normal file
@ -0,0 +1,39 @@
|
||||
# Pure cmake script to generate licence.h from LICENCE
|
||||
|
||||
file(READ "${LICENCE_FILE}" LICENCE_TEXT)
|
||||
|
||||
function(c_string_escape outvar value)
|
||||
string(REPLACE "\\" "\\\\" value "${value}")
|
||||
string(REPLACE "\"" "\\\"" value "${value}")
|
||||
set("${outvar}" "${value}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
set(copyright_regex "PuTTY is copyright ([0-9]+-[0-9]+ [^\n]*[^\n.])\\.?\n")
|
||||
string(REGEX MATCH "${copyright_regex}" COPYRIGHT_NOTICE "${LICENCE_TEXT}")
|
||||
string(REGEX REPLACE "${copyright_regex}" "\\1"
|
||||
COPYRIGHT_NOTICE "${COPYRIGHT_NOTICE}")
|
||||
c_string_escape(COPYRIGHT_NOTICE "${COPYRIGHT_NOTICE}")
|
||||
|
||||
string(REGEX REPLACE "\n$" "" LICENCE_TEXT "${LICENCE_TEXT}")
|
||||
string(REPLACE "\r" "" LICENCE_TEXT "${LICENCE_TEXT}")
|
||||
string(REPLACE "\n\n" "\r" LICENCE_TEXT "${LICENCE_TEXT}")
|
||||
string(REPLACE "\n" " " LICENCE_TEXT "${LICENCE_TEXT}")
|
||||
string(REPLACE "\r" "\n" LICENCE_TEXT "${LICENCE_TEXT}")
|
||||
|
||||
c_string_escape(LICENCE_TEXT "${LICENCE_TEXT}")
|
||||
string(REPLACE "\n" "\" \\\n parsep \\\n \""
|
||||
LICENCE_TEXT "${LICENCE_TEXT}")
|
||||
|
||||
file(WRITE "${OUTPUT_FILE}" "\
|
||||
/*
|
||||
* licence.h - macro definitions for the PuTTY licence.
|
||||
*
|
||||
* Generated by cmake/licence.cmake from ./LICENCE.
|
||||
* You should edit those files rather than editing this one.
|
||||
*/
|
||||
|
||||
#define LICENCE_TEXT(parsep) \\
|
||||
\"${LICENCE_TEXT}\"
|
||||
|
||||
#define SHORT_COPYRIGHT_DETAILS \"${COPYRIGHT_NOTICE}\"
|
||||
")
|
121
cmake/platforms/unix.cmake
Normal file
121
cmake/platforms/unix.cmake
Normal file
@ -0,0 +1,121 @@
|
||||
set(PLATFORM_SUBDIRS charset unix)
|
||||
|
||||
set(PUTTY_GSSAPI DYNAMIC
|
||||
CACHE STRING "Build PuTTY with dynamically or statically linked \
|
||||
Kerberos / GSSAPI support, if possible")
|
||||
set_property(CACHE PUTTY_GSSAPI
|
||||
PROPERTY STRINGS DYNAMIC STATIC OFF)
|
||||
|
||||
include(CheckIncludeFile)
|
||||
include(CheckLibraryExists)
|
||||
include(CheckSymbolExists)
|
||||
include(CheckCSourceCompiles)
|
||||
|
||||
set(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
|
||||
-D_DEFAULT_SOURCE -D_GNU_SOURCE)
|
||||
|
||||
check_include_file(sys/auxv.h HAVE_SYS_AUXV_H)
|
||||
check_include_file(asm/hwcap.h HAVE_ASM_HWCAP_H)
|
||||
check_include_file(sys/sysctl.h HAVE_SYS_SYSCTL_H)
|
||||
check_include_file(sys/types.h HAVE_SYS_TYPES_H)
|
||||
check_include_file(glob.h HAVE_GLOB_H)
|
||||
|
||||
check_symbol_exists(futimes "sys/time.h" HAVE_FUTIMES)
|
||||
check_symbol_exists(getaddrinfo "sys/types.h;sys/socket.h;netdb.h"
|
||||
HAVE_GETADDRINFO)
|
||||
check_symbol_exists(posix_openpt "stdlib.h;fcntl.h" HAVE_POSIX_OPENPT)
|
||||
check_symbol_exists(ptsname "stdlib.h" HAVE_PTSNAME)
|
||||
check_symbol_exists(setresuid "unistd.h" HAVE_SETRESUID)
|
||||
check_symbol_exists(setresgid "unistd.h" HAVE_SETRESGID)
|
||||
check_symbol_exists(strsignal "string.h" HAVE_STRSIGNAL)
|
||||
check_symbol_exists(updwtmpx "utmpx.h" HAVE_UPDWTMPX)
|
||||
check_symbol_exists(fstatat "sys/types.h;sys/stat.h;unistd.h" HAVE_FSTATAT)
|
||||
check_symbol_exists(dirfd "sys/types.h;dirent.h" HAVE_DIRFD)
|
||||
check_symbol_exists(setpwent "sys/types.h;pwd.h" HAVE_SETPWENT)
|
||||
check_symbol_exists(endpwent "sys/types.h;pwd.h" HAVE_ENDPWENT)
|
||||
check_symbol_exists(getauxval "sys/auxv.h" HAVE_GETAUXVAL)
|
||||
check_symbol_exists(CLOCK_MONOTONIC "time.h" HAVE_CLOCK_MONOTONIC)
|
||||
check_symbol_exists(clock_gettime "time.h" HAVE_CLOCK_GETTIME)
|
||||
|
||||
check_c_source_compiles("
|
||||
#define _GNU_SOURCE
|
||||
#include <features.h>
|
||||
#include <sys/socket.h>
|
||||
int main(int argc, char **argv) {
|
||||
struct ucred cr;
|
||||
socklen_t crlen = sizeof(cr);
|
||||
return getsockopt(0, SOL_SOCKET, SO_PEERCRED, &cr, &crlen) +
|
||||
cr.pid + cr.uid + cr.gid;
|
||||
}" HAVE_SO_PEERCRED)
|
||||
|
||||
if(HAVE_GETADDRINFO AND PUTTY_IPV6)
|
||||
set(NO_IPV6 OFF)
|
||||
else()
|
||||
set(NO_IPV6 ON)
|
||||
endif()
|
||||
|
||||
include(cmake/gtk.cmake)
|
||||
|
||||
find_package(X11)
|
||||
if(NOT X11_FOUND)
|
||||
set(NOT_X_WINDOWS ON)
|
||||
else()
|
||||
set(NOT_X_WINDOWS OFF)
|
||||
endif()
|
||||
|
||||
include_directories(${CMAKE_SOURCE_DIR}/charset ${GTK_INCLUDE_DIRS} ${X11_INCLUDE_DIR})
|
||||
link_directories(${GTK_LIBRARY_DIRS})
|
||||
|
||||
function(add_optional_system_lib library testfn)
|
||||
check_library_exists(${library} ${testfn} "" HAVE_LIB${library})
|
||||
if (HAVE_LIB${library})
|
||||
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES};-l${library})
|
||||
link_libraries(-l${library})
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
add_optional_system_lib(m pow)
|
||||
add_optional_system_lib(rt clock_gettime)
|
||||
add_optional_system_lib(xnet socket)
|
||||
|
||||
if(PUTTY_GSSAPI STREQUAL DYNAMIC)
|
||||
add_optional_system_lib(dl dlopen)
|
||||
if(HAVE_NO_LIBdl)
|
||||
message(WARNING
|
||||
"Could not find libdl -- cannot provide dynamic GSSAPI support")
|
||||
set(NO_GSSAPI ON)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(PUTTY_GSSAPI STREQUAL STATIC)
|
||||
find_package(PkgConfig)
|
||||
pkg_check_modules(KRB5 krb5-gssapi)
|
||||
if(KRB5_FOUND)
|
||||
include_directories(${KRB5_INCLUDE_DIRS})
|
||||
link_directories(${KRB5_LIBRARY_DIRS})
|
||||
link_libraries(${KRB5_LIBRARIES})
|
||||
set(STATIC_GSSAPI ON)
|
||||
else()
|
||||
message(WARNING
|
||||
"Could not find krb5 via pkg-config -- \
|
||||
cannot provide static GSSAPI support")
|
||||
set(NO_GSSAPI ON)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(STRICT AND (CMAKE_C_COMPILER_ID MATCHES "GNU" OR
|
||||
CMAKE_C_COMPILER_ID MATCHES "Clang"))
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror -Wpointer-arith -Wvla")
|
||||
endif()
|
||||
|
||||
function(installed_program target)
|
||||
if(CMAKE_VERSION VERSION_LESS 3.14)
|
||||
# CMake 3.13 and earlier required an explicit install destination.
|
||||
install(TARGETS ${target} RUNTIME DESTINATION bin)
|
||||
else()
|
||||
# 3.14 and above selects a sensible default, which we should avoid
|
||||
# overriding here so that end users can override it using
|
||||
# CMAKE_INSTALL_BINDIR.
|
||||
install(TARGETS ${target})
|
||||
endif()
|
||||
endfunction()
|
171
cmake/platforms/windows.cmake
Normal file
171
cmake/platforms/windows.cmake
Normal file
@ -0,0 +1,171 @@
|
||||
set(PLATFORM_SUBDIRS windows)
|
||||
|
||||
# I copied this over from the pre-CMake build system just to prove it
|
||||
# still worked, but I should probably remove it now, together with all
|
||||
# the #ifdefs that depend on it.
|
||||
#
|
||||
# Rationale: it was there so that you could do dev builds of PuTTY on
|
||||
# compilers designed for the pre-NT single-user versions of Windows
|
||||
# (Win95, Win98 etc). But we're not supporting those development
|
||||
# environments any more!
|
||||
set(PUTTY_NO_SECURITY OFF
|
||||
CACHE BOOL "OBSOLETE AND DANGEROUS - DO NOT DEFINE! \
|
||||
Build PuTTY without any use of the Windows security APIs.")
|
||||
set(PUTTY_MINEFIELD OFF
|
||||
CACHE BOOL "Build PuTTY with its built-in memory debugger 'Minefield'")
|
||||
set(PUTTY_GSSAPI ON
|
||||
CACHE BOOL "Build PuTTY with GSSAPI support")
|
||||
set(PUTTY_LINK_MAPS OFF
|
||||
CACHE BOOL "Attempt to generate link maps")
|
||||
set(PUTTY_EMBEDDED_CHM_FILE ""
|
||||
CACHE FILEPATH "Path to a .chm help file to embed in the binaries")
|
||||
|
||||
function(define_negation newvar oldvar)
|
||||
if(${oldvar})
|
||||
set(${newvar} OFF PARENT_SCOPE)
|
||||
else()
|
||||
set(${newvar} ON PARENT_SCOPE)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
include(CheckIncludeFiles)
|
||||
include(CheckSymbolExists)
|
||||
include(CheckCSourceCompiles)
|
||||
|
||||
# Still needed for AArch32 Windows builds
|
||||
set(CMAKE_REQUIRED_DEFINITIONS -D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE)
|
||||
|
||||
check_include_files("windows.h;winresrc.h" HAVE_WINRESRC_H)
|
||||
check_include_files("windows.h;winres.h" HAVE_WINRES_H)
|
||||
check_include_files("windows.h;win.h" HAVE_WIN_H)
|
||||
check_include_files("stdint.h" HAVE_STDINT_H)
|
||||
define_negation(HAVE_NO_STDINT_H HAVE_STDINT_H)
|
||||
|
||||
check_include_files("windows.h;multimon.h" HAVE_MULTIMON_H)
|
||||
define_negation(NO_MULTIMON HAVE_MULTIMON_H)
|
||||
|
||||
check_include_files("windows.h;htmlhelp.h" HAVE_HTMLHELP_H)
|
||||
define_negation(NO_HTMLHELP HAVE_HTMLHELP_H)
|
||||
|
||||
check_symbol_exists(SecureZeroMemory "windows.h" HAVE_SECUREZEROMEMORY)
|
||||
define_negation(NO_SECUREZEROMEMORY HAVE_SECUREZEROMEMORY)
|
||||
|
||||
check_symbol_exists(strtoumax "inttypes.h" HAVE_STRTOUMAX)
|
||||
check_symbol_exists(AddDllDirectory "windows.h" HAVE_ADDDLLDIRECTORY)
|
||||
check_symbol_exists(SetDefaultDllDirectories "windows.h"
|
||||
HAVE_SETDEFAULTDLLDIRECTORIES)
|
||||
check_symbol_exists(GetNamedPipeClientProcessId "windows.h"
|
||||
HAVE_GETNAMEDPIPECLIENTPROCESSID)
|
||||
|
||||
check_c_source_compiles("
|
||||
#include <windows.h>
|
||||
GCP_RESULTSW gcpw;
|
||||
int main(void) { return 0; }
|
||||
" HAVE_GCP_RESULTSW)
|
||||
|
||||
set(NO_SECURITY ${PUTTY_NO_SECURITY})
|
||||
|
||||
add_compile_definitions(
|
||||
_WINDOWS
|
||||
_CRT_SECURE_NO_WARNINGS
|
||||
_WINSOCK_DEPRECATED_NO_WARNINGS
|
||||
_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE)
|
||||
|
||||
if(PUTTY_MINEFIELD)
|
||||
add_compile_definitions(MINEFIELD)
|
||||
endif()
|
||||
if(NOT PUTTY_GSSAPI)
|
||||
add_compile_definitions(NO_GSSAPI)
|
||||
endif()
|
||||
if(PUTTY_EMBEDDED_CHM_FILE)
|
||||
add_compile_definitions("EMBEDDED_CHM_FILE=\"${PUTTY_EMBEDDED_CHM_FILE}\"")
|
||||
endif()
|
||||
|
||||
if(WINELIB)
|
||||
enable_language(RC)
|
||||
set(LFLAG_MANIFEST_NO "")
|
||||
elseif(CMAKE_C_COMPILER_ID MATCHES "MSVC" OR
|
||||
CMAKE_C_COMPILER_FRONTEND_VARIANT MATCHES "MSVC")
|
||||
set(CMAKE_RC_FLAGS "${CMAKE_RC_FLAGS} /nologo /C1252")
|
||||
set(LFLAG_MANIFEST_NO "/manifest:no")
|
||||
else()
|
||||
set(CMAKE_RC_FLAGS "${CMAKE_RC_FLAGS} -c1252")
|
||||
set(LFLAG_MANIFEST_NO "")
|
||||
endif()
|
||||
|
||||
if(STRICT AND (CMAKE_C_COMPILER_ID MATCHES "GNU" OR
|
||||
CMAKE_C_COMPILER_ID MATCHES "Clang"))
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Wpointer-arith -Wvla")
|
||||
endif()
|
||||
|
||||
if(CMAKE_C_COMPILER_ID MATCHES "MSVC")
|
||||
# Turn off some warnings that I've just found too noisy.
|
||||
#
|
||||
# - 4244, 4267: "possible loss of data" when narrowing an integer
|
||||
# type (separate warning numbers for initialisers and
|
||||
# assignments). Every time I spot-check instances of this, they
|
||||
# turn out to be sensible (e.g. something was already checked, or
|
||||
# was assigned from a previous variable that must have been in
|
||||
# range). I don't think putting a warning-suppression idiom at
|
||||
# every one of these sites would improve code legibility.
|
||||
#
|
||||
# - 4018: "signed/unsigned mismatch" in integer comparison. Again,
|
||||
# comes up a lot, and generally my spot checks make it look as if
|
||||
# it's OK.
|
||||
#
|
||||
# - 4235: applying unary '-' to an unsigned type. We do that all
|
||||
# the time in deliberate bit-twiddling code like mpint.c or
|
||||
# crypto implementations.
|
||||
#
|
||||
# - 4293: warning about undefined behaviour if a shift count is too
|
||||
# big. We often do this inside a ?: clause which doesn't evaluate
|
||||
# the overlong shift unless the shift count _isn't_ too big. When
|
||||
# the shift count is constant, MSVC spots the potential problem
|
||||
# in one branch of the ?:, but doesn't also spot that that branch
|
||||
# isn't ever taken, so it complains about a thing that's already
|
||||
# guarded.
|
||||
#
|
||||
# - 4090: different 'const' qualifiers. It's a shame to suppress
|
||||
# this one, because const mismatches really are a thing I'd
|
||||
# normally like to be warned about. But MSVC (as of 2017 at
|
||||
# least) seems to have a bug in which assigning a 'void *' into a
|
||||
# 'const char **' thinks there's a const-qualifier mismatch.
|
||||
# There isn't! Both are pointers to modifiable objects. The fact
|
||||
# that in one case, the modifiable object is a pointer to
|
||||
# something _else_ const should make no difference.
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} \
|
||||
/wd4244 /wd4267 /wd4018 /wd4146 /wd4293 /wd4090")
|
||||
endif()
|
||||
|
||||
if(CMAKE_C_COMPILER_FRONTEND_VARIANT MATCHES "MSVC")
|
||||
set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} /dynamicbase /nxcompat")
|
||||
endif()
|
||||
|
||||
set(platform_libraries
|
||||
advapi32.lib comdlg32.lib gdi32.lib imm32.lib
|
||||
ole32.lib shell32.lib user32.lib ws2_32.lib kernel32.lib)
|
||||
|
||||
# Generate link maps
|
||||
if(PUTTY_LINK_MAPS)
|
||||
if(CMAKE_C_COMPILER_ID MATCHES "Clang" AND
|
||||
"x${CMAKE_C_COMPILER_FRONTEND_VARIANT}" STREQUAL "xMSVC")
|
||||
set(CMAKE_C_LINK_EXECUTABLE
|
||||
"${CMAKE_C_LINK_EXECUTABLE} /lldmap:<TARGET>.map")
|
||||
elseif(CMAKE_C_COMPILER_ID MATCHES "MSVC")
|
||||
set(CMAKE_C_LINK_EXECUTABLE
|
||||
"${CMAKE_C_LINK_EXECUTABLE} /map:<TARGET>.map")
|
||||
else()
|
||||
message(WARNING
|
||||
"Don't know how to generate link maps on this toolchain")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Write out a file in the cmake output directory listing the
|
||||
# executables that are 'official' enough to want to code-sign and
|
||||
# ship.
|
||||
file(WRITE ${CMAKE_BINARY_DIR}/shipped.txt "")
|
||||
function(installed_program target)
|
||||
file(APPEND ${CMAKE_BINARY_DIR}/shipped.txt
|
||||
"${target}${CMAKE_EXECUTABLE_SUFFIX}\n")
|
||||
endfunction()
|
78
cmake/setup.cmake
Normal file
78
cmake/setup.cmake
Normal file
@ -0,0 +1,78 @@
|
||||
# Forcibly re-enable assertions, even if we're building in release
|
||||
# mode. This is a security project - assertions may be enforcing
|
||||
# security-critical constraints. A backstop #ifdef in defs.h should
|
||||
# give a #error if this manoeuvre doesn't do what it needs to.
|
||||
string(REPLACE "/DNDEBUG" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
|
||||
string(REPLACE "-DNDEBUG" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
|
||||
|
||||
set(PUTTY_IPV6 ON
|
||||
CACHE BOOL "Build PuTTY with IPv6 support if possible")
|
||||
set(PUTTY_DEBUG OFF
|
||||
CACHE BOOL "Build PuTTY with debug() statements enabled")
|
||||
set(PUTTY_FUZZING OFF
|
||||
CACHE BOOL "Build PuTTY binaries suitable for fuzzing, NOT FOR REAL USE")
|
||||
|
||||
set(STRICT OFF
|
||||
CACHE BOOL "Enable extra compiler warnings and make them errors")
|
||||
|
||||
include(FindGit)
|
||||
|
||||
set(GENERATED_SOURCES_DIR ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY})
|
||||
|
||||
set(GENERATED_LICENCE_H ${GENERATED_SOURCES_DIR}/licence.h)
|
||||
set(INTERMEDIATE_LICENCE_H ${GENERATED_LICENCE_H}.tmp)
|
||||
add_custom_command(OUTPUT ${INTERMEDIATE_LICENCE_H}
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
-DLICENCE_FILE=${CMAKE_SOURCE_DIR}/LICENCE
|
||||
-DOUTPUT_FILE=${INTERMEDIATE_LICENCE_H}
|
||||
-P ${CMAKE_SOURCE_DIR}/cmake/licence.cmake
|
||||
DEPENDS ${CMAKE_SOURCE_DIR}/cmake/licence.cmake ${CMAKE_SOURCE_DIR}/LICENCE)
|
||||
add_custom_target(generated_licence_h
|
||||
BYPRODUCTS ${GENERATED_LICENCE_H}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
${INTERMEDIATE_LICENCE_H} ${GENERATED_LICENCE_H}
|
||||
DEPENDS ${INTERMEDIATE_LICENCE_H}
|
||||
COMMENT "Updating licence.h")
|
||||
|
||||
set(GENERATED_COMMIT_C ${GENERATED_SOURCES_DIR}/cmake_commit.c)
|
||||
set(INTERMEDIATE_COMMIT_C ${GENERATED_COMMIT_C}.tmp)
|
||||
add_custom_target(check_git_commit
|
||||
BYPRODUCTS ${INTERMEDIATE_COMMIT_C}
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
-DGIT_EXECUTABLE=${GIT_EXECUTABLE}
|
||||
-DTOPLEVEL_SOURCE_DIR=${CMAKE_SOURCE_DIR}
|
||||
-DOUTPUT_FILE=${INTERMEDIATE_COMMIT_C}
|
||||
-P ${CMAKE_SOURCE_DIR}/cmake/gitcommit.cmake
|
||||
DEPENDS ${CMAKE_SOURCE_DIR}/cmake/gitcommit.cmake
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
COMMENT "Checking current git commit")
|
||||
add_custom_target(cmake_commit_c
|
||||
BYPRODUCTS ${GENERATED_COMMIT_C}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
${INTERMEDIATE_COMMIT_C} ${GENERATED_COMMIT_C}
|
||||
DEPENDS check_git_commit ${INTERMEDIATE_COMMIT_C}
|
||||
COMMENT "Updating cmake_commit.c")
|
||||
|
||||
function(add_platform_sources_to_library target)
|
||||
set(sources ${ARGN})
|
||||
list(TRANSFORM sources PREPEND ${CMAKE_CURRENT_SOURCE_DIR}/)
|
||||
target_sources(${target} PRIVATE ${sources})
|
||||
endfunction()
|
||||
|
||||
if(CMAKE_SYSTEM_NAME MATCHES "Windows" OR WINELIB)
|
||||
include(cmake/platforms/windows.cmake)
|
||||
else()
|
||||
include(cmake/platforms/unix.cmake)
|
||||
endif()
|
||||
|
||||
include_directories(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${GENERATED_SOURCES_DIR}
|
||||
${PLATFORM_SUBDIRS})
|
||||
|
||||
if(PUTTY_DEBUG)
|
||||
add_compile_definitions(DEBUG)
|
||||
endif()
|
||||
if(PUTTY_FUZZING)
|
||||
add_compile_definitions(FUZZING)
|
||||
endif()
|
10
cmake/toolchain-mingw.cmake
Normal file
10
cmake/toolchain-mingw.cmake
Normal file
@ -0,0 +1,10 @@
|
||||
# Simple toolchain file for cross-building Windows PuTTY on Linux
|
||||
# using MinGW (tested on Ubuntu).
|
||||
|
||||
set(CMAKE_SYSTEM_NAME Windows)
|
||||
set(CMAKE_SYSTEM_PROCESSOR x86_64)
|
||||
|
||||
set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc)
|
||||
set(CMAKE_RC_COMPILER x86_64-w64-mingw32-windres)
|
||||
set(CMAKE_AR x86_64-w64-mingw32-ar)
|
||||
set(CMAKE_RANLIB x86_64-w64-mingw32-ranlib)
|
33
cmake/toolchain-winegcc.cmake
Normal file
33
cmake/toolchain-winegcc.cmake
Normal file
@ -0,0 +1,33 @@
|
||||
# Toolchain file for cross-building a Winelib version of Windows PuTTY
|
||||
# on Linux, using winegcc (tested on Ubuntu).
|
||||
|
||||
# Winelib is weird because it's basically compiling ordinary Linux
|
||||
# objects and executables, but we want to pretend to be Windows for
|
||||
# purposes of (a) having resource files, and (b) selecting the Windows
|
||||
# platform subdirectory.
|
||||
#
|
||||
# So, do we tag this as a weird kind of Windows build, or a weird kind
|
||||
# of Linux build? Either way we have to do _something_ out of the
|
||||
# ordinary.
|
||||
#
|
||||
# After some experimentation, it seems to make more sense to treat
|
||||
# Winelib builds as basically Linux, and set a flag WINELIB that
|
||||
# PuTTY's main build scripts will detect and handle specially.
|
||||
# Specifically, that flag will cause cmake/setup.cmake to select the
|
||||
# Windows platform (overriding the usual check of CMAKE_SYSTEM_NAME),
|
||||
# and also trigger a call to enable_language(RC), which for some kind
|
||||
# of cmake re-entrancy reason we can't do in this toolchain file
|
||||
# itself.
|
||||
set(CMAKE_SYSTEM_NAME Linux)
|
||||
set(WINELIB ON)
|
||||
|
||||
# We need a wrapper script around winegcc proper, because cmake's link
|
||||
# command lines will refer to system libraries as "-lkernel32.lib"
|
||||
# rather than the required "-lkernel32". The winegcc script alongside
|
||||
# this toolchain file bodges that command-line translation.
|
||||
set(CMAKE_C_COMPILER ${CMAKE_SOURCE_DIR}/cmake/winegcc)
|
||||
|
||||
set(CMAKE_RC_COMPILER wrc)
|
||||
set(CMAKE_RC_OUTPUT_EXTENSION .res.o)
|
||||
set(CMAKE_RC_COMPILE_OBJECT
|
||||
"<CMAKE_RC_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> <SOURCE>")
|
29
cmake/winegcc
Executable file
29
cmake/winegcc
Executable file
@ -0,0 +1,29 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Wrapper for winegcc that allows it to be used in a build generated
|
||||
# from PuTTY's CMakeLists.txt, by bodging around the command-line
|
||||
# options that CMake gets wrong.
|
||||
|
||||
init=true
|
||||
for arg in init "$@"; do
|
||||
if $init; then
|
||||
set --
|
||||
init=false
|
||||
continue
|
||||
fi
|
||||
|
||||
case "$arg" in
|
||||
# The Windows build definition for PuTTY specifies all the
|
||||
# system API libraries by names like kernel32.lib. When CMake
|
||||
# reads that file and thinks it's compiling for Linux, it will
|
||||
# generate link options such as -lkernel32.lib. But in fact
|
||||
# winegcc expects -lkernel32, so we need to strip the ".lib"
|
||||
# suffix.
|
||||
-l*.lib) set -- "$@" "${arg%.lib}";;
|
||||
|
||||
# Anything else, we leave unchanged.
|
||||
*) set -- "$@" "$arg";;
|
||||
esac
|
||||
done
|
||||
|
||||
exec winegcc "$@"
|
Reference in New Issue
Block a user