Skip to content

Commit 2bec1af

Browse files
committed
cmake: avoid undefined
1 parent 5e95559 commit 2bec1af

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

cmake/add_compiler_flag_if_supported.cmake

+25-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,15 @@ include(CheckCXXSourceCompiles)
99
include(CMakeCheckCompilerFlagCommonPatterns)
1010

1111
macro (CHECK_CXX_COMPILER_FLAG _FLAG _RESULT)
12-
set(SAFE_CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS}")
12+
## end copy ]]
13+
set(cccf_do_save_crd false)
14+
if(DEFINED CMAKE_REQUIRED_DEFINITIONS)
15+
set(cccf_do_save_crd true)
16+
## begin copy [[
17+
set(SAFE_CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS}")
18+
## end copy ]]
19+
endif()
20+
## begin copy [[
1321
set(CMAKE_REQUIRED_DEFINITIONS "${_FLAG}")
1422
## end copy ]]
1523

@@ -40,7 +48,13 @@ macro (CHECK_CXX_COMPILER_FLAG _FLAG _RESULT)
4048
)
4149
foreach(v ${_CheckCXXCompilerFlag_LOCALE_VARS})
4250
if (DEFINED _CheckCXXCompilerFlag_SAVED_${v})
43-
set(ENV{${v}} ${${_CheckCXXCompilerFlag_SAVED_${v}}})
51+
## end copy ]]
52+
if(DEFINED ${_CheckCXXCompilerFlag_SAVED_${v}})
53+
## begin copy [[
54+
set(ENV{${v}} ${${_CheckCXXCompilerFlag_SAVED_${v}}})
55+
## end copy ]]
56+
endif()
57+
## begin copy [[
4458
unset(_CheckCXXCompilerFlag_SAVED_${v})
4559
else()
4660
unset (ENV{${v}})
@@ -49,7 +63,15 @@ macro (CHECK_CXX_COMPILER_FLAG _FLAG _RESULT)
4963
unset(_CheckCXXCompilerFlag_LOCALE_VARS)
5064
unset(_CheckCXXCompilerFlag_COMMON_PATTERNS)
5165

52-
set (CMAKE_REQUIRED_DEFINITIONS "${SAFE_CMAKE_REQUIRED_DEFINITIONS}")
66+
## end copy ]]
67+
if(cccf_do_save_crd)
68+
## begin copy [[
69+
set (CMAKE_REQUIRED_DEFINITIONS "${SAFE_CMAKE_REQUIRED_DEFINITIONS}")
70+
## end copy ]]
71+
else()
72+
unset(CMAKE_REQUIRED_DEFINITIONS)
73+
endif()
74+
## begin copy [[
5375
endmacro ()
5476
## end copy ]]
5577

0 commit comments

Comments
 (0)