CMake: correctly use if(STREQUAL).

If an operand is a string, it should be quoted to prevent expansion.
This doesn't matter with "GNU", but does with "MSVC" (which expands
to "YES").
pull/33/head
whitequark 2016-07-31 22:51:50 +00:00
parent 14cf0e09df
commit 7f0083aa1d
2 changed files with 8 additions and 8 deletions

View File

@ -31,7 +31,7 @@ if(NOT WIN32 AND NOT APPLE)
set(GUI gtk2 CACHE STRING "GUI toolkit to use (one of: gtk2 gtk3)") set(GUI gtk2 CACHE STRING "GUI toolkit to use (one of: gtk2 gtk3)")
endif() endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL GNU) if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0) if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0)
# GCC 4.8/4.9 ship with broken but present <regex>. meh. # GCC 4.8/4.9 ship with broken but present <regex>. meh.
message(FATAL_ERROR "GCC 5.0+ is required") message(FATAL_ERROR "GCC 5.0+ is required")
@ -54,7 +54,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
endif() endif()
if(SANITIZE) if(SANITIZE)
if(NOT (CMAKE_C_COMPILER_ID STREQUAL Clang AND CMAKE_CXX_COMPILER_ID STREQUAL Clang)) if(NOT (CMAKE_C_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang"))
message(ERROR "Sanitizers are only available in Clang/Clang++") message(ERROR "Sanitizers are only available in Clang/Clang++")
endif() endif()
set(SANITIZE_FLAGS "-O1 -fno-omit-frame-pointer -fno-optimize-sibling-calls") set(SANITIZE_FLAGS "-O1 -fno-omit-frame-pointer -fno-optimize-sibling-calls")
@ -166,9 +166,9 @@ if(MSVC)
set(WARNING_FLAGS "${WARNING_FLAGS} /we4062") set(WARNING_FLAGS "${WARNING_FLAGS} /we4062")
endif() endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL GNU OR CMAKE_CXX_COMPILER_ID STREQUAL Clang) if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(WARNING_FLAGS "-Wall -Wextra -Wno-unused-parameter") set(WARNING_FLAGS "-Wall -Wextra -Wno-unused-parameter")
if(CMAKE_CXX_COMPILER_ID STREQUAL Clang) if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(WARNING_FLAGS "${WARNING_FLAGS} -Wfloat-conversion") set(WARNING_FLAGS "${WARNING_FLAGS} -Wfloat-conversion")
endif() endif()
# We rely on these -Werror flags. # We rely on these -Werror flags.

View File

@ -1,15 +1,15 @@
# Disables all warnings on MSVC and GNU-compatible compilers. # Disables all warnings on MSVC and GNU-compatible compilers.
function(disable_warnings) function(disable_warnings)
if(CMAKE_C_COMPILER_ID STREQUAL GNU OR CMAKE_C_COMPILER_ID STREQUAL Clang) if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "Clang")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w" PARENT_SCOPE) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w" PARENT_SCOPE)
elseif(CMAKE_C_COMPILER_ID STREQUAL MSVC) elseif(CMAKE_C_COMPILER_ID STREQUAL "MSVC")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W0" PARENT_SCOPE) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W0" PARENT_SCOPE)
endif() endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL GNU OR CMAKE_CXX_COMPILER_ID STREQUAL Clang) if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w" PARENT_SCOPE) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w" PARENT_SCOPE)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL MSVC) elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W0" PARENT_SCOPE) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W0" PARENT_SCOPE)
endif() endif()
endfunction() endfunction()