Created
January 1, 2018 14:22
-
-
Save mdaniel/219e78903e8d08cedeaff793b897b7aa to your computer and use it in GitHub Desktop.
CMake descriptor for PuTTY so CLion can work with it; It's not perfect, but it builds working executables, so there's that
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CMAKE_MINIMUM_REQUIRED(VERSION 3.9.0) | |
CMAKE_POLICY(VERSION 3.9) | |
SET(PUTTY_VERSION "0.70.20180101") | |
PROJECT(putty VERSION ${PUTTY_VERSION} LANGUAGES C) | |
FIND_PROGRAM(PERL_EXE | |
NAMES perl perl.exe | |
DOC "location of an executable Perl used to generate files within the project") | |
OPTION(NO_IPV6 [=[ | |
Disables PuTTY's ability to make IPv6 connections, enabling | |
it to compile under development environments which do not | |
support IPv6 in their header files. | |
]=]) | |
FUNCTION(RECIPE) | |
LIST(GET ARGV 0 RECIPE_NAME) | |
LIST(REMOVE_AT ARGV 0) | |
LIST(GET ARGV 0 RECIPE_KIND) | |
LIST(REMOVE_AT ARGV 0) | |
IF(${RECIPE_KIND} STREQUAL "=") | |
# it's a simple sources decl, no action required | |
ELSEIF(${RECIPE_KIND} STREQUAL ":") | |
LIST(GET ARGV 0 MAYBE_SUBSYS) | |
IF(NOT (${MAYBE_SUBSYS} MATCHES "\\[[A-Z]\\]")) | |
MESSAGE(FATAL_ERROR "What kind of subsystem is ${MAYBE_SUBSYS}") | |
ENDIF() | |
# but we don't do anything with them right now | |
LIST(REMOVE_AT ARGV 0) | |
ELSE() | |
MESSAGE(FATAL_ERROR "Unrecognized Recipe verb: [=[${RECIPE_KIND}]=]") | |
ENDIF() | |
# because "Recipe" pathnames are not qualified (!!!) | |
# this is the filename search path | |
SET(maybe_dir_prefixes "" "charset/" "unix/" "windows/") | |
FOREACH(a IN LISTS ARGV) | |
IF(${a} STREQUAL "+") # eat the line continuation junk | |
CONTINUE() | |
ELSEIF(${a} STREQUAL "LIBS") | |
# it's implied, since he uses it in every WIN32 [G] or [C] target | |
CONTINUE() | |
ELSEIF (${a} MATCHES "^[A-Z][A-Z_]+\$") | |
# reference to other group | |
SET(RECIPE_SOURCES ${RECIPE_SOURCES} ${${a}_SOURCES}) | |
ELSEIF(${a} MATCHES "[a-z][/a-z0-9_]+") | |
# for some godforsaken reason, he specified .res for the .rc | |
# it seems to be the only suffix included :rage4: | |
IF(${a} MATCHES "(.*)\\.res$") | |
# windows .rc files only live in windows/ so skip the pretense otherwise | |
SET(RECIPE_SOURCES ${RECIPE_SOURCES} "windows/${CMAKE_MATCH_1}.rc") | |
SET_PROPERTY( | |
SOURCE "windows/${CMAKE_MATCH_1}.rc" | |
APPEND | |
PROPERTY OBJECT_DEPENDS "${CMAKE_SOURCE_DIR}/licence.h" | |
) | |
CONTINUE() | |
ENDIF() | |
FOREACH(d IN LISTS maybe_dir_prefixes) | |
SET(ac "${d}${a}.c") | |
SET(ah "${d}${a}.h") | |
SET(found FALSE) | |
# pathname must be fully-qualified to EXISTS | |
# but may be relative for _SOURCES | |
IF(EXISTS "${CMAKE_SOURCE_DIR}/${ac}") | |
SET(RECIPE_SOURCES ${RECIPE_SOURCES} "${ac}") | |
SET(found TRUE) | |
ENDIF() | |
IF(EXISTS "${CMAKE_SOURCE_DIR}/${ah}") | |
SET(RECIPE_SOURCES ${RECIPE_SOURCES} "${ah}") | |
SET(found TRUE) | |
ENDIF() | |
IF(${found}) | |
BREAK() | |
ENDIF() | |
ENDFOREACH() | |
ELSE() | |
MESSAGE(FATAL_ERROR "unrecognized input to RECIPE(): ${a}") | |
ENDIF() | |
ENDFOREACH() | |
SET("${RECIPE_NAME}_SOURCES" ${RECIPE_SOURCES} | |
PARENT_SCOPE) | |
IF(CMAKE_VERBOSE_MAKEFILE) | |
MESSAGE(STATUS "Created \$${RECIPE_NAME}_SOURCES containing ${RECIPE_SOURCES}") | |
ENDIF() | |
IF(${RECIPE_KIND} STREQUAL ":") | |
IF(${MAYBE_SUBSYS} STREQUAL "[G]") | |
SET(RECIPE_LIBS ${LIBS}) | |
ADD_EXECUTABLE(${RECIPE_NAME} WIN32 ${RECIPE_SOURCES}) | |
ELSEIF(${MAYBE_SUBSYS} STREQUAL "[C]") | |
SET(RECIPE_LIBS ${LIBS}) | |
LIST(REMOVE_ITEM RECIPE_LIBS "gdi32") | |
ADD_EXECUTABLE(${RECIPE_NAME} ${RECIPE_SOURCES}) | |
ENDIF() | |
TARGET_LINK_LIBRARIES(${RECIPE_NAME} PRIVATE ${RECIPE_LIBS}) | |
SET(TARGET_NAME_LIST ${TARGET_NAME_LIST} ${RECIPE_NAME} | |
PARENT_SCOPE) | |
ENDIF() | |
ENDFUNCTION(RECIPE) | |
ADD_CUSTOM_COMMAND( | |
OUTPUT "${CMAKE_SOURCE_DIR}/licence.h" | |
COMMAND ${PERL_EXE} licence.pl | |
COMMENT "generating licence.h from LICENCE" | |
DEPENDS "${CMAKE_SOURCE_DIR}/LICENCE" | |
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" | |
) | |
SET_PROPERTY( | |
SOURCE "${CMAKE_SOURCE_DIR}/windows/windlg.c" | |
APPEND | |
PROPERTY OBJECT_DEPENDS "${CMAKE_SOURCE_DIR}/licence.h" | |
) | |
ADD_CUSTOM_COMMAND( | |
OUTPUT "${CMAKE_SOURCE_DIR}/charset/sbcsdat.c" | |
COMMAND ${PERL_EXE} "sbcsgen.pl" | |
COMMENT "generating sbcsdat.c from charset/sbcs.dat" | |
DEPENDS "${CMAKE_SOURCE_DIR}/charset/sbcs.dat" | |
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/charset" | |
) | |
FILE(WRITE empty.h "/* Empty file touched by automake makefile to force rebuild of version.o */") | |
# Standard libraries. | |
# needs to come first, and needs TLC because cmake doesn't want the ".lib" suffix | |
SET(LIBS advapi32 user32 gdi32 comdlg32 shell32 imm32 ole32) | |
# ------------------------------------------------------------ | |
# Definitions of object groups. A group name, followed by an =, | |
# followed by any number of objects or other already-defined group | |
# names. A line beginning `+' is assumed to continue the previous | |
# line. | |
# Terminal emulator and its (platform-independent) dependencies. | |
RECIPE(TERMINAL = terminal wcwidth ldiscucs logging tree234 minibidi | |
+ config dialog conf | |
) | |
# GUI front end and terminal emulator (putty, puttytel). | |
RECIPE(GUITERM = TERMINAL window windlg winctrls sizetip winprint winutils | |
+ wincfg sercfg winhelp winjump sessprep | |
) | |
# Same thing on Unix. | |
RECIPE(UXTERM = TERMINAL uxcfg sercfg uxucs uxprint timing callback miscucs | |
) | |
RECIPE(GTKTERM = UXTERM gtkwin gtkcfg gtkdlg gtkfont gtkcols gtkmisc xkeysym | |
+ x11misc gtkcomm sessprep | |
) | |
RECIPE(GTKMAIN = gtkmain cmdline | |
) | |
# Non-SSH back ends (putty, puttytel, plink). | |
RECIPE(NONSSH = telnet raw rlogin ldisc pinger | |
) | |
# SSH back end (putty, plink, pscp, psftp). | |
RECIPE(SSH = ssh sshcrc sshdes sshmd5 sshrsa sshrand sshsha sshblowf | |
+ sshdh sshcrcda sshpubk sshzlib sshdss x11fwd portfwd | |
+ sshaes sshccp sshsh256 sshsh512 sshbn wildcard pinger ssharcf | |
+ sshgssc pgssapi sshshare sshecc aqsync | |
) | |
RECIPE(WINSSH = SSH winnoise wincapi winpgntc wingss winshare winnps winnpc | |
+ winhsock errsock | |
) | |
RECIPE(UXSSH = SSH uxnoise uxagentc uxgss uxshare | |
) | |
# SFTP implementation (pscp, psftp). | |
RECIPE(SFTP = sftp int64 logging cmdline | |
) | |
# Miscellaneous objects appearing in all the network utilities (not | |
# Pageant or PuTTYgen). | |
RECIPE(MISC = timing callback misc version settings tree234 proxy conf be_misc | |
) | |
RECIPE(WINMISC = MISC winstore winnet winhandl cmdline windefs winmisc winproxy | |
+ wintime winhsock errsock winsecur winucs miscucs | |
) | |
RECIPE(UXMISC = MISC uxstore uxsel uxnet uxpeer uxmisc uxproxy time | |
) | |
# import.c and dependencies, for PuTTYgen-like utilities that have to | |
# load foreign key files. | |
RECIPE(IMPORT = import sshbcrypt sshblowf | |
) | |
# Character set library, for use in pterm. | |
RECIPE(CHARSET = sbcsdat slookup sbcs utf8 toucs fromucs xenc mimeenc macenc localenc | |
) | |
# Network backend sets. This also brings in the relevant attachment | |
# to proxy.c depending on whether we're crypto-avoidant or not. | |
RECIPE(BE_ALL = be_all cproxy | |
) | |
RECIPE(BE_NOSSH = be_nossh nocproxy | |
) | |
RECIPE(BE_SSH = be_ssh cproxy | |
) | |
RECIPE(BE_NONE = be_none nocproxy | |
) | |
# More backend sets, with the additional Windows serial-port module. | |
RECIPE(W_BE_ALL = be_all_s winser cproxy | |
) | |
RECIPE(W_BE_NOSSH = be_nos_s winser nocproxy | |
) | |
# And with the Unix serial-port module. | |
RECIPE(U_BE_ALL = be_all_s uxser cproxy | |
) | |
RECIPE(U_BE_NOSSH = be_nos_s uxser nocproxy | |
# ------------------------------------------------------------ | |
# Definitions of actual programs. The program name, followed by a | |
# colon, followed by a list of objects. Also in the list may be the | |
# keywords [G] for Windows GUI app, [C] for Console app, [X] for | |
# X/GTK Unix app, [U] for command-line Unix app. | |
) | |
RECIPE(putty : [G] GUITERM NONSSH WINSSH W_BE_ALL WINMISC winx11 putty.res LIBS | |
) | |
RECIPE(puttytel : [G] GUITERM NONSSH W_BE_NOSSH WINMISC puttytel.res nogss LIBS | |
) | |
RECIPE(plink : [C] winplink wincons NONSSH WINSSH W_BE_ALL logging WINMISC | |
+ winx11 plink.res winnojmp sessprep noterm LIBS | |
) | |
RECIPE(pscp : [C] pscp winsftp wincons WINSSH BE_SSH SFTP wildcard WINMISC | |
+ pscp.res winnojmp LIBS | |
) | |
RECIPE(psftp : [C] psftp winsftp wincons WINSSH BE_SSH SFTP wildcard WINMISC | |
+ psftp.res winnojmp LIBS | |
) | |
RECIPE(pageant : [G] winpgnt pageant sshrsa sshpubk sshdes sshbn sshmd5 version | |
+ tree234 misc sshaes sshsha winsecur winpgntc aqsync sshdss sshsh256 | |
+ sshsh512 winutils sshecc winmisc winhelp conf pageant.res LIBS | |
) | |
RECIPE(puttygen : [G] winpgen sshrsag sshdssg sshprime sshdes sshbn sshmd5 version | |
+ sshrand winnoise sshsha winstore misc winctrls sshrsa sshdss winmisc | |
+ sshpubk sshaes sshsh256 sshsh512 IMPORT winutils puttygen.res | |
+ tree234 notiming winhelp winnojmp conf LIBS wintime sshecc | |
+ sshecdsag winsecur | |
) | |
IF(CMAKE_VERBOSE_MAKEFILE) | |
MESSAGE(STATUS "defined ${TARGET_NAME_LIST} targets") | |
ENDIF() | |
IF(WIN32) | |
FOREACH(tgt IN LISTS TARGET_NAME_LIST) | |
TARGET_COMPILE_DEFINITIONS(${tgt} PRIVATE | |
-DNO_IPV6 | |
-DNO_GSSAPI | |
-D_WINDOWS) | |
TARGET_INCLUDE_DIRECTORIES(${tgt} BEFORE PRIVATE | |
"${CMAKE_SOURCE_DIR}" | |
"${CMAKE_SOURCE_DIR}/windows") | |
ENDFOREACH() | |
ENDIF() | |
IF(MINGW) | |
FOREACH(tgt IN LISTS TARGET_NAME_LIST) | |
TARGET_COMPILE_DEFINITIONS(${tgt} PRIVATE | |
"-DSOURCE_COMMIT=\"5f7604888bcd5a2a96392874b947f4a74056d303\"" | |
-D_WIN32_IE=0x0500 -DWINVER=0x0500 -D_WIN32_WINDOWS=0x0410 -D_WIN32_WINNT=0x0500) | |
ENDFOREACH() | |
ENDIF() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the script. could you help me with an issue I have??? I cannot build with your script. I get errors after 100%.
My basic issue is, that I need a test vector for the putty file loading. I am 0% c or c++... So I don't know how I get to create one.
Could you debug a password encrypted ppk file load and send me the data I need?? Would be awesome!!!!
my build output is: