mirror of
https://github.com/Syllo/nvtop.git
synced 2024-03-13 10:04:14 +03:00
cmake: use check_linker_flag for checking linker flags
check_c_compiler_flag does not actually pass the flag to the linker, and so the test file successfully compiles for any linker flag. This caused the -Wl,z,relro flag to be passed to the compiler even if it was not supported. check_c_compiler_flag was introduced in cmake 3.18, so this commit also bumps the minimum required cmake version to 3.18 (released in 2020).
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
cmake_minimum_required(VERSION 3.18)
|
||||
|
||||
#///////////////////////////////////////////////////////////////////#
|
||||
# PROJECT #
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
include(CheckLinkerFlag)
|
||||
|
||||
function(add_compiler_option_to_target_type TARGET BUILDTYPE VISIBILITY OPTIONS)
|
||||
include(CheckCCompilerFlag)
|
||||
list(APPEND OPTIONS ${ARGN})
|
||||
@@ -29,7 +31,7 @@ function(add_linker_option_to_target_type TARGET BUILDTYPE VISIBILITY OPTIONS)
|
||||
list(APPEND OPTIONS ${ARGN})
|
||||
foreach(LINK_OPTION IN LISTS OPTIONS)
|
||||
string(REPLACE "," "_" LINK_OPTION_NAME "${LINK_OPTION}")
|
||||
check_c_compiler_flag(${LINK_OPTION} "linker_has${LINK_OPTION_NAME}")
|
||||
check_linker_flag(C "${LINK_OPTION}" "linker_has${LINK_OPTION_NAME}")
|
||||
if (${linker_has${LINK_OPTION_NAME}})
|
||||
target_link_libraries(${TARGET} ${VISIBILITY}
|
||||
$<$<CONFIG:${BUILDTYPE}>:${LINK_OPTION}>)
|
||||
@@ -42,7 +44,7 @@ function(add_linker_option_to_all_but_target_type TARGET BUILDTYPE VISIBILITY OP
|
||||
list(APPEND OPTIONS ${ARGN})
|
||||
foreach(LINK_OPTION IN LISTS OPTIONS)
|
||||
string(REPLACE "," "_" LINK_OPTION_NAME "${LINK_OPTION}")
|
||||
check_c_compiler_flag(${LINK_OPTION} "linker_has${LINK_OPTION_NAME}")
|
||||
check_linker_flag(C "${LINK_OPTION}" "linker_has${LINK_OPTION_NAME}")
|
||||
if (${linker_has${LINK_OPTION_NAME}})
|
||||
target_link_libraries(${TARGET} ${VISIBILITY}
|
||||
$<$<NOT:$<CONFIG:${BUILDTYPE}>>:${LINK_OPTION}>)
|
||||
|
||||
Reference in New Issue
Block a user