Skip to content

Commit

Permalink
Persist CMake variables used during multiple builds in cache
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
leonlynch committed Dec 24, 2023
1 parent f12f4a0 commit a969145
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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()
Expand Down

0 comments on commit a969145

Please sign in to comment.