1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 17:38:00 +00:00

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 $<TARGET_OBJECTS:foo>
   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.
This commit is contained in:
Simon Tatham 2021-10-29 18:08:18 +01:00
parent e24444dba8
commit 5eee8ca648
6 changed files with 26 additions and 11 deletions

View File

@ -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
--------------------------------

View File

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.12)
cmake_minimum_required(VERSION 3.7)
project(putty LANGUAGES C)
include(cmake/setup.cmake)

View File

@ -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()

View File

@ -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)

View File

@ -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

View File

@ -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_OBJECTS:puttygen-common>)
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_OBJECTS:puttygen-common>)
target_link_libraries(cgtest keygen console crypto utils)
add_executable(testsc
${CMAKE_SOURCE_DIR}/testsc.c)