Skip to content

Commit 8420502

Browse files
kouterrelln
authored andcommitted
Don't require CMake 3.18 or later
fix #3500 CMake 3.18 or later was required by #3392. Because it uses `CheckLinkerFlag`. But requiring CMake 3.18 or later is a bit aggressive. Because Ubuntu 20.04 LTS still uses CMake 3.16.3: https://packages.ubuntu.com/search?keywords=cmake This change disables `-z noexecstack` check with old CMake. This will not break any existing users. Because users who need `-z noexecstack` must already use CMake 3.18 or later.
1 parent 1c42844 commit 8420502

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

build/cmake/CMakeModules/AddZstdCompilationFlags.cmake

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
include(CheckCXXCompilerFlag)
22
include(CheckCCompilerFlag)
3-
include(CheckLinkerFlag)
3+
# VERSION_GREATER_EQUAL requires CMake 3.7 or later.
4+
# https://cmake.org/cmake/help/latest/command/if.html#version-greater-equal
5+
if (CMAKE_VERSION VERSION_LESS 3.18)
6+
set(ZSTD_HAVE_CHECK_LINKER_FLAG false)
7+
else ()
8+
set(ZSTD_HAVE_CHECK_LINKER_FLAG true)
9+
endif ()
10+
if (ZSTD_HAVE_CHECK_LINKER_FLAG)
11+
include(CheckLinkerFlag)
12+
endif()
413

514
function(EnableCompilerFlag _flag _C _CXX _LD)
615
string(REGEX REPLACE "\\+" "PLUS" varname "${_flag}")
@@ -20,7 +29,15 @@ function(EnableCompilerFlag _flag _C _CXX _LD)
2029
endif ()
2130
endif ()
2231
if (_LD)
23-
CHECK_LINKER_FLAG(C ${_flag} LD_FLAG_${varname})
32+
# We never add a linker flag with CMake < 3.18. We will
33+
# implement CHECK_LINKER_FLAG() like feature for CMake < 3.18
34+
# or require CMake >= 3.18 when we need to add a required
35+
# linker flag in future.
36+
if (ZSTD_HAVE_CHECK_LINKER_FLAG)
37+
CHECK_LINKER_FLAG(C ${_flag} LD_FLAG_${varname})
38+
else ()
39+
set(LD_FLAG_${varname} false)
40+
endif ()
2441
if (LD_FLAG_${varname})
2542
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${_flag}" PARENT_SCOPE)
2643
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${_flag}" PARENT_SCOPE)

0 commit comments

Comments
 (0)