Skip to content

Commit

Permalink
Fix compiler flags check error (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
Saigut committed Aug 8, 2023
1 parent ed87892 commit dc77211
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,24 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
endif()
foreach(FLAG ${FLAGS})
string(REGEX REPLACE "[-=+]" "_" F ${FLAG})
check_c_compiler_flag(${FLAG} ${F})
if(${F})
set(C_F C_${F})
set(CXX_F CXX_${F})
check_c_compiler_flag(${FLAG} ${C_F})
if(${C_F})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLAG}")
endif()
check_cxx_compiler_flag(${FLAG} ${F})
if(${F})
check_cxx_compiler_flag(${FLAG} ${CXX_F})
if(${CXX_F})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAG}")
endif()
endforeach()

# Set CXX flags
foreach(FLAG -Wno-c++98-compat -Wno-global-constructors)
string(REGEX REPLACE "[-=+]" "_" F ${FLAG})
check_cxx_compiler_flag(${FLAG} ${F})
if(${F})
set(CXX_F CXX_${F})
check_cxx_compiler_flag(${FLAG} ${CXX_F})
if(${CXX_F})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAG}")
endif()
endforeach()
Expand Down Expand Up @@ -128,8 +131,8 @@ if(CMAKE_BUILD_TYPE MATCHES Debug)
HAVE_ASAN_ADDRESS_IS_POISONED)
cmake_reset_check_state()
set(CMAKE_REQUIRED_FLAGS -fsanitize=address,undefined,leak)
check_c_compiler_flag("" _fsanitize_address_undefined_leak)
if(_fsanitize_address_undefined_leak)
check_c_compiler_flag("" C_fsanitize_address_undefined_leak)
if(C_fsanitize_address_undefined_leak)
string(CONCAT CMAKE_C_FLAGS "${CMAKE_C_FLAGS} "
"-fsanitize=address,undefined,leak")
string(CONCAT CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} "
Expand All @@ -148,12 +151,14 @@ if(CMAKE_BUILD_TYPE MATCHES Debug)
)
foreach(FLAG ${FLAGS})
string(REGEX REPLACE "[-=+]" "_" F ${FLAG})
check_c_compiler_flag(${FLAG} ${F})
if(${F})
set(C_F C_${F})
set(CXX_F CXX_${F})
check_c_compiler_flag(${FLAG} ${C_F})
if(${C_F})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLAG}")
endif()
check_cxx_compiler_flag(${FLAG} ${F})
if(${F})
check_cxx_compiler_flag(${FLAG} ${CXX_F})
if(${CXX_F})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAG}")
endif()
endforeach()
Expand Down

0 comments on commit dc77211

Please sign in to comment.