File tree Expand file tree Collapse file tree 2 files changed +11
-8
lines changed Expand file tree Collapse file tree 2 files changed +11
-8
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,10 @@ if(POLICY CMP0171)
19
19
cmake_policy (SET CMP0171 NEW )
20
20
endif ()
21
21
22
+ # When adjusting CMake flag variables, we must not override those explicitly
23
+ # set by the user. These are a subset of the CACHE_VARIABLES property.
24
+ get_directory_property (precious_variables CACHE_VARIABLES )
25
+
22
26
#=============================
23
27
# Project / Package metadata
24
28
#=============================
Original file line number Diff line number Diff line change @@ -105,14 +105,13 @@ function(remove_cxx_flag_from_all_configs flag)
105
105
endfunction ()
106
106
107
107
function (replace_cxx_flag_in_config config old_flag new_flag )
108
- string (TOUPPER "${config} " config_uppercase )
109
- string (REGEX REPLACE "(^| )${old_flag} ( |$)" "\\ 1${new_flag} \\ 2" new_flags "${CMAKE_CXX_FLAGS_${config_uppercase} }" )
110
- set (CMAKE_CXX_FLAGS_${config_uppercase} "${new_flags} " PARENT_SCOPE )
111
- set (CMAKE_CXX_FLAGS_${config_uppercase} "${new_flags} "
112
- CACHE STRING
113
- "Flags used by the CXX compiler during ${config_uppercase} builds."
114
- FORCE
115
- )
108
+ string (TOUPPER "CMAKE_CXX_FLAGS_${config} " var_name )
109
+ if ("${var_name} " IN_LIST precious_variables )
110
+ return ()
111
+ endif ()
112
+ string (REGEX REPLACE "(^| )${old_flag} ( |$)" "\\ 1${new_flag} \\ 2" ${var_name} "${${var_name} }" )
113
+ set (${var_name} "${${var_name} }" PARENT_SCOPE )
114
+ set_property (CACHE ${var_name} PROPERTY VALUE "${${var_name} }" )
116
115
endfunction ()
117
116
118
117
set_default_config (RelWithDebInfo )
You can’t perform that action at this time.
0 commit comments