blob: c2fe376cc20bdddf0f7751f9b43f20961bb51d03 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
##
# This module extracts CMake cached variables into a variable.
#
# Author: snukky
#
# This module sets the following variables:
# * PROJECT_CMAKE_CACHE - to the output of "cmake -L" - an uncached list of
# non-advanced cached variables
# * PROJECT_CMAKE_CACHE_ADVANCED - to the output of "cmake -LA" - an uncached
# list of advanced cached variables
#
set(PROJECT_CMAKE_CACHE "")
set(PROJECT_CMAKE_CACHE_ADVANCED "")
# Get all CMake variables
get_cmake_property(_variableNames VARIABLES)
list(SORT _variableNames)
list(REMOVE_DUPLICATES _variableNames)
foreach(_variableName ${_variableNames})
# If it is a cache variable
get_property(_cachePropIsSet CACHE "${_variableName}" PROPERTY VALUE SET)
if(_cachePropIsSet)
# Get the variable's type
get_property(_variableType CACHE ${_variableName} PROPERTY TYPE)
# Get the variable's value
set(_variableValue "${${_variableName}}")
# Skip static or internal cached variables, cmake -L[A] does not print them, see
# https://github.com/Kitware/CMake/blob/master/Source/cmakemain.cxx#L282
if( (NOT "${_variableType}" STREQUAL "STATIC") AND
(NOT "${_variableType}" STREQUAL "INTERNAL") AND
(NOT "${_variableValue}" STREQUAL "") )
string(REPLACE "\"" " " _variableValueEscapedQuotes ${_variableValue})
string(REPLACE "\\" "/" _variableValueEscaped ${_variableValueEscapedQuotes})
set(PROJECT_CMAKE_CACHE_ADVANCED "${PROJECT_CMAKE_CACHE_ADVANCED} \"${_variableName}=${_variableValueEscaped}\\n\"\n")
# Get the variable's advanced flag
get_property(_isAdvanced CACHE ${_variableName} PROPERTY ADVANCED SET)
if(NOT _isAdvanced)
set(PROJECT_CMAKE_CACHE "${PROJECT_CMAKE_CACHE} \"${_variableName}=${_variableValueEscaped}\\n\"\n")
endif()
# Print variables for debugging
#message(STATUS "${_variableName}=${_variableValueEscaped}")
#message(STATUS " Type=${_variableType}")
#message(STATUS " Advanced=${_isAdvanced}")
endif()
endif(_cachePropIsSet)
endforeach()
|