From 5eee8ca648c8453ff5308f7a009277eccfa80d16 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Fri, 29 Oct 2021 18:08:18 +0100 Subject: [PATCH] Compatibility with older versions of cmake. After this change, the cmake setup now works even on Debian stretch (oldoldstable), which runs cmake 3.7. In order to support a version that early I had to: - write a fallback implementation of 'add_compile_definitions' for older cmakes, which is easy, because add_compile_definitions(FOO) is basically just add_compile_options(-DFOO) - stop using list(TRANSFORM) and string(JOIN), of which I had one case each, and they were easily replaced with simple foreach loops - stop putting OBJECT libraries in the target_link_libraries command for executable targets, in favour of adding $ to the main sources list for the same target. That matches what I do with library targets, so it's probably more sensible anyway. I tried going back by another Debian release and getting this cmake setup to work on jessie, but that runs CMake 3.0.1, and in _that_ version of cmake the target_sources command is missing, and I didn't find any alternative way to add extra sources to a target after having first declared it. Reorganising to cope with _that_ omission would be too much upheaval without a very good reason. --- CHECKLST.txt | 3 +++ CMakeLists.txt | 2 +- cmake/setup.cmake | 14 ++++++++++++-- crypto/CMakeLists.txt | 4 +++- doc/CMakeLists.txt | 2 +- unix/CMakeLists.txt | 12 ++++++------ 6 files changed, 26 insertions(+), 11 deletions(-) diff --git a/CHECKLST.txt b/CHECKLST.txt index c3a5365a..82fc9d6a 100644 --- a/CHECKLST.txt +++ b/CHECKLST.txt @@ -37,6 +37,9 @@ Things to do during the branch-stabilisation period: particular, any headline features for the release should get a workout with memory checking enabled! + - Test the CMake build scripts with the oldest CMake they claim to + support, on both Unix and Windows. + Making a release candidate build -------------------------------- diff --git a/CMakeLists.txt b/CMakeLists.txt index 299f04c4..16a0bc96 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.12) +cmake_minimum_required(VERSION 3.7) project(putty LANGUAGES C) include(cmake/setup.cmake) diff --git a/cmake/setup.cmake b/cmake/setup.cmake index c0965c49..6612de97 100644 --- a/cmake/setup.cmake +++ b/cmake/setup.cmake @@ -55,9 +55,19 @@ add_custom_target(cmake_commit_c DEPENDS check_git_commit ${INTERMEDIATE_COMMIT_C} COMMENT "Updating cmake_commit.c") +if(CMAKE_VERSION VERSION_LESS 3.12) + function(add_compile_definitions) + foreach(i ${ARGN}) + add_compile_options(-D${i}) + endforeach() + endfunction() +endif() + function(add_sources_from_current_dir target) - set(sources ${ARGN}) - list(TRANSFORM sources PREPEND ${CMAKE_CURRENT_SOURCE_DIR}/) + set(sources) + foreach(i ${ARGN}) + set(sources ${sources} ${CMAKE_CURRENT_SOURCE_DIR}/${i}) + endforeach() target_sources(${target} PRIVATE ${sources}) endfunction() diff --git a/crypto/CMakeLists.txt b/crypto/CMakeLists.txt index 7d11f444..c6420361 100644 --- a/crypto/CMakeLists.txt +++ b/crypto/CMakeLists.txt @@ -54,7 +54,9 @@ function(test_compile_with_flags outvar) endif() # See if we can compile the provided test program. - string(JOIN " " CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS} ${flags}) + foreach(i ${flags}) + set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${i}") + endforeach() check_c_source_compiles("${OPT_TEST_SOURCE}" "${outvar}") if(${outvar} AND OPT_ADD_SOURCES_IF_SUCCESSFUL) diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt index eb273758..cc90fcdc 100644 --- a/doc/CMakeLists.txt +++ b/doc/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.12) +cmake_minimum_required(VERSION 3.7) project(putty-documentation LANGUAGES) # This build script can be run standalone, or included as a diff --git a/unix/CMakeLists.txt b/unix/CMakeLists.txt index 37ea4337..a2332473 100644 --- a/unix/CMakeLists.txt +++ b/unix/CMakeLists.txt @@ -87,15 +87,15 @@ add_library(puttygen-common OBJECT ${CMAKE_SOURCE_DIR}/sshrand.c) add_executable(puttygen - ${CMAKE_SOURCE_DIR}/cmdgen.c) -target_link_libraries(puttygen - puttygen-common keygen console crypto utils) + ${CMAKE_SOURCE_DIR}/cmdgen.c + $) +target_link_libraries(puttygen keygen console crypto utils) installed_program(puttygen) add_executable(cgtest - ${CMAKE_SOURCE_DIR}/cgtest.c) -target_link_libraries(cgtest - puttygen-common keygen console crypto utils) + ${CMAKE_SOURCE_DIR}/cgtest.c + $) +target_link_libraries(cgtest keygen console crypto utils) add_executable(testsc ${CMAKE_SOURCE_DIR}/testsc.c)