Skip to content

Commit

Permalink
contrib: add CMakeLists.txt under contrib/windows-cmake
Browse files Browse the repository at this point in the history
Inspired from https://github.com/microsoft/vcpkg/tree/master/ports/hwloc
(MIT license, OK for BSD-3).

See the README for details.

Closes #88

Signed-off-by: Brice Goglin <[email protected]>
  • Loading branch information
bgoglin committed Oct 25, 2021
1 parent 58fa0dc commit f9f10c7
Show file tree
Hide file tree
Showing 5 changed files with 200 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ endif
DIST_SUBDIRS = $(SUBDIRS)
if HWLOC_BUILD_STANDALONE
DIST_SUBDIRS += contrib/windows
EXTRA_DIST += contrib/windows-cmake
if !BUILD_NETLOC
DIST_SUBDIRS += netloc
endif
Expand Down
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Version 2.6.0
- Try /opt/rocm if it exists.
- See "How do I enable ROCm SMI and select which version to use?"
in the FAQ for details.
+ Add a CMakeLists for Windows under contrib/windows-cmake/ .
* Documentation
+ Add FAQ entry "How do I create a custom heterogeneous and
asymmetric topology?"
Expand Down
170 changes: 170 additions & 0 deletions contrib/windows-cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
cmake_minimum_required(VERSION 3.15)
project(hwloc
LANGUAGES C
VERSION 2.7.0)

# Available configuration options
# HWLOC_SKIP_LSTOPO doesn't build/install lstopo
# HWLOC_SKIP_TOOLS doesn't build/install other hwloc tools
# HWLOC_SKIP_INCLUDES doesn't install headers

set(TOPDIR ../..)

# Configure based on the MSVC config

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

file(READ ${CMAKE_CURRENT_BINARY_DIR}/include/private/autogen/config.h PRIVATE_CONFIG_H)
string(REPLACE "#define SIZEOF_VOID_P 8" "#define SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P}" PRIVATE_CONFIG_H "${PRIVATE_CONFIG_H}")

# disable x86 entirely by default
string(REPLACE "#define HWLOC_X86_32_ARCH 1" "/* #undef HWLOC_X86_32_ARCH */" PRIVATE_CONFIG_H "${PRIVATE_CONFIG_H}")
string(REPLACE "#define HWLOC_X86_64_ARCH 1" "/* #undef HWLOC_X86_64_ARCH */" PRIVATE_CONFIG_H "${PRIVATE_CONFIG_H}")
# and now reenable x86-36 or x86-64 if detected
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
# "AMD64" on Windows, "x86_64" on Linux
string(REPLACE "/* #undef HWLOC_X86_64_ARCH */" "#define HWLOC_X86_64_ARCH 1" PRIVATE_CONFIG_H "${PRIVATE_CONFIG_H}")
elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86" OR CMAKE_SYSTEM_PROCESSOR MATCHES "i.86")
# "x86" on Windows, "i.86" on Linux
string(REPLACE "/* #undef HWLOC_X86_32_ARCH */" "#define HWLOC_X86_32_ARCH 1" PRIVATE_CONFIG_H "${PRIVATE_CONFIG_H}")
endif()

# 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)
# string(REPLACE "#define HAVE_DECL_SNPRINTF 0" "#define HAVE_DECL_SNPRINTF 1" PRIVATE_CONFIG_H "${PRIVATE_CONFIG_H}")
# - strtoull() had some issues in the past (see 9559bd08b79ef63dce45df87fb7f875b73ecb512)
# string(REPLACE "#define HAVE_DECL_STRTOULL 0" "#define HAVE_DECL_STRTOULL 1" PRIVATE_CONFIG_H "${PRIVATE_CONFIG_H}")

file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/include/private/autogen/config.h "${PRIVATE_CONFIG_H}")

# Library

add_compile_options("$<$<CONFIG:DEBUG>:-DHWLOC_DEBUG=1>")

# FIXME dll soname
add_library(libhwloc
${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
${TOPDIR}/hwloc/topology-windows.c
${TOPDIR}/hwloc/topology-x86.c
)

set_target_properties(libhwloc PROPERTIES DEFINE_SYMBOL _USRDLL)

target_include_directories(libhwloc PRIVATE ${TOPDIR}/include ${TOPDIR}/hwloc ${CMAKE_CURRENT_BINARY_DIR}/include)

# 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_include_directories(${tool} PRIVATE ${TOPDIR}/include ${CMAKE_CURRENT_BINARY_DIR}/include)
target_link_libraries(${tool} PRIVATE libhwloc)
endforeach(tool)

endif()

# lstopo

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 libhwloc)

add_executable(lstopo
${LSTOPO_COMMON_SOURCES}
${TOPDIR}/utils/lstopo/lstopo-windows.c
)
set_target_properties(lstopo PROPERTIES COMPILE_FLAGS "-DLSTOPO_HAVE_GRAPHICS")

add_executable(lstopo-win
${LSTOPO_COMMON_SOURCES}
${TOPDIR}/utils/lstopo/lstopo-windows.c
)
set_target_properties(lstopo-win PROPERTIES COMPILE_FLAGS "-DLSTOPO_HAVE_GRAPHICS")
target_link_options(lstopo-win PRIVATE "/subsystem:windows" "/entry:mainCRTStartup")

foreach(tool IN ITEMS ${LSTOPOS})
target_include_directories(${tool} PRIVATE ${TOPDIR}/include ${CMAKE_CURRENT_BINARY_DIR}/include ${TOPDIR}/utils/hwloc)
target_link_libraries(${tool} PRIVATE libhwloc)
endforeach(tool)

endif()

# Misc

foreach(target IN ITEMS libhwloc ${TOOLS} ${LSTOPOS})
target_compile_definitions(${target} PRIVATE _CRT_SECURE_NO_WARNINGS)
endforeach(target)

# Install

install(TARGETS libhwloc
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib)

if(NOT HWLOC_SKIP_TOOLS)
install(TARGETS ${TOOLS}
RUNTIME DESTINATION bin)
endif()

if(NOT HWLOC_SKIP_LSTOPO)
install(TARGETS ${LSTOPOS}
RUNTIME DESTINATION bin)
endif()

if(NOT HWLOC_SKIP_INCLUDES)
install(FILES ${TOPDIR}/include/hwloc.h DESTINATION include)
install(DIRECTORY ${TOPDIR}/include/hwloc DESTINATION include FILES_MATCHING PATTERN "*.h")
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/hwloc/autogen/config.h DESTINATION include/hwloc/autogen)
endif()
25 changes: 25 additions & 0 deletions contrib/windows-cmake/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
This CMake support for Windows builds is inspired from
https://github.com/microsoft/vcpkg/blob/7e495c0773353de69f24f3af8aea0ae9a129508c/ports/hwloc/CMakeLists.txt
(before vcpkg switched from CMake to autotools).

May be used with:
$ cmake [options] -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=\path\to\install .
$ cmake --build .
$ cmake --build . --target INSTALL

The "Debug" build type is also available, it enables lots of
verbose debug messages and assertions.

Options:
-DHWLOC_SKIP_LSTOPO=1 to ignore lstopo
-DHWLOC_SKIP_TOOLS=1 to ignore other hwloc command-line tools
-DHWLOC_SKIP_INCLUDES=1 to ignore header installation

See contrib/ci.inria.fr/job-1-wincmake.bat for an example.


hwloc-compress-dir not built because it needs work.

hwloc-gather-topology is Linux specific.

hwloc-ps is not built because it does nothing on Windows anyway (see #367).
3 changes: 3 additions & 0 deletions doc/hwloc.doxy
Original file line number Diff line number Diff line change
Expand Up @@ -4079,6 +4079,9 @@ repository for an example used for nightly testing.

hwloc also supports the Cygwin environment for porting Unix code to Windows.

Windows support is also possible with CMake thanks to
<tt>contrib/windows-cmake/CMakeLists.txt</tt>.

hwloc releases also contain a basic Microsoft Visual Studio solution
under <tt>contrib/windows/</tt>.

Expand Down

0 comments on commit f9f10c7

Please sign in to comment.