Skip to content

Commit 1feb92c

Browse files
PatKaminkbenzie
andcommitted
Install Windows debug libraries with postfix
Co-authored-by: Kenneth Benzie (Benie) <[email protected]>
1 parent 3e2d042 commit 1feb92c

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

Diff for: CMakeLists.txt

+59-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ set(UMF_INSTALL_RPATH
8989
"Set the runtime search path to the directory with dependencies (e.g. hwloc)"
9090
)
9191

92-
umf_option(UMF_USE_DEBUG_POSTFIX "Add a 'd' postfix to Windows debug libraries" OFF)
92+
umf_option(UMF_USE_DEBUG_POSTFIX "Add a 'd' postfix to Windows debug libraries"
93+
OFF)
9394
umf_option(UMF_DEVELOPER_MODE "Enable additional developer checks" OFF)
9495
umf_option(
9596
UMF_FORMAT_CODE_STYLE
@@ -427,6 +428,57 @@ elseif(UMF_BUILD_CUDA_PROVIDER)
427428
message(STATUS "CUDA_INCLUDE_DIRS = ${CUDA_INCLUDE_DIRS}")
428429
endif()
429430

431+
if(WINDOWS)
432+
# Build debug libraries with the d suffix that are compiled with /MDd so
433+
# users can link against these in debug builds.
434+
include(ExternalProject)
435+
set(UMFD_BINARY_DIR ${CMAKE_BINARY_DIR}/umfd)
436+
set(UMFD_INSTALL_DIR ${UMFD_BINARY_DIR}/install)
437+
438+
ExternalProject_Add(
439+
umfd
440+
SOURCE_DIR ${PROJECT_SOURCE_DIR}
441+
BINARY_DIR ${UMFD_BINARY_DIR}
442+
INSTALL_DIR ${UMFD_INSTALL_DIR}
443+
INSTALL_COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --target
444+
install-umf-libraries
445+
CMAKE_CACHE_ARGS
446+
-DCMAKE_BUILD_TYPE=DEBUG
447+
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
448+
# Enable d suffix on libraries
449+
-DUMF_USE_DEBUG_POSTFIX=ON
450+
# Don't build unnecessary targets in subbuild.
451+
-DUMF_BUILD_EXAMPLES=OFF
452+
-DUMF_BUILD_TESTS=OFF
453+
# Inherit settings from parent build.
454+
-DUMF_BUILD_SHARED_LIBRARY=${UMF_BUILD_SHARED_LIBRARY}
455+
-DUMF_BUILD_LEVEL_ZERO_PROVIDER=${UMF_BUILD_LEVEL_ZERO_PROVIDER}
456+
-DUMF_BUILD_CUDA_PROVIDER=${UMF_BUILD_CUDA_PROVIDER}
457+
-DUMF_BUILD_LIBUMF_POOL_JEMALLOC=${UMF_BUILD_LIBUMF_POOL_JEMALLOC}
458+
-DUMF_DISABLE_HWLOC=${UMF_DISABLE_HWLOC}
459+
-DUMF_LINK_HWLOC_STATICALLY=${UMF_LINK_HWLOC_STATICALLY}
460+
-DUMF_HWLOC_NAME=${UMF_HWLOC_NAME}
461+
-DUMF_INSTALL_RPATH=${UMF_INSTALL_RPATH})
462+
463+
# Copy debug runtime libraries to the parent build directory
464+
set(UMFD_FILES_TO_COPY)
465+
list(APPEND UMFD_COPY_FILES ${PROJECT_BINARY_DIR}/bin/umfd.dll
466+
${PROJECT_BINARY_DIR}/lib/umfd.lib)
467+
add_custom_command(
468+
OUTPUT ${PROJECT_BINARY_DIR}/bin/umfd.dll
469+
${PROJECT_BINARY_DIR}/lib/umfd.lib
470+
COMMAND ${CMAKE_COMMAND} -E copy ${UMFD_INSTALL_DIR}/bin/umfd.dll
471+
${PROJECT_BINARY_DIR}/bin/umfd.dll
472+
COMMAND ${CMAKE_COMMAND} -E copy ${UMFD_INSTALL_DIR}/lib/umfd.lib
473+
${PROJECT_BINARY_DIR}/lib/umfd.lib)
474+
475+
add_custom_target(copy-umfd-files DEPENDS ${UMFD_COPY_FILES})
476+
add_dependencies(copy-umfd-files umfd)
477+
endif()
478+
479+
# Target with all UMF libraries added with add_umf_library()
480+
add_custom_target(umf-libraries)
481+
430482
# This build type check is not possible on Windows when CMAKE_BUILD_TYPE is not
431483
# set, because in this case the build type is determined after a CMake
432484
# configuration is done (at the build time)
@@ -859,6 +911,12 @@ install(FILES ${PROJECT_BINARY_DIR}/cmake/${PROJECT_NAME}-config.cmake
859911
${PROJECT_BINARY_DIR}/cmake/${PROJECT_NAME}-config-version.cmake
860912
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
861913

914+
# Install Windows debug libraries
915+
add_custom_target(
916+
install-umf-libraries
917+
COMMAND ${CMAKE_COMMAND} --install ${UMFD_INSTALL_DIR}
918+
DEPENDS umf-libraries)
919+
862920
# Configure uninstall commands
863921
configure_file("${PROJECT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
864922
"${PROJECT_BINARY_DIR}/cmake_uninstall.cmake" IMMEDIATE @ONLY)

Diff for: cmake/helpers.cmake

+1
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ function(add_umf_library)
395395
if(WINDOWS AND UMF_USE_DEBUG_POSTFIX)
396396
set_target_properties(${ARG_NAME} PROPERTIES DEBUG_POSTFIX d)
397397
endif()
398+
add_dependencies(umf-libraries ${ARG_NAME})
398399
endfunction()
399400

400401
# Add sanitizer ${flag}, if it is supported, for both C and C++ compiler

0 commit comments

Comments
 (0)