@@ -58,6 +58,8 @@ macro(umf_option)
5858 option (${ARGV} )
5959endmacro ()
6060
61+ # All CMake options have to be explicitly set in the build_umfd target's
62+ # configuration command
6163umf_option(UMF_BUILD_SHARED_LIBRARY "Build UMF as shared library" OFF )
6264umf_option(UMF_BUILD_LEVEL_ZERO_PROVIDER "Build Level Zero memory provider" ON )
6365umf_option(UMF_BUILD_CUDA_PROVIDER "Build CUDA memory provider" ON )
@@ -148,6 +150,8 @@ if(UMF_DEVELOPER_MODE)
148150 UMF_DEVELOPER_MODE=1)
149151endif ()
150152
153+ message (STATUS "CMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH} " )
154+
151155if (NOT UMF_BUILD_LIBUMF_POOL_JEMALLOC)
152156 set (UMF_POOL_JEMALLOC_ENABLED FALSE )
153157 set (JEMALLOC_FOUND FALSE )
@@ -293,6 +297,7 @@ else()
293297 set (HWLOC_ENABLE_TESTING OFF )
294298 set (HWLOC_SKIP_LSTOPO ON )
295299 set (HWLOC_SKIP_TOOLS ON )
300+ set (HWLOC_SKIP_INCLUDES ON )
296301
297302 FetchContent_Declare(
298303 hwloc_targ
@@ -436,25 +441,72 @@ elseif(UMF_BUILD_CUDA_PROVIDER)
436441 message (STATUS "CUDA_INCLUDE_DIRS = ${CUDA_INCLUDE_DIRS} " )
437442endif ()
438443
444+ # Build the umfd target in a separate directory with Debug configuration
439445if (WINDOWS AND UMF_USE_DEBUG_POSTFIX )
440- # Build debug umf library with the d suffix that is compiled with /MDd so
441- # users can link against it in debug builds.
442- set (CMAKE_DEBUG_POSTFIX d)
443-
446+ # The build_umfd target's configuration command requires to have
447+ # CMAKE_PREFIX_PATH with semicolons escaped
448+ string (JOIN "\; " UMFD_CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} )
444449 add_custom_target (
445- umfd ALL
446- COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target umf
447- --config Debug
448- COMMENT "Building debug umf library with the d suffix" )
450+ build_umfd ALL
451+ COMMAND
452+ ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR} " -S ${UMF_CMAKE_SOURCE_DIR}
453+ -B ${CMAKE_BINARY_DIR} /umfd_build -DCMAKE_BUILD_TYPE=Debug
454+ -DCMAKE_DEBUG_POSTFIX =d
455+ -DCMAKE_PREFIX_PATH="${UMFD_CMAKE_PREFIX_PATH} "
456+ -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
457+ -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
458+ -DUMF_USE_DEBUG_POSTFIX =OFF
459+ -DUMF_BUILD_SHARED_LIBRARY=${UMF_BUILD_SHARED_LIBRARY}
460+ -DUMF_BUILD_LEVEL_ZERO_PROVIDER=${UMF_BUILD_LEVEL_ZERO_PROVIDER}
461+ -DUMF_BUILD_CUDA_PROVIDER=${UMF_BUILD_CUDA_PROVIDER}
462+ -DUMF_BUILD_LIBUMF_POOL_JEMALLOC=${UMF_BUILD_LIBUMF_POOL_JEMALLOC}
463+ -DUMF_BUILD_TESTS=OFF -DUMF_BUILD_GPU_TESTS=OFF
464+ -DUMF_BUILD_BENCHMARKS=OFF -DUMF_BUILD_BENCHMARKS_MT=OFF
465+ -DUMF_BUILD_EXAMPLES=OFF -DUMF_BUILD_GPU_EXAMPLES=OFF
466+ -DUMF_BUILD_FUZZTESTS=OFF -DUMF_DISABLE_HWLOC=${UMF_DISABLE_HWLOC}
467+ -DUMF_LINK_HWLOC_STATICALLY=${UMF_LINK_HWLOC_STATICALLY}
468+ -DUMF_HWLOC_NAME=${UMF_HWLOC_NAME}
469+ -DUMF_INSTALL_RPATH=${UMF_INSTALL_RPATH} -DUMF_DEVELOPER_MODE=OFF
470+ -DUMF_FORMAT_CODE_STYLE=OFF -DUMF_TESTS_FAIL_ON_SKIP=OFF
471+ -DUMF_USE_ASAN=OFF -DUMF_USE_UBSAN=OFF -DUMF_USE_TSAN=OFF
472+ -DUMF_USE_MSAN=OFF -DUMF_USE_VALGRIND=OFF -DUMF_USE_COVERAGE=OFF
473+ -DUMF_PROXY_LIB_BASED_ON_POOL=${UMF_PROXY_LIB_BASED_ON_POOL}
474+ COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} /umfd_build --target
475+ umf --config Debug
476+ COMMENT
477+ "Configuring and building umfd.dll in a separate directory with Debug configuration"
478+ )
449479
450- # Copy built UMF libraries to the Release build subdirectory
480+ # Copy built UMF libraries to the main binary directory and remove
481+ # umfd_build
482+ if (CMAKE_CONFIGURATION_TYPES )
483+ # Multi-config generator (e.g., Visual Studio)
484+ set (UMFD_DLL_SRC "${CMAKE_BINARY_DIR} /umfd_build/bin/Debug/umfd.dll" )
485+ set (UMFD_LIB_SRC "${CMAKE_BINARY_DIR} /umfd_build/lib/Debug/umfd.lib" )
486+ set (UMFD_DLL "${CMAKE_BINARY_DIR} /bin/$<CONFIG>/umfd.dll" )
487+ set (UMFD_LIB "${CMAKE_BINARY_DIR} /lib/$<CONFIG>/umfd.lib" )
488+ else ()
489+ # Single-config generator (e.g., Ninja)
490+ set (UMFD_DLL_SRC "${CMAKE_BINARY_DIR} /umfd_build/bin/umfd.dll" )
491+ set (UMFD_LIB_SRC "${CMAKE_BINARY_DIR} /umfd_build/lib/umfd.lib" )
492+ set (UMFD_DLL "${CMAKE_BINARY_DIR} /bin/umfd.dll" )
493+ set (UMFD_LIB "${CMAKE_BINARY_DIR} /lib/umfd.lib" )
494+ endif ()
495+
496+ if (UMF_BUILD_SHARED_LIBRARY)
497+ add_custom_command (
498+ TARGET build_umfd
499+ COMMAND ${CMAKE_COMMAND} -E copy_if_different ${UMFD_DLL_SRC}
500+ ${UMFD_DLL}
501+ COMMENT "Copying umfd.dll to the main binary directory" )
502+ endif ()
451503 add_custom_command (
452- TARGET umfd
453- COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR} /bin/Debug/umfd.dll
454- ${CMAKE_BINARY_DIR} /bin/Release/umfd.dll
455- COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR} /lib/Debug/umfd.lib
456- ${CMAKE_BINARY_DIR} /lib/Release/umfd.lib
457- COMMENT "Copying debug libraries to the Release build directory" )
504+ TARGET build_umfd
505+ COMMAND ${CMAKE_COMMAND} -E copy_if_different ${UMFD_LIB_SRC}
506+ ${UMFD_LIB}
507+ COMMAND ${CMAKE_COMMAND} -E remove_directory
508+ ${CMAKE_BINARY_DIR} /umfd_build DEPENDS ${UMFD_DLL}
509+ COMMENT "Copying umfd.lib to the main library directory" )
458510endif ()
459511
460512# This build type check is not possible on Windows when CMAKE_BUILD_TYPE is not
@@ -849,12 +901,18 @@ endif()
849901# --------------------------------------------------------------------------- #
850902# Configure make install/uninstall and packages
851903# --------------------------------------------------------------------------- #
852- # Install umfd target
904+ # Install the umfd library files as part of the umfd component
853905if (WINDOWS AND UMF_USE_DEBUG_POSTFIX )
854- install (FILES ${CMAKE_BINARY_DIR} /bin/Debug/umfd.dll
855- DESTINATION ${CMAKE_INSTALL_BINDIR} )
856- install (FILES ${CMAKE_BINARY_DIR} /lib/Debug/umfd.lib
857- DESTINATION ${CMAKE_INSTALL_LIBDIR} )
906+ if (UMF_BUILD_SHARED_LIBRARY)
907+ install (
908+ FILES ${UMFD_DLL}
909+ DESTINATION ${CMAKE_INSTALL_BINDIR}
910+ COMPONENT umfd)
911+ endif ()
912+ install (
913+ FILES ${UMFD_LIB}
914+ DESTINATION ${CMAKE_INSTALL_LIBDIR}
915+ COMPONENT umfd)
858916endif ()
859917
860918install (FILES ${PROJECT_SOURCE_DIR} /LICENSE.TXT
0 commit comments