Skip to content

Commit d9c9fb0

Browse files
committed
Test optimization flags only when CMAKE_CXX_FLAGS is set
1 parent 5e69066 commit d9c9fb0

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

cmake/functions/project_flags.cmake

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,17 @@ endmacro()
5050
# @brief Set the default optimization flags in case the user didn't
5151
# explicitly choose it with -DCMAKE_CXX_FLAGS
5252
macro(set_optimization_flags)
53-
set(OPT_FLAGS /O1 /O2 /Ob /Od /Og /Oi /Os /Ot /Ox /Oy /favor -O0 -O1 -O -O2 -O3 -Os -Ofast -Og)
5453
set(OPTIMIZATION_FLAG_IS_SET OFF)
55-
string(REPLACE " " ";" CMAKE_CXX_FLAGS_LIST ${CMAKE_CXX_FLAGS})
56-
foreach(FLAG ${CMAKE_CXX_FLAGS_LIST})
57-
if (${FLAG} IN_LIST OPT_FLAGS)
58-
message("CXX optimization flag is already set to ${FLAG}")
59-
set(OPTIMIZATION_FLAG_IS_SET ON)
60-
endif()
61-
endforeach()
54+
if (CMAKE_CXX_FLAGS)
55+
set(OPT_FLAGS /O1 /O2 /Ob /Od /Og /Oi /Os /Ot /Ox /Oy /favor -O0 -O1 -O -O2 -O3 -Os -Ofast -Og)
56+
string(REPLACE " " ";" CMAKE_CXX_FLAGS_LIST ${CMAKE_CXX_FLAGS})
57+
foreach(FLAG ${CMAKE_CXX_FLAGS_LIST})
58+
if (${FLAG} IN_LIST OPT_FLAGS)
59+
message("CXX optimization flag is already set to ${FLAG}")
60+
set(OPTIMIZATION_FLAG_IS_SET ON)
61+
endif()
62+
endforeach()
63+
endif()
6264

6365
if (NOT OPTIMIZATION_FLAG_IS_SET)
6466
if (CMAKE_BUILD_TYPE STREQUAL "Debug")

0 commit comments

Comments
 (0)