Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CMake support; Resolves #565 #566

Open
wants to merge 36 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
7a263b5
VERSION: prepare for 2.8rc1
bgoglin Jun 21, 2022
1974932
configure: disable netloc by default in 2.8
bgoglin Dec 18, 2017
3c6fd18
ci.inria.fr: move the v2.8 nightly build to a different time
bgoglin Jun 21, 2022
b62ca67
private/windows.h: guard against _ANONYMOUS_UNION/STRUCT redefinition
bgoglin Jun 28, 2022
1f746c0
VERSION: 2.8.0rc1 released, doing rc2 now
bgoglin Jun 29, 2022
cf388b0
VERSION: 2.8.0 released, doing 2.8.1rc1 now
bgoglin Jul 5, 2022
0db5fdc
pci: document the PCI affinity quirk for HPE Cray EX235a
bgoglin Jul 12, 2022
38fbe3d
utils/tests/calc: check for multiple levels of groups
bgoglin Jul 19, 2022
32d273f
levelzero: fix subdevice info properties
bgoglin Jul 19, 2022
6d1ea4f
pci+linux: make 32bits domain warnings non-critical
bgoglin Jul 25, 2022
346d231
core: if debug is enabled and debug messages are disabled, unhide err…
bgoglin Jul 25, 2022
d8f96b3
xml: also demote 32bits pci domain import errors to non-critical
bgoglin Jul 25, 2022
4a782cc
xml: fix an error message in the future xml obj id attribute
bgoglin Jul 25, 2022
2475694
completion: fix diff --refname
bgoglin Jul 28, 2022
0d4a0d2
bitmap.h: fix the doc for foreach()
bgoglin Aug 10, 2022
f0a9246
doc/examples: add memory-attributes.c
bgoglin Aug 19, 2022
f2ae31a
memattrs.h: cleanup doxygen formatting of the enum of memory attributes
bgoglin Aug 19, 2022
676f9db
doc/examples: use hwloc_uint64_t in memory-attributes.c
bgoglin Aug 23, 2022
060a4a1
nvml/bw: add nvlink versions 3&4
bgoglin Aug 23, 2022
863e887
tests/backends: fix build with ClangCI 15 compiler frontend for MSVC
bgoglin Sep 19, 2022
ba439ea
completion/lstopo: update the list of output formats
bgoglin Sep 23, 2022
3cbcde1
cuda: update to compute capability 9
bgoglin Oct 7, 2022
b6cf3af
Leak in hwloc__xml_import_cpukind
hzhou Oct 11, 2022
f58797e
lstopo/draw: fix the displaying of non-HBM L0 device memory
bgoglin Oct 26, 2022
a28cec6
cuda: update for compute capability 8.9
bgoglin Nov 2, 2022
a5bbb02
doxy: number of character +s
bgoglin Nov 10, 2022
637927f
diff: reuse temp variable
bgoglin Nov 10, 2022
69d5d8b
pci: don't ignore CXL memory expanders
bgoglin Dec 5, 2022
20c4d4a
utils/gather-topology: gather cxl devices and drivers
bgoglin Dec 5, 2022
802b625
NEWS: bring 2.7.2 bullets
bgoglin Jan 3, 2023
c6f6ed8
contrib/*/check-versions.sh: add --update to usage
bgoglin Jan 3, 2023
f588db9
contrib/android/check-versions.sh: make a remaining verbose message c…
bgoglin Jan 3, 2023
f2ec6ef
contrib/dist/make_dist_tarball: update android/windows VERSION too
bgoglin Jan 3, 2023
cfab985
darwin: don't forget to filter perflevel caches
bgoglin Feb 1, 2023
1a5a66d
feat: Create a CMakeLists.txt file
FunMiles Jan 30, 2023
ef897c3
chore: Reactivate tests and introduce OS specific test treatment.
FunMiles Apr 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
257 changes: 257 additions & 0 deletions CMakeLists.txt
@@ -0,0 +1,257 @@
cmake_minimum_required(VERSION 3.24)
project(hwloc
LANGUAGES C
VERSION 3.0.0)

enable_testing()

if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
set( STANDALONE TRUE )
endif()

option(HWLOC_ENABLE_TESTING "Enable testing" ON)
option(HWLOC_SKIP_LSTOPO "don't build/install lstopo")
option(HWLOC_SKIP_TOOLS "don't build/install other hwloc tools")
option(HWLOC_SKIP_INCLUDES "don't install headers")
option(HWLOC_WITH_LIBXML2 "use libxml2 instead of minimal XML")
option(HWLOC_WITH_OPENCL "enable OpenCL support")
option(HWLOC_WITH_CUDA "enable CUDA support")
option(HWLOC_BUILD_SHARED_LIBS "build shared libraries" ${BUILD_SHARED_LIBS})

set(TOPDIR .)
#configure_file(${TOPDIR}/contrib/windows/hwloc_config.h include/hwloc/autogen/config.h COPYONLY)

# Configure dynamically based on platform capabilities
include(CheckIncludeFile)
include(CheckSymbolExists)
include(CheckCSourceCompiles)

check_include_file("dirent.h" HAVE_DIRENT_H)
check_include_file("unistd.h" HAVE_UNISTD_H)
check_include_file("malloc.h" HAVE_MALLOC_H)
check_include_file("memory.h" HAVE_MEMORY_H)

check_symbol_exists(mkstemp "stdlib.h" HAVE_MKSTEMP)
check_symbol_exists(memalign "malloc.h" HAVE_MEMALIGN)

check_symbol_exists(strncasecmp "strings.h" HAVE_STRNCASECMP)
if(MSVC AND HAVE_STRNCASECMP)
set(hwloc_strncasecmp 1)
set(hwloc_strncasecmp_fcn strncasecmp)
else()
set(hwloc_strncasecmp 0)
set(hwloc_strncasecmp_fcn strncmp)
endif()


set(SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P})
# disable x86 entirely by default
set(HWLOC_X86_32_ARCH)
set(HWLOC_X86_64_ARCH)
set(HWLOC_HAVE_X86_CPUID 1)
if (CMAKE_SYSTEM_PROCESSOR MATCHES "(^AMD64$|^x86_64$)")
# "AMD64" on Windows, "x86_64" on Linux
set(HWLOC_X86_64_ARCH 1)
elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "(^x86$|i.86)")
# "x86" on Windows, "i.86" on Linux
set(HWLOC_X86_32_ARCH 1)
else()
set(HWLOC_HAVE_X86_CPUID 0)
endif()

check_c_source_compiles("int main(void) {int cpuinfo[4]; __cpuidex(cpuinfo,0,0); return 0;}"
HWLOC_HAVE_MSVC_CPUIDEX
)

# the following lines are disabled until we are sure they are safe with old build environmentx
# - snprintf() returned broken values in the past, hwloc detects it during configure (see 7a4ee26510c06b55fc04aaccbfa18d0ca3b87198)
# set(HAVE_DECL_SNPRINTF 1)
# - strtoull() had some issues in the past (see 9559bd08b79ef63dce45df87fb7f875b73ecb512)
# set(HAVE_DECL_STRTOULL 1)

# --- optional external libraries
set(HWLOC_HAVE_LIBXML2)
if(HWLOC_WITH_LIBXML2)
find_package(LibXml2 REQUIRED)
set(HWLOC_HAVE_LIBXML2 1)
endif()

set(HWLOC_HAVE_OPENCL)
if(HWLOC_WITH_OPENCL)
find_package(OpenCL REQUIRED)
set(HWLOC_HAVE_OPENCL 1)
endif()

set(HAVE_CUDA)
set(HAVE_CUDA_H)
set(HAVE_CUDA_RUNTIME_API_H)
set(HWLOC_HAVE_CUDART)
if(HWLOC_WITH_CUDA)
find_package(CUDAToolkit REQUIRED)
set(HAVE_CUDA 1)
set(HAVE_CUDA_H 1)
set(HAVE_CUDA_RUNTIME_API_H 1)
set(HWLOC_HAVE_CUDART 1)
endif()

# Library

add_compile_definitions($<$<CONFIG:DEBUG>:HWLOC_DEBUG=1>)

add_library(hwloc)
add_library(hwloc::hwloc ALIAS hwloc)
target_sources(hwloc PRIVATE
${TOPDIR}/hwloc/topology.c
${TOPDIR}/hwloc/traversal.c
${TOPDIR}/hwloc/distances.c
${TOPDIR}/hwloc/memattrs.c
${TOPDIR}/hwloc/cpukinds.c
${TOPDIR}/hwloc/components.c
${TOPDIR}/hwloc/bind.c
${TOPDIR}/hwloc/bitmap.c
${TOPDIR}/hwloc/pci-common.c
${TOPDIR}/hwloc/diff.c
${TOPDIR}/hwloc/shmem.c
${TOPDIR}/hwloc/misc.c
${TOPDIR}/hwloc/base64.c
${TOPDIR}/hwloc/topology-noos.c
${TOPDIR}/hwloc/topology-synthetic.c
${TOPDIR}/hwloc/topology-xml.c
${TOPDIR}/hwloc/topology-xml-nolibxml.c
$<$<BOOL:${MSVC}>:${TOPDIR}/hwloc/topology-windows.c>
${TOPDIR}/hwloc/topology-x86.c
$<$<BOOL:${HWLOC_HAVE_LIBXML2}>:${TOPDIR}/hwloc/topology-xml-libxml.c>
$<$<BOOL:${HWLOC_HAVE_OPENCL}>:${TOPDIR}/hwloc/topology-opencl.c>
$<$<BOOL:${HAVE_CUDA}>:${TOPDIR}/hwloc/topology-cuda.c>
PRIVATE FILE_SET private_headers TYPE HEADERS
BASE_DIRS ${PROJECT_SOURCE_DIR}/include ${CMAKE_CURRENT_BINARY_DIR}/include/
FILES
${CMAKE_CURRENT_BINARY_DIR}/include/private/autogen/config.h
${CMAKE_CURRENT_BINARY_DIR}/include/static-components.h
PUBLIC FILE_SET HEADERS
BASE_DIRS ${PROJECT_SOURCE_DIR}/include ${CMAKE_CURRENT_BINARY_DIR}/include/
FILES
include/hwloc.h
include/hwloc/rename.h
include/hwloc/bitmap.h
include/hwloc/helper.h
include/hwloc/inlines.h
include/hwloc/memattrs.h
include/hwloc/cpukinds.h
include/hwloc/export.h
include/hwloc/distances.h
include/hwloc/diff.h
include/hwloc/deprecated.h
${CMAKE_CURRENT_BINARY_DIR}/include/hwloc/autogen/config.h
)

if (APPLE)
set (OS_CONTRIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/contrib/macos)

configure_file(${OS_CONTRIB_DIR}/private_config.h.in include/private/autogen/config.h)
configure_file(${OS_CONTRIB_DIR}/static-components.h.in include/static-components.h)
configure_file(${OS_CONTRIB_DIR}/hwloc_config.h include/hwloc/autogen/config.h COPYONLY)

target_sources(hwloc PRIVATE
${TOPDIR}/hwloc/topology-darwin.c
)
target_link_libraries(hwloc PUBLIC "-framework CoreFoundation" "-framework IOKit")
endif ()

if (STANDALONE)
if(HWLOC_ENABLE_TESTING)
add_subdirectory(${TOPDIR}/tests/hwloc ${CMAKE_CURRENT_BINARY_DIR}/tests/hwloc)
endif()
# Tools under utils/hwloc

if (NOT HWLOC_SKIP_TOOLS)

set(TOOLS
hwloc-bind
hwloc-calc
hwloc-diff
hwloc-distrib
hwloc-gather-cpuid
hwloc-info
hwloc-patch
)

foreach (tool IN ITEMS ${TOOLS})
add_executable(${tool}
${TOPDIR}/utils/hwloc/${tool}.c)
target_link_libraries(${tool} hwloc)
endforeach (tool)

endif ()

if (NOT HWLOC_SKIP_LSTOPO)

set(LSTOPOS
lstopo-no-graphics
# lstopo
# lstopo-win
)

# set(LSTOPO_COMMON_SOURCES
# ${TOPDIR}/utils/lstopo/lstopo.c
# ${TOPDIR}/utils/lstopo/lstopo-draw.c
# ${TOPDIR}/utils/lstopo/lstopo-tikz.c
# ${TOPDIR}/utils/lstopo/lstopo-fig.c
# ${TOPDIR}/utils/lstopo/lstopo-svg.c
# ${TOPDIR}/utils/lstopo/lstopo-ascii.c
# ${TOPDIR}/utils/lstopo/lstopo-text.c
# ${TOPDIR}/utils/lstopo/lstopo-xml.c
# ${TOPDIR}/utils/hwloc/common-ps.c
# )
#
# add_executable(lstopo-no-graphics
# ${LSTOPO_COMMON_SOURCES}
# )
# target_link_libraries(lstopo-no-graphics PRIVATE hwloc)

# add_executable(lstopo
# ${LSTOPO_COMMON_SOURCES}
## ${TOPDIR}/utils/lstopo/lstopo-windows.c
# )
# target_compile_definitions(lstopo PRIVATE LSTOPO_HAVE_GRAPHICS)

# add_executable(lstopo-win WIN32
# ${LSTOPO_COMMON_SOURCES}
# ${TOPDIR}/utils/lstopo/lstopo-windows.c
# )
# target_compile_definitions(lstopo-win PRIVATE LSTOPO_HAVE_GRAPHICS)
# target_link_options(lstopo-win PRIVATE "$<$<BOOL:${MSVC}>:/subsystem:windows;/entry:mainCRTStartup>")


endif ()

include(GNUInstallDirs)
include(CMakePackageConfigHelpers)

install(TARGETS hwloc
EXPORT ${PROJECT_NAME}_Targets
FILE_SET HEADERS
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
INCLUDES DESTINATION include)

install(EXPORT ${PROJECT_NAME}_Targets
FILE ${PROJECT_NAME}Targets.cmake
NAMESPACE ${PROJECT_NAME}::
DESTINATION lib/cmake/hwloc)

write_basic_package_version_file("${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion)

configure_package_config_file(
"${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}Config.cmake.in"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION
${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake)

install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake)
endif ()
17 changes: 16 additions & 1 deletion NEWS
@@ -1,5 +1,5 @@
Copyright © 2009 CNRS
Copyright © 2009-2022 Inria. All rights reserved.
Copyright © 2009-2023 Inria. All rights reserved.
Copyright © 2009-2013 Université Bordeaux
Copyright © 2009-2011 Cisco Systems, Inc. All rights reserved.
Copyright © 2020 Hewlett Packard Enterprise. All rights reserved.
Expand All @@ -17,6 +17,13 @@ bug fixes (and other actions) for each version of hwloc since version
0.9.


Version 2.8.1
-------------
* Don't forget to apply filters to "perflevel" caches detected on recent
Mac OS X releases, thanks to Michel Lesoinne for the report.
* Add support for CUDA compute capability up to 9.0.


Version 2.8.0
-------------
* API
Expand Down Expand Up @@ -47,6 +54,14 @@ Version 2.8.0
file from the documentation.


Version 2.7.2
-------------
* Fix a crash when LevelZero devices have multiple subdevices,
e.g. on PonteVecchio GPUs, thanks to Jonathan Peyton.
* Fix a leak when importing cpukinds from XML,
thanks to Hui Zhou.


Version 2.7.1
-------------
* Workaround crashes when virtual machines report incoherent x86 CPUID
Expand Down
6 changes: 3 additions & 3 deletions VERSION
Expand Up @@ -9,7 +9,7 @@

major=2
minor=8
release=0
release=1

# greek is used for alpha or beta release tags. If it is non-empty,
# it will be appended to the version number. It does not have to be
Expand All @@ -18,7 +18,7 @@ release=0
# requirement is that it must be entirely printable ASCII characters
# and have no white space.

greek=a1
greek=rc1

# The date when this release was created

Expand All @@ -41,7 +41,7 @@ snapshot_version=${major}.${minor}.${release}${greek}-git
# 2. Version numbers are described in the Libtool current:revision:age
# format.

libhwloc_so_version=0:0:0
libhwloc_so_version=21:0:6
libnetloc_so_version=0:0:0

# Please also update the <TargetName> lines in contrib/windows/libhwloc.vcxproj
4 changes: 4 additions & 0 deletions cmake/hwlocConfig.cmake.in
@@ -0,0 +1,4 @@
@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")
check_required_components("@PROJECT_NAME@")
4 changes: 2 additions & 2 deletions configure.ac
Expand Up @@ -141,10 +141,10 @@ AC_SUBST([libnetloc_so_version])

AC_ARG_ENABLE([netloc],
[AS_HELP_STRING([--enable-netloc],
[The Netloc functionality is enabled by default, but will be silently skipped it if cannot be built (e.g., not supported on your platform). Using --enable-netloc will cause configure to abort if Netloc cannot be build. Using --disable-netloc will cause configure to skip attempting to build netloc at all.])
[The Netloc functionality is disabled by default. Using --enable-netloc will cause configure to abort if Netloc cannot be build (e.g., not supported on your platform).])
])

AS_IF([test "$enable_netloc" != "no" -a "$hwloc_mode" = "standalone"],
AS_IF([test "$enable_netloc" = "yes" -a "$hwloc_mode" = "standalone"],
[NETLOC_SETUP_CORE([], [],
[AS_IF([test "$enable_netloc" = "yes"],
[AC_MSG_ERROR([Cannot build netloc core])])
Expand Down
2 changes: 1 addition & 1 deletion contrib/android/AndroidApp/lstopo/build.gradle
Expand Up @@ -11,7 +11,7 @@ android {
// Official hwloc version - snapshot number - android apk version
// Set snapshot number to 1 when the hwloc version is increased.
// Increase the snapshot number when the hwloc code changed but not its version
versionName "2.8.0a1-1-1.5.1"
versionName "2.8.1rc1-1-1.5.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
Expand Down
6 changes: 3 additions & 3 deletions contrib/android/check-versions.sh
@@ -1,6 +1,6 @@
#!/bin/bash
#
# Copyright © 2018-2021 Inria. All rights reserved.
# Copyright © 2018-2023 Inria. All rights reserved.
# $COPYRIGHT$
#

Expand All @@ -10,7 +10,7 @@ function die() {
}

if test "x$1" = "x-h" -o "x$1" = "x--help"; then
echo "$0 [--quiet] [git root directory]"
echo "$0 [--quiet] [--update] [git root directory]"
exit 0
fi

Expand Down Expand Up @@ -60,7 +60,7 @@ if test "x$update" = "x1"; then
sed -r -e '/define HWLOC_VERSION_MINOR /s/[0-9]+/'$official_minor'/' -i "$android_config_h"
sed -r -e '/define HWLOC_VERSION_RELEASE /s/[0-9]+/'$official_release'/' -i "$android_config_h"
sed -r -e '/define HWLOC_VERSION_GREEK "/s/"[0-9a-zA-Z\.-]*"/"'$official_greek'"/' -i "$android_config_h"
echo "Updating Android VERSION in $android_gradle ..."
$echo "Updating Android VERSION in $android_gradle ..."
# replace oldversion-X-Y with newversion-1-Y since a version bump usually puts back snapshot number to 1
suffix=$(grep -w versionName $android_gradle | grep -oP '".*"' | tr -d \" | grep -oP -- '-[0-9\.]+$')
sed -r -e '/versionName "/s/"[0-9a-zA-Z\.-]+"/"'$official_version'-1'$suffix'"/' -i $android_gradle
Expand Down
8 changes: 4 additions & 4 deletions contrib/android/include/hwloc/autogen/config.h
@@ -1,7 +1,7 @@
/* include/hwloc/autogen/config.h. Generated from config.h.in by configure. */
/* -*- c -*-
* Copyright © 2009 CNRS
* Copyright © 2009-2021 Inria. All rights reserved.
* Copyright © 2009-2022 Inria. All rights reserved.
* Copyright © 2009-2012 Université Bordeaux
* Copyright © 2009-2011 Cisco Systems, Inc. All rights reserved.
* See COPYING in top-level directory.
Expand All @@ -12,11 +12,11 @@
#ifndef HWLOC_CONFIG_H
#define HWLOC_CONFIG_H

#define HWLOC_VERSION "2.8.0a1"
#define HWLOC_VERSION "2.8.1rc1"
#define HWLOC_VERSION_MAJOR 2
#define HWLOC_VERSION_MINOR 8
#define HWLOC_VERSION_RELEASE 0
#define HWLOC_VERSION_GREEK "a1"
#define HWLOC_VERSION_RELEASE 1
#define HWLOC_VERSION_GREEK "rc1"

#if (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95))
# define __hwloc_restrict __restrict
Expand Down