Skip to content

Commit

Permalink
Fix CMake syntax for variable expansion
Browse files Browse the repository at this point in the history
When using variables to compare (like in if clause) the variable
shouldn't be quoted. More details can be found at the link below:

https://cmake.org/cmake/help/latest/command/if.html#variable-expansion

Signed-off-by: HS <[email protected]>
  • Loading branch information
hs-apotell authored and parrt committed Jul 6, 2022
1 parent 68ceefb commit f6c29b6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
14 changes: 7 additions & 7 deletions runtime/Cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ if(WITH_DEMO)
endif()
endif(WITH_DEMO)

if("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC")
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
set(MY_CXX_WARNING_FLAGS " /W4")

if(DISABLE_WARNINGS)
Expand All @@ -94,7 +94,7 @@ endif()
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_UTF8_INSTEAD_OF_CODECVT")

# Initialize CXXFLAGS.
if("${CMAKE_VERSION}" VERSION_GREATER 3.1.0)
if(CMAKE_VERSION VERSION_GREATER 3.1.0)
if(NOT DEFINED CMAKE_CXX_STANDARD)
# only set CMAKE_CXX_STANDARD if not already set
# this allows the standard to be set by the caller, for example with -DCMAKE_CXX_STANDARD:STRING=17
Expand All @@ -112,7 +112,7 @@ endif()

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MY_CXX_WARNING_FLAGS}")

if("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC")
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /Od /Zi /MP ${MY_CXX_WARNING_FLAGS}")
set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /O1 /Oi /Ob2 /Gy /MP /DNDEBUG ${MY_CXX_WARNING_FLAGS}")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /O2 /Oi /Ob2 /Gy /MP /DNDEBUG ${MY_CXX_WARNING_FLGAS}")
Expand All @@ -125,20 +125,20 @@ else()
endif()

# Compiler-specific C++17 activation.
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Intel")
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Intel")
execute_process(
COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
# Just g++-5.0 and greater contain <codecvt> header. (test in ubuntu)
if(NOT (GCC_VERSION VERSION_GREATER 5.0 OR GCC_VERSION VERSION_EQUAL 5.0))
message(FATAL_ERROR "${PROJECT_NAME} requires g++ 5.0 or greater.")
endif ()
elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" AND ANDROID)
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND ANDROID)
# Need -Os cflag and cxxflags here to work with exception handling on armeabi.
# see https://github.com/android-ndk/ndk/issues/573
# and without -stdlib=libc++ cxxflags
elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" AND APPLE)
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -stdlib=libc++")
elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" AND ( CMAKE_SYSTEM_NAME MATCHES "Linux" OR CMAKE_SYSTEM_NAME MATCHES "FreeBSD") )
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND ( CMAKE_SYSTEM_NAME MATCHES "Linux" OR CMAKE_SYSTEM_NAME MATCHES "FreeBSD") )
execute_process(
COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE CLANG_VERSION)
if(NOT (CLANG_VERSION VERSION_GREATER 4.2.1 OR CLANG_VERSION VERSION_EQUAL 4.2.1))
Expand Down
6 changes: 3 additions & 3 deletions runtime/Cpp/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ else()
endif()


if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(disabled_compile_warnings "${disabled_compile_warnings} -Wno-dollar-in-identifier-extension -Wno-four-char-constants")
elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Intel")
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Intel")
set(disabled_compile_warnings "${disabled_compile_warnings} -Wno-multichar")
endif()

Expand All @@ -91,7 +91,7 @@ if (WIN32)
set(static_lib_suffix "-static")
target_compile_definitions(antlr4_shared PUBLIC ANTLR4CPP_EXPORTS)
target_compile_definitions(antlr4_static PUBLIC ANTLR4CPP_STATIC)
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC")
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
set(extra_share_compile_flags "-MP /wd4251")
set(extra_static_compile_flags "-MP")
endif()
Expand Down

0 comments on commit f6c29b6

Please sign in to comment.