Skip to content
This repository was archived by the owner on Mar 22, 2023. It is now read-only.

Commit 205c536

Browse files
cmake: handle cxx compiler's flags properly in check_compiling_issues
and cleanup other, locally set variables after use.
1 parent 069db3a commit 205c536

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

cmake/check_compiling_issues.cmake

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66
# Original CMake flags and includes are saved to be restored at the end of the file.
77
# This way project's original settings are not modified by the process of these checks.
88
set(SAVED_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
9+
set(SAVED_CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
910
set(SAVED_CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES})
1011

12+
set(CMAKE_CXX_FLAGS "")
13+
1114
if(NOT MSVC_VERSION)
1215

1316
# Even if we are ensuring that we use CMAKE_CXX_STANDARD >= 14, check if
@@ -56,6 +59,7 @@ if(NOT MSVC_VERSION)
5659

5760
# Check for issues with older gcc compilers if "inline" aggregate initialization
5861
# works for array class members https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65815
62+
set(CMAKE_REQUIRED_FLAGS "")
5963
CHECK_CXX_SOURCE_COMPILES(
6064
"struct array {
6165
int data[2];
@@ -98,6 +102,7 @@ if(NOT MSVC_VERSION)
98102
return 0;
99103
}"
100104
NO_CLANG_TEMPLATE_BUG)
105+
set(CMAKE_REQUIRED_INCLUDES "") # clean includes after check
101106

102107
# This is a workaround for older incompatible versions of libstdc++ and clang.
103108
# Please see https://llvm.org/bugs/show_bug.cgi?id=15517 for more info.
@@ -142,5 +147,6 @@ CHECK_CXX_SOURCE_COMPILES(
142147
)
143148

144149
# Restore original, project's settings
145-
set(CMAKE_REQUIRED_INCLUDES ${SAVED_CMAKE_REQUIRED_INCLUDES})
146150
set(CMAKE_REQUIRED_FLAGS ${SAVED_CMAKE_REQUIRED_FLAGS})
151+
set(CMAKE_CXX_FLAGS ${SAVED_CMAKE_CXX_FLAGS})
152+
set(CMAKE_REQUIRED_INCLUDES ${SAVED_CMAKE_REQUIRED_INCLUDES})

0 commit comments

Comments
 (0)