This is an automated email from the ASF dual-hosted git repository.
bneradt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push:
new da99b1d698 Check for 128bit CAS in CMake build (#9851)
da99b1d698 is described below
commit da99b1d698686a6776ddae503420f052ee08ae55
Author: JosiahWI <[email protected]>
AuthorDate: Thu Jun 15 14:44:19 2023 -0500
Check for 128bit CAS in CMake build (#9851)
This adds a script that sets the following variables:
TS_HAS_128BIT_CAS, TS_NEEDS_MCX16_FOR_CAS. The source code for
the compile check was taken from the autotools build with some
minor modifications (removed void arg to main, removed extraneous
semicolon, brought main body back to 1 level of indentation).
---
CMakeLists.txt | 2 ++
cmake/Check128BitCas.cmake | 60 ++++++++++++++++++++++++++++++++++++
include/tscore/ink_config.h.cmake.in | 1 +
src/tscore/CMakeLists.txt | 3 ++
4 files changed, 66 insertions(+)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 35cf6376e9..294dd39e7b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -129,6 +129,8 @@ endif()
find_package(ZLIB REQUIRED)
+include(Check128BitCas)
+
# Find ccache
include(find_ccache)
diff --git a/cmake/Check128BitCas.cmake b/cmake/Check128BitCas.cmake
new file mode 100644
index 0000000000..1e9a80b9ba
--- /dev/null
+++ b/cmake/Check128BitCas.cmake
@@ -0,0 +1,60 @@
+#######################
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
contributor license
+# agreements. See the NOTICE file distributed with this work for additional
information regarding
+# copyright ownership. The ASF licenses this file to you under the Apache
License, Version 2.0
+# (the "License"); you may not use this file except in compliance with the
License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
distributed under the License
+# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express
+# or implied. See the License for the specific language governing permissions
and limitations under
+# the License.
+#
+#######################
+
+# Check128BitCas.cmake
+#
+# This will define the following variables
+#
+# TS_HAS_128BIT_CAS
+# TS_NEEDS_MCX16_FOR_CAS
+#
+
+set(CHECK_PROGRAM
+ "
+ int
+ main()
+ {
+ __int128_t x = 0;
+ __sync_bool_compare_and_swap(&x,0,10);
+
+ return 0;
+ }
+ "
+)
+
+include(CheckCSourceCompiles)
+check_c_source_compiles("${CHECK_PROGRAM}" TS_HAS_128BIT_CAS)
+
+if(NOT TS_HAS_128BIT_CAS)
+ unset(TS_HAS_128BIT_CAS CACHE)
+ set(CMAKE_REQUIRED_FLAGS "-Werror" "-mcx16")
+ check_c_source_compiles("${CHECK_PROGRAM}" TS_HAS_128BIT_CAS)
+ set(NEED_MCX16 ${TS_HAS_128BIT_CAS})
+ unset(CMAKE_REQUIRED_FLAGS)
+endif()
+
+set(TS_NEEDS_MCX16_FOR_CAS
+ ${NEED_MCX16}
+ CACHE
+ BOOL
+ "Whether -mcx16 is needed to compile CAS"
+)
+
+unset(CHECK_PROGRAM)
+unset(NEEDS_MCX16)
+
+mark_as_advanced(TS_HAS_128BIT_CAS TS_NEEDS_MCX16_FOR_CAS)
diff --git a/include/tscore/ink_config.h.cmake.in
b/include/tscore/ink_config.h.cmake.in
index d894f3bf74..fbe34dc0df 100644
--- a/include/tscore/ink_config.h.cmake.in
+++ b/include/tscore/ink_config.h.cmake.in
@@ -108,6 +108,7 @@ const int DEFAULT_STACKSIZE = @DEFAULT_STACK_SIZE@;
#define TS_MAX_HOST_NAME_LEN @TS_MAX_HOST_NAME_LEN@
/* Feature Flags */
+#cmakedefine01 TS_HAS_128BIT_CAS
#cmakedefine01 TS_HAS_BACKTRACE
#cmakedefine01 TS_HAS_IN6_IS_ADDR_UNSPECIFIED
#cmakedefine01 TS_HAS_JEMALLOC
diff --git a/src/tscore/CMakeLists.txt b/src/tscore/CMakeLists.txt
index 567c082e2d..5322f30831 100644
--- a/src/tscore/CMakeLists.txt
+++ b/src/tscore/CMakeLists.txt
@@ -119,6 +119,9 @@ target_link_libraries(tscore
if(TS_USE_HWLOC)
target_link_libraries(tscore PUBLIC hwloc::hwloc)
endif()
+if(TS_HAS_128BIT_CAS AND TS_NEEDS_MCX16_FOR_CAS)
+ target_compile_options(tscore PUBLIC "-mcx16")
+endif()
add_executable(test_tscore
unit_tests/test_AcidPtr.cc