From a96914535b716c175f77663004ef912a7d638585 Mon Sep 17 00:00:00 2001 From: Leon Lynch Date: Sun, 24 Dec 2023 21:36:36 +0100 Subject: [PATCH] Persist CMake variables used during multiple builds in cache When a variable created during configuration is used during multiple builds, and isn't written to a generated header, it should be a cache variable. If it isn't a cache variable, it will be unavailable during subsequent builds that perform partial configuration, which in turn has unintended consequences for those builds. --- src/CMakeLists.txt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 844e2f8..51a9a9c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -64,7 +64,8 @@ if(NOT HAVE_STRPTIME) check_symbol_exists(strptime time.h HAVE_STRPTIME) list(REMOVE_ITEM CMAKE_REQUIRED_DEFINITIONS -D${TIME_H_DEFINITIONS_TRY}) if(HAVE_STRPTIME) - set(TIME_H_DEFINITIONS ${TIME_H_DEFINITIONS_TRY}) + # set as cache entry to persist across multiple builds + set(TIME_H_DEFINITIONS ${TIME_H_DEFINITIONS_TRY} CACHE INTERNAL "Definitions required for time.h") endif() endif() check_symbol_exists(timegm time.h HAVE_TIMEGM) @@ -74,7 +75,8 @@ if(NOT HAVE_TIMEGM) check_symbol_exists(timegm time.h HAVE_TIMEGM) list(REMOVE_ITEM CMAKE_REQUIRED_DEFINITIONS -D${TIME_H_DEFINITIONS_TRY}) if(HAVE_TIMEGM) - set(TIME_H_DEFINITIONS ${TIME_H_DEFINITIONS_TRY}) + # set as cache entry to persist across multiple builds + set(TIME_H_DEFINITIONS ${TIME_H_DEFINITIONS_TRY} CACHE INTERNAL "Definitions required for time.h") endif() endif() if(WIN32) @@ -84,10 +86,12 @@ endif() # conversion. If strptime() is absent, sscanf() will be used instead. if(HAVE_SETLOCALE AND (HAVE_TIMEGM OR HAVE_MKGMTIME)) message(STATUS "Enabling date/time conversion") - set(TR31_ENABLE_DATETIME_CONVERSION ON) + # set as cache entry to persist across multiple builds + set(TR31_ENABLE_DATETIME_CONVERSION ON CACHE INTERNAL "Date/time conversion availability") else() message(STATUS "Disabling date/time conversion; some tests may fail") - set(TR31_ENABLE_DATETIME_CONVERSION OFF) + # set as cache entry to persist across multiple builds + set(TR31_ENABLE_DATETIME_CONVERSION OFF CACHE INTERNAL "Date/time conversion availability") endif() include(GNUInstallDirs) # provides CMAKE_INSTALL_* variables and good defaults for install()