From 4c61a04cd5207f2140b65f955559aa4ffc848e9c Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Thu, 18 Oct 2018 23:16:05 +0300 Subject: [PATCH] Make cmake's check_const_exists() rely on cache --- cmake/CheckConstExists.cmake | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/cmake/CheckConstExists.cmake b/cmake/CheckConstExists.cmake index 56b49882..de074581 100644 --- a/cmake/CheckConstExists.cmake +++ b/cmake/CheckConstExists.cmake @@ -1,23 +1,25 @@ include(CheckCSourceCompiles) macro(check_const_exists CONST FILES VARIABLE) - set(check_const_exists_source "") - foreach(file ${FILES}) + if (NOT DEFINED ${VARIABLE}) + set(check_const_exists_source "") + foreach(file ${FILES}) + set(check_const_exists_source + "${check_const_exists_source} + #include <${file}>") + endforeach() set(check_const_exists_source "${check_const_exists_source} - #include <${file}>") - endforeach() - set(check_const_exists_source - "${check_const_exists_source} - int main() { (void)${CONST}; return 0; }") + int main() { (void)${CONST}; return 0; }") - check_c_source_compiles("${check_const_exists_source}" ${VARIABLE}) + check_c_source_compiles("${check_const_exists_source}" ${VARIABLE}) - if (${${VARIABLE}}) - set(${VARIABLE} 1 CACHE INTERNAL "Have const ${CONST}") - message(STATUS "Looking for ${CONST} - found") - else() - set(${VARIABLE} 0 CACHE INTERNAL "Have const ${CONST}") - message(STATUS "Looking for ${CONST} - not found") + if (${${VARIABLE}}) + set(${VARIABLE} 1 CACHE INTERNAL "Have const ${CONST}") + message(STATUS "Looking for ${CONST} - found") + else() + set(${VARIABLE} 0 CACHE INTERNAL "Have const ${CONST}") + message(STATUS "Looking for ${CONST} - not found") + endif() endif() endmacro(check_const_exists)