Skip to content

Commit 282f697

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

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

CMakeLists.txt

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,63 @@ elseif(UMF_BUILD_CUDA_PROVIDER)
427427
message(STATUS "CUDA_INCLUDE_DIRS = ${CUDA_INCLUDE_DIRS}")
428428
endif()
429429

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

919+
# Install Windows debug libraries
920+
add_custom_target(install-umf-libraries
921+
COMMAND
922+
${CMAKE_COMMAND}
923+
--install ${UMFD_INSTALL_DIR}
924+
DEPENDS umf-libraries)
925+
862926
# Configure uninstall commands
863927
configure_file("${PROJECT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
864928
"${PROJECT_BINARY_DIR}/cmake_uninstall.cmake" IMMEDIATE @ONLY)

cmake/helpers.cmake

Lines changed: 1 addition & 0 deletions
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)