[NFC][CMake] quote ${CMAKE_SYSTEM_NAME} consistently (#154537)
A CMake change included in CMake 4.0 makes `AIX` into a variable
(similar to `APPLE`, etc.)
https://gitlab.kitware.com/cmake/cmake/-/commit/ff03db6657c38c8cf992877ea66174c33d0bcb0b
However, `${CMAKE_SYSTEM_NAME}` unfortunately also expands exactly to
`AIX` and `if` auto-expands variable names in CMake. That means you get
a double expansion if you write:
`if (${CMAKE_SYSTEM_NAME} MATCHES "AIX")`
which becomes:
`if (AIX MATCHES "AIX")`
which is as if you wrote:
`if (ON MATCHES "AIX")`
You can prevent this by quoting the expansion of "${CMAKE_SYSTEM_NAME}",
due to policy
[CMP0054](https://cmake.org/cmake/help/latest/policy/CMP0054.html#policy:CMP0054)
which is on by default in 4.0+. Most of the LLVM CMake already does
this, but this PR fixes the remaining cases where we do not.
GitOrigin-RevId: 63195d3d7a8bde05590f91a38398f986bb4265b2
diff --git a/CMakeLists.txt b/CMakeLists.txt
index edd79df..f3de4bc 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -117,7 +117,7 @@
# there is no point in trying to compile libomptarget on other OSes.
# 32-bit systems are not supported either.
if (APPLE OR WIN32 OR WASM OR NOT "cxx_std_17" IN_LIST CMAKE_CXX_COMPILE_FEATURES
- OR NOT CMAKE_SIZEOF_VOID_P EQUAL 8 OR ${CMAKE_SYSTEM_NAME} MATCHES "AIX")
+ OR NOT CMAKE_SIZEOF_VOID_P EQUAL 8 OR "${CMAKE_SYSTEM_NAME}" MATCHES "AIX")
set(ENABLE_LIBOMPTARGET OFF)
endif()
diff --git a/cmake/OpenMPTesting.cmake b/cmake/OpenMPTesting.cmake
index 14cc5c6..85240ae 100644
--- a/cmake/OpenMPTesting.cmake
+++ b/cmake/OpenMPTesting.cmake
@@ -57,7 +57,7 @@
if (MSVC OR XCODE)
set(DEFAULT_LIT_ARGS "${DEFAULT_LIT_ARGS} --no-progress-bar")
endif()
- if (${CMAKE_SYSTEM_NAME} MATCHES "AIX")
+ if ("${CMAKE_SYSTEM_NAME}" MATCHES "AIX")
set(DEFAULT_LIT_ARGS "${DEFAULT_LIT_ARGS} --time-tests --timeout=3000")
endif()
set(OPENMP_LIT_ARGS "${DEFAULT_LIT_ARGS}" CACHE STRING "Options for lit.")
diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt
index b6c4759..93eb14f 100644
--- a/runtime/CMakeLists.txt
+++ b/runtime/CMakeLists.txt
@@ -136,7 +136,7 @@
"Appended user specified assembler flags.")
set(LIBOMP_LDFLAGS "" CACHE STRING
"Appended user specified linker flags.")
-if(${CMAKE_SYSTEM_NAME} MATCHES "AIX")
+if("${CMAKE_SYSTEM_NAME}" MATCHES "AIX")
set(LIBOMP_LIBFLAGS "-lperfstat" CACHE STRING
"Appended user specified linked libs flags. (e.g., -lm)")
if("${LIBOMP_ARCH}" STREQUAL "ppc")
diff --git a/runtime/cmake/LibompHandleFlags.cmake b/runtime/cmake/LibompHandleFlags.cmake
index 61fc31d..c36a88f 100644
--- a/runtime/cmake/LibompHandleFlags.cmake
+++ b/runtime/cmake/LibompHandleFlags.cmake
@@ -140,14 +140,14 @@
if(LIBOMP_HAVE_SHM_OPEN_WITH_LRT)
libomp_append(libflags_local -lrt)
endif()
- if(${CMAKE_SYSTEM_NAME} MATCHES "DragonFly|FreeBSD|OpenBSD")
+ if("${CMAKE_SYSTEM_NAME}" MATCHES "DragonFly|FreeBSD|OpenBSD")
libomp_append(libflags_local "-Wl,--no-as-needed" LIBOMP_HAVE_AS_NEEDED_FLAG)
libomp_append(libflags_local "-lm")
libomp_append(libflags_local "-Wl,--as-needed" LIBOMP_HAVE_AS_NEEDED_FLAG)
- if (${CMAKE_SYSTEM_NAME} STREQUAL "DragonFly")
+ if ("${CMAKE_SYSTEM_NAME}" STREQUAL "DragonFly")
libomp_append(libflags_local "-lkvm")
endif()
- elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux|NetBSD|SunOS")
+ elseif("${CMAKE_SYSTEM_NAME}" MATCHES "Linux|NetBSD|SunOS")
libomp_append(libflags_local -lm)
endif()
set(libflags_local ${libflags_local} ${LIBOMP_LIBFLAGS})
diff --git a/runtime/cmake/config-ix.cmake b/runtime/cmake/config-ix.cmake
index 144c657..30b69d4 100644
--- a/runtime/cmake/config-ix.cmake
+++ b/runtime/cmake/config-ix.cmake
@@ -321,7 +321,7 @@
(LIBOMP_ARCH STREQUAL sparcv9))
AND # OS supported?
((WIN32 AND LIBOMP_HAVE_PSAPI) OR APPLE OR
- (NOT (WIN32 OR ${CMAKE_SYSTEM_NAME} MATCHES "AIX") AND LIBOMP_HAVE_WEAK_ATTRIBUTE)))
+ (NOT (WIN32 OR "${CMAKE_SYSTEM_NAME}" MATCHES "AIX") AND LIBOMP_HAVE_WEAK_ATTRIBUTE)))
set(LIBOMP_HAVE_OMPT_SUPPORT TRUE)
else()
set(LIBOMP_HAVE_OMPT_SUPPORT FALSE)
diff --git a/runtime/src/CMakeLists.txt b/runtime/src/CMakeLists.txt
index 569061c..08e1753 100644
--- a/runtime/src/CMakeLists.txt
+++ b/runtime/src/CMakeLists.txt
@@ -121,7 +121,7 @@
# Unix specific files
libomp_append(LIBOMP_CXXFILES z_Linux_util.cpp)
libomp_append(LIBOMP_CXXFILES kmp_gsupport.cpp)
- if(${CMAKE_SYSTEM_NAME} MATCHES "AIX")
+ if("${CMAKE_SYSTEM_NAME}" MATCHES "AIX")
libomp_append(LIBOMP_GNUASMFILES z_AIX_asm.S) # AIX assembly file
else()
libomp_append(LIBOMP_GNUASMFILES z_Linux_asm.S) # Unix assembly file
@@ -218,7 +218,7 @@
LINK_FLAGS "${LIBOMP_CONFIGURED_LDFLAGS}"
LINKER_LANGUAGE ${LIBOMP_LINKER_LANGUAGE}
)
-elseif(${CMAKE_SYSTEM_NAME} MATCHES "AIX")
+elseif("${CMAKE_SYSTEM_NAME}" MATCHES "AIX")
set(LIBOMP_SHARED_OUTPUT_NAME "omp" CACHE STRING "Output name for the shared libomp runtime library.")
set_target_properties(omp PROPERTIES
OUTPUT_NAME "${LIBOMP_SHARED_OUTPUT_NAME}"