Skip to content

Commit b553b20

Browse files
[CMake] Clean up code around UMF_DISABLE_HWLOC
print general info when hwloc is disabled (not only for examples), remove the dead code when DLL_PATH_LIST would be set with empty var, print hwloc variables only once.
1 parent 8e073fd commit b553b20

File tree

1 file changed

+91
-95
lines changed

1 file changed

+91
-95
lines changed

CMakeLists.txt

Lines changed: 91 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ option(UMF_BUILD_FUZZTESTS "Build UMF fuzz tests" OFF)
4949
option(UMF_BUILD_GPU_EXAMPLES "Build UMF GPU examples" OFF)
5050
option(UMF_DEVELOPER_MODE "Enable additional developer checks" OFF)
5151
option(
52-
UMF_LINK_HWLOC_STATICALLY
53-
"Link UMF with HWLOC library statically (supported for Linux, MacOS and Release build on Windows)"
52+
UMF_DISABLE_HWLOC
53+
"Disable hwloc and UMF features requiring it (OS provider, memtargets, topology discovery)"
5454
OFF)
5555
option(
56-
UMF_DISABLE_HWLOC
57-
"Disable features that requires hwloc (OS provider, memory targets, topology discovery)"
56+
UMF_LINK_HWLOC_STATICALLY
57+
"Link UMF with HWLOC library statically (supported for Linux, MacOS and Release build on Windows)"
5858
OFF)
5959
option(UMF_FORMAT_CODE_STYLE
6060
"Add clang, cmake, and black -format-check and -format-apply targets"
@@ -100,16 +100,19 @@ else()
100100
message(FATAL_ERROR "Unknown OS type")
101101
endif()
102102

103-
if(NOT DEFINED UMF_HWLOC_REPO)
104-
set(UMF_HWLOC_REPO "https://github.com/open-mpi/hwloc.git")
105-
endif()
103+
if(UMF_DISABLE_HWLOC)
104+
message(STATUS "hwloc is disabled, hence OS provider, memtargets, "
105+
"topology discovery, examples won't be available!")
106+
else()
107+
if(NOT DEFINED UMF_HWLOC_REPO)
108+
set(UMF_HWLOC_REPO "https://github.com/open-mpi/hwloc.git")
109+
endif()
106110

107-
if(NOT DEFINED UMF_HWLOC_TAG)
108-
set(UMF_HWLOC_TAG hwloc-2.10.0)
109-
endif()
111+
if(NOT DEFINED UMF_HWLOC_TAG)
112+
set(UMF_HWLOC_TAG hwloc-2.10.0)
113+
endif()
110114

111-
if(NOT UMF_LINK_HWLOC_STATICALLY)
112-
if(NOT UMF_DISABLE_HWLOC)
115+
if(NOT UMF_LINK_HWLOC_STATICALLY)
113116
pkg_check_modules(LIBHWLOC hwloc>=2.3.0)
114117
if(NOT LIBHWLOC_FOUND)
115118
find_package(LIBHWLOC 2.3.0 REQUIRED hwloc)
@@ -119,86 +122,83 @@ if(NOT UMF_LINK_HWLOC_STATICALLY)
119122
set(DLL_PATH_LIST
120123
"${DLL_PATH_LIST};PATH=path_list_append:${LIBHWLOC_LIBRARY_DIRS}/../bin"
121124
)
122-
endif()
123-
# add PATH to DLL on Windows
124-
set(DLL_PATH_LIST
125-
"${DLL_PATH_LIST};PATH=path_list_append:${LIBHWLOC_LIBRARY_DIRS}/../bin"
126-
)
127-
elseif(WINDOWS AND NOT UMF_DISABLE_HWLOC)
128-
include(FetchContent)
129-
set(HWLOC_ENABLE_TESTING OFF)
130-
set(HWLOC_SKIP_LSTOPO ON)
131-
set(HWLOC_SKIP_TOOLS ON)
132-
133-
message(STATUS "Will fetch hwloc from ${UMF_HWLOC_REPO}")
134-
135-
FetchContent_Declare(
136-
hwloc_targ
137-
GIT_REPOSITORY ${UMF_HWLOC_REPO}
138-
GIT_TAG ${UMF_HWLOC_TAG}
139-
SOURCE_SUBDIR contrib/windows-cmake/ FIND_PACKAGE_ARGS)
140-
141-
FetchContent_GetProperties(hwloc_targ)
142-
if(NOT hwloc_targ_POPULATED)
143-
FetchContent_MakeAvailable(hwloc_targ)
144-
endif()
125+
elseif(WINDOWS)
126+
include(FetchContent)
127+
set(HWLOC_ENABLE_TESTING OFF)
128+
set(HWLOC_SKIP_LSTOPO ON)
129+
set(HWLOC_SKIP_TOOLS ON)
130+
131+
message(
132+
STATUS
133+
"Will fetch hwloc from ${UMF_HWLOC_REPO} (tag: ${UMF_HWLOC_TAG})"
134+
)
145135

146-
set(LIBHWLOC_INCLUDE_DIRS
147-
${hwloc_targ_SOURCE_DIR}/include;${hwloc_targ_BINARY_DIR}/include)
148-
set(LIBHWLOC_LIBRARY_DIRS
149-
${hwloc_targ_BINARY_DIR}/Release;${hwloc_targ_BINARY_DIR}/Debug)
136+
FetchContent_Declare(
137+
hwloc_targ
138+
GIT_REPOSITORY ${UMF_HWLOC_REPO}
139+
GIT_TAG ${UMF_HWLOC_TAG}
140+
SOURCE_SUBDIR contrib/windows-cmake/ FIND_PACKAGE_ARGS)
150141

151-
message(STATUS " LIBHWLOC_LIBRARIES = ${LIBHWLOC_LIBRARIES}")
152-
message(STATUS " LIBHWLOC_INCLUDE_DIRS = ${LIBHWLOC_INCLUDE_DIRS}")
153-
message(STATUS " LIBHWLOC_LIBRARY_DIRS = ${LIBHWLOC_LIBRARY_DIRS}")
154-
elseif(NOT UMF_DISABLE_HWLOC)
155-
include(FetchContent)
156-
message(STATUS "Will fetch hwloc from ${UMF_HWLOC_REPO}")
157-
158-
FetchContent_Declare(
159-
hwloc_targ
160-
GIT_REPOSITORY ${UMF_HWLOC_REPO}
161-
GIT_TAG ${UMF_HWLOC_TAG})
162-
163-
FetchContent_GetProperties(hwloc_targ)
164-
if(NOT hwloc_targ_POPULATED)
165-
FetchContent_MakeAvailable(hwloc_targ)
166-
endif()
142+
FetchContent_GetProperties(hwloc_targ)
143+
if(NOT hwloc_targ_POPULATED)
144+
FetchContent_MakeAvailable(hwloc_targ)
145+
endif()
146+
147+
set(LIBHWLOC_INCLUDE_DIRS
148+
${hwloc_targ_SOURCE_DIR}/include;${hwloc_targ_BINARY_DIR}/include)
149+
set(LIBHWLOC_LIBRARY_DIRS
150+
${hwloc_targ_BINARY_DIR}/Release;${hwloc_targ_BINARY_DIR}/Debug)
151+
else()
152+
include(FetchContent)
153+
message(
154+
STATUS
155+
"Will fetch hwloc from ${UMF_HWLOC_REPO} (tag: ${UMF_HWLOC_TAG})"
156+
)
167157

168-
add_custom_command(
169-
COMMAND ./autogen.sh
170-
WORKING_DIRECTORY ${hwloc_targ_SOURCE_DIR}
171-
OUTPUT ${hwloc_targ_SOURCE_DIR}/configure)
172-
add_custom_command(
173-
COMMAND
174-
./configure --prefix=${hwloc_targ_BINARY_DIR} --enable-static=yes
175-
--enable-shared=no --disable-libxml2 --disable-levelzero
176-
--disable-opencl --disable-cuda --disable-nvml CFLAGS=-fPIC
177-
CXXFLAGS=-fPIC
178-
WORKING_DIRECTORY ${hwloc_targ_SOURCE_DIR}
179-
OUTPUT ${hwloc_targ_SOURCE_DIR}/Makefile
180-
DEPENDS ${hwloc_targ_SOURCE_DIR}/configure)
181-
add_custom_command(
182-
COMMAND make
183-
WORKING_DIRECTORY ${hwloc_targ_SOURCE_DIR}
184-
OUTPUT ${hwloc_targ_SOURCE_DIR}/lib/libhwloc.la
185-
DEPENDS ${hwloc_targ_SOURCE_DIR}/Makefile)
186-
add_custom_command(
187-
COMMAND make install
188-
WORKING_DIRECTORY ${hwloc_targ_SOURCE_DIR}
189-
OUTPUT ${hwloc_targ_BINARY_DIR}/lib/libhwloc.a
190-
DEPENDS ${hwloc_targ_SOURCE_DIR}/lib/libhwloc.la)
191-
192-
add_custom_target(hwloc_prod
193-
DEPENDS ${hwloc_targ_BINARY_DIR}/lib/libhwloc.a)
194-
add_library(hwloc INTERFACE)
195-
target_link_libraries(hwloc
196-
INTERFACE ${hwloc_targ_BINARY_DIR}/lib/libhwloc.a)
197-
add_dependencies(hwloc hwloc_prod)
198-
199-
set(LIBHWLOC_LIBRARY_DIRS ${hwloc_targ_BINARY_DIR}/lib)
200-
set(LIBHWLOC_INCLUDE_DIRS ${hwloc_targ_BINARY_DIR}/include)
201-
set(LIBHWLOC_LIBRARIES ${hwloc_targ_BINARY_DIR}/lib/libhwloc.a)
158+
FetchContent_Declare(
159+
hwloc_targ
160+
GIT_REPOSITORY ${UMF_HWLOC_REPO}
161+
GIT_TAG ${UMF_HWLOC_TAG})
162+
163+
FetchContent_GetProperties(hwloc_targ)
164+
if(NOT hwloc_targ_POPULATED)
165+
FetchContent_MakeAvailable(hwloc_targ)
166+
endif()
167+
168+
add_custom_command(
169+
COMMAND ./autogen.sh
170+
WORKING_DIRECTORY ${hwloc_targ_SOURCE_DIR}
171+
OUTPUT ${hwloc_targ_SOURCE_DIR}/configure)
172+
add_custom_command(
173+
COMMAND
174+
./configure --prefix=${hwloc_targ_BINARY_DIR}
175+
--enable-static=yes --enable-shared=no --disable-libxml2
176+
--disable-levelzero CFLAGS=-fPIC CXXFLAGS=-fPIC
177+
WORKING_DIRECTORY ${hwloc_targ_SOURCE_DIR}
178+
OUTPUT ${hwloc_targ_SOURCE_DIR}/Makefile
179+
DEPENDS ${hwloc_targ_SOURCE_DIR}/configure)
180+
add_custom_command(
181+
COMMAND make
182+
WORKING_DIRECTORY ${hwloc_targ_SOURCE_DIR}
183+
OUTPUT ${hwloc_targ_SOURCE_DIR}/lib/libhwloc.la
184+
DEPENDS ${hwloc_targ_SOURCE_DIR}/Makefile)
185+
add_custom_command(
186+
COMMAND make install
187+
WORKING_DIRECTORY ${hwloc_targ_SOURCE_DIR}
188+
OUTPUT ${hwloc_targ_BINARY_DIR}/lib/libhwloc.a
189+
DEPENDS ${hwloc_targ_SOURCE_DIR}/lib/libhwloc.la)
190+
191+
add_custom_target(hwloc_prod
192+
DEPENDS ${hwloc_targ_BINARY_DIR}/lib/libhwloc.a)
193+
add_library(hwloc INTERFACE)
194+
target_link_libraries(hwloc
195+
INTERFACE ${hwloc_targ_BINARY_DIR}/lib/libhwloc.a)
196+
add_dependencies(hwloc hwloc_prod)
197+
198+
set(LIBHWLOC_LIBRARY_DIRS ${hwloc_targ_BINARY_DIR}/lib)
199+
set(LIBHWLOC_INCLUDE_DIRS ${hwloc_targ_BINARY_DIR}/include)
200+
set(LIBHWLOC_LIBRARIES ${hwloc_targ_BINARY_DIR}/lib/libhwloc.a)
201+
endif()
202202

203203
message(STATUS " LIBHWLOC_LIBRARIES = ${LIBHWLOC_LIBRARIES}")
204204
message(STATUS " LIBHWLOC_INCLUDE_DIRS = ${LIBHWLOC_INCLUDE_DIRS}")
@@ -414,12 +414,8 @@ if(UMF_BUILD_BENCHMARKS)
414414
add_subdirectory(benchmark)
415415
endif()
416416

417-
if(UMF_BUILD_EXAMPLES)
418-
if(NOT UMF_DISABLE_HWLOC)
419-
add_subdirectory(examples)
420-
else()
421-
message(WARNING "Examples cannot be build - hwloc disabled")
422-
endif()
417+
if(UMF_BUILD_EXAMPLES AND NOT UMF_DISABLE_HWLOC)
418+
add_subdirectory(examples)
423419
endif()
424420

425421
if(UMF_FORMAT_CODE_STYLE)

0 commit comments

Comments
 (0)