You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by bn...@apache.org on 2023/06/09 16:25:47 UTC

[trafficserver] branch master updated: Add support for hwloc library to CMake build (#9811)

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 bfc12b6ac4 Add support for hwloc library to CMake build (#9811)
bfc12b6ac4 is described below

commit bfc12b6ac4a56b68a155ff4e3934cc8a80452ac3
Author: JosiahWI <41...@users.noreply.github.com>
AuthorDate: Fri Jun 9 11:25:41 2023 -0500

    Add support for hwloc library to CMake build (#9811)
    
    The library will be used automatically if it is found on the system.
    If the library was found, a status message should be printed with the
    path to the library.
---
 CMakeLists.txt                       |  5 ++++
 cmake/Findhwloc.cmake                | 49 ++++++++++++++++++++++++++++++++++++
 include/tscore/ink_config.h.cmake.in |  1 +
 src/tscore/CMakeLists.txt            | 19 ++++++++++++--
 4 files changed, 72 insertions(+), 2 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0081155656..b316074ebb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -41,6 +41,7 @@ set(DEFAULT_STACK_SIZE 1048576 CACHE STRING "Default stack size (default 1048576
 set(TS_MAX_HOST_NAME_LEN 256 CACHE STRING "Max host name length (default 256)")
 set(TS_USE_SET_RBIO 1 CACHE STRING "Use openssl set_rbio (default 1)")
 set(TS_USE_DIAGS 1 CACHE STRING "Use diags (default 1)")
+option(TS_USE_HWLOC "Use hwloc (default OFF)")
 
 set(TS_VERSION_MAJOR 10)
 set(TS_VERSION_MINOR 0)
@@ -87,6 +88,10 @@ CHECK_INCLUDE_FILE(arpa/nameser_compat.h HAVE_ARPA_NAMESER_COMPAT_H)
 CHECK_INCLUDE_FILE(siginfo.h HAVE_SIGINFO_H)
 
 # Find libraries
+find_package(hwloc)
+if(hwloc_FOUND)
+    set(TS_USE_HWLOC TRUE)
+endif()
 find_package(PCRE)
 include(FindOpenSSL)
 find_package(OpenSSL)
diff --git a/cmake/Findhwloc.cmake b/cmake/Findhwloc.cmake
new file mode 100644
index 0000000000..7e67dddd47
--- /dev/null
+++ b/cmake/Findhwloc.cmake
@@ -0,0 +1,49 @@
+#######################
+#
+#  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.
+#
+#######################
+
+# Findhwloc.cmake
+#
+# This will define the following variables
+#
+#     hwloc_FOUND
+#     hwloc_LIBRARY
+#     hwloc_INCLUDE_DIRS
+#
+# and the following imported targets
+#
+#     hwloc::hwloc
+#
+
+find_library(hwloc_LIBRARY NAMES hwloc)
+find_path(hwloc_INCLUDE_DIR NAMES hwloc.h)
+
+mark_as_advanced(hwloc_FOUND hwloc_LIBRARY hwloc_INCLUDE_DIR)
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(hwloc
+    REQUIRED_VARS hwloc_LIBRARY hwloc_INCLUDE_DIR
+)
+
+if(hwloc_FOUND)
+    set(hwloc_INCLUDE_DIRS ${hwloc_INCLUDE_DIR})
+endif()
+
+if(hwloc_FOUND AND NOT TARGET hwloc::hwloc)
+    add_library(hwloc::hwloc INTERFACE IMPORTED)
+    target_include_directories(hwloc::hwloc INTERFACE ${hwloc_INCLUDE_DIRS})
+    target_link_libraries(hwloc::hwloc INTERFACE ${hwloc_LIBRARY})
+endif()
diff --git a/include/tscore/ink_config.h.cmake.in b/include/tscore/ink_config.h.cmake.in
index 9f93b0ef04..a4980bf9b5 100644
--- a/include/tscore/ink_config.h.cmake.in
+++ b/include/tscore/ink_config.h.cmake.in
@@ -105,6 +105,7 @@ const int DEFAULT_STACKSIZE = @DEFAULT_STACK_SIZE@;
 
 /* Feature Flags */
 #cmakedefine01 TS_USE_EPOLL
+#cmakedefine01 TS_USE_HWLOC
 #cmakedefine01 TS_USE_KQUEUE
 #cmakedefine01 TS_USE_LINUX_IO_URING
 #cmakedefine01 TS_USE_LINUX_NATIVE_AIO
diff --git a/src/tscore/CMakeLists.txt b/src/tscore/CMakeLists.txt
index 0c9a8f1e07..312ed92677 100644
--- a/src/tscore/CMakeLists.txt
+++ b/src/tscore/CMakeLists.txt
@@ -106,7 +106,17 @@ target_include_directories(tscore PRIVATE
         ${CMAKE_CURRENT_BINARY_DIR}
         ${YAML_INCLUDE_DIRS}
 )
-target_link_libraries(tscore ${PCRE_LIBRARIES} ${OPENSSL_LIBRARIES} yaml-cpp::yaml-cpp tscpputil resolv libswoc)
+target_link_libraries(tscore
+    PUBLIC
+        $<$<BOOL:TS_USE_HWLOC>:hwloc::hwloc>
+        libswoc
+        ${OPENSSL_LIBRARIES}
+        ${PCRE_LIBRARIES}
+        resolv
+        tscpputil
+    PRIVATE
+        yaml-cpp::yaml-cpp
+)
 
 add_executable(test_tscore
         unit_tests/test_AcidPtr.cc
@@ -139,7 +149,12 @@ add_executable(test_tscore
         unit_tests/test_scoped_resource.cc
         unit_tests/unit_test_main.cc
 )
-target_link_libraries(test_tscore PRIVATE tscore libswoc)
+target_link_libraries(test_tscore
+    PRIVATE
+        $<$<BOOL:TS_USE_HWLOC>:hwloc::hwloc>
+        libswoc
+        tscore
+)
 target_include_directories(test_tscore PRIVATE ${CMAKE_SOURCE_DIR}/include ${CATCH_INCLUDE_DIR})
 
 add_test(NAME test_tscore COMMAND $<TARGET_FILE:test_tscore>)