Merge pull request #22 from orbea/clang

cmake: Silence warnings with clang.
This commit is contained in:
Connor McLaughlin 2020-02-13 13:33:00 +09:00 committed by GitHub
commit 9c82096f8f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 7 deletions

View file

@ -81,16 +81,13 @@ endif()
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-Wall" COMPILER_SUPPORTS_WALL)
if(COMPILER_SUPPORTS_WALL)
message("Enabling -Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
endif()
include(CheckCXXFlag)
check_cxx_flag(-Wall COMPILER_SUPPORTS_WALL)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-switch")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-switch")
if(NOT ANDROID)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-class-memaccess -Wno-invalid-offsetof")
check_cxx_flag(-Wno-class-memaccess COMPILER_SUPPORTS_MEMACCESS)
check_cxx_flag(-Wno-invalid-offsetof COMPILER_SUPPORTS_OFFSETOF)
endif()
endif()

View file

@ -0,0 +1,8 @@
include(CheckCXXCompilerFlag)
function(check_cxx_flag flag var)
CHECK_CXX_COMPILER_FLAG("-Werror ${flag}" ${var})
if(${var})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}" PARENT_SCOPE)
endif()
endfunction()