From 1dd392c8bd1f3b643c00d461c4637c951368e7ff Mon Sep 17 00:00:00 2001 From: Patryk Kaminski Date: Fri, 21 Mar 2025 15:47:52 +0100 Subject: [PATCH] Build and install umfd debug library on Windows when UMF_USE_DEBUG_POSTFIX CMake option is set. --- .github/workflows/reusable_basic.yml | 3 +++ CMakeLists.txt | 31 ++++++++++++++++++++++++++++ test/test_installation.py | 16 +++++++++++++- 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/.github/workflows/reusable_basic.yml b/.github/workflows/reusable_basic.yml index 41ce4b385..816c45a7a 100644 --- a/.github/workflows/reusable_basic.yml +++ b/.github/workflows/reusable_basic.yml @@ -241,6 +241,7 @@ jobs: shared_library: 'ON' level_zero_provider: 'ON' cuda_provider: 'ON' + umfd_lib: 'ON' - os: 'windows-2022' build_type: Release compiler: {c: cl, cxx: cl} @@ -289,6 +290,7 @@ jobs: -DUMF_BUILD_LEVEL_ZERO_PROVIDER=${{matrix.level_zero_provider}} -DUMF_BUILD_CUDA_PROVIDER=${{matrix.cuda_provider}} -DUMF_TESTS_FAIL_ON_SKIP=ON + -DUMF_USE_DEBUG_POSTFIX=${{matrix.umfd_lib}} - name: Build UMF run: cmake --build ${{env.BUILD_DIR}} --config ${{matrix.build_type}} -j $Env:NUMBER_OF_PROCESSORS @@ -307,6 +309,7 @@ jobs: ${{matrix.shared_library == 'ON' && '--proxy' || '' }} --umf-version ${{env.UMF_VERSION}} ${{ matrix.shared_library == 'ON' && '--shared-library' || ''}} + ${{ matrix.umfd_lib == 'ON' && '--umfd-lib' || ''}} - name: check /DEPENDENTLOADFLAG in umf.dll if: ${{matrix.shared_library == 'ON' && matrix.compiler.cxx == 'cl'}} diff --git a/CMakeLists.txt b/CMakeLists.txt index ef2658fd9..8e98b9ef8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -89,6 +89,8 @@ set(UMF_INSTALL_RPATH "Set the runtime search path to the directory with dependencies (e.g. hwloc)" ) +umf_option(UMF_USE_DEBUG_POSTFIX "Add a 'd' postfix to Windows debug libraries" + OFF) umf_option(UMF_DEVELOPER_MODE "Enable additional developer checks" OFF) umf_option( UMF_FORMAT_CODE_STYLE @@ -426,6 +428,27 @@ elseif(UMF_BUILD_CUDA_PROVIDER) message(STATUS "CUDA_INCLUDE_DIRS = ${CUDA_INCLUDE_DIRS}") endif() +if(WINDOWS AND UMF_USE_DEBUG_POSTFIX) + # Build debug umf library with the d suffix that is compiled with /MDd so + # users can link against it in debug builds. + set(CMAKE_DEBUG_POSTFIX d) + + add_custom_target( + umfd ALL + COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target umf + --config Debug + COMMENT "Building debug umf library with the d suffix") + + # Copy built UMF libraries to the Release build subdirectory + add_custom_command( + TARGET umfd + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/bin/Debug/umfd.dll + ${CMAKE_BINARY_DIR}/bin/Release/umfd.dll + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/lib/Debug/umfd.lib + ${CMAKE_BINARY_DIR}/lib/Release/umfd.lib + COMMENT "Copying debug libraries to the Release build directory") +endif() + # This build type check is not possible on Windows when CMAKE_BUILD_TYPE is not # set, because in this case the build type is determined after a CMake # configuration is done (at the build time) @@ -818,6 +841,14 @@ endif() # --------------------------------------------------------------------------- # # Configure make install/uninstall and packages # --------------------------------------------------------------------------- # +# Install umfd target +if(WINDOWS AND UMF_USE_DEBUG_POSTFIX) + install(FILES ${CMAKE_BINARY_DIR}/bin/Debug/umfd.dll + DESTINATION ${CMAKE_INSTALL_BINDIR}) + install(FILES ${CMAKE_BINARY_DIR}/lib/Debug/umfd.lib + DESTINATION ${CMAKE_INSTALL_LIBDIR}) +endif() + install(FILES ${PROJECT_SOURCE_DIR}/LICENSE.TXT DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/doc/${PROJECT_NAME}/") install( diff --git a/test/test_installation.py b/test/test_installation.py index ef30ac759..ff494101f 100644 --- a/test/test_installation.py +++ b/test/test_installation.py @@ -41,6 +41,7 @@ def __init__( proxy: bool, pools: List[str], umf_version: Version, + umfd_lib: bool, ): self.workspace_dir = workspace_dir self.build_dir = build_dir @@ -50,6 +51,7 @@ def __init__( self.proxy = proxy self.pools = pools self.umf_version = umf_version + self.umfd_lib = umfd_lib self.match_list = self._create_match_list() def _create_match_list(self) -> List[str]: @@ -74,10 +76,14 @@ def _create_match_list(self) -> List[str]: lib_prefix = "lib" bin = [] - if platform.system() == "Windows" and (self.shared_library or self.proxy): + if platform.system() == "Windows" and ( + self.shared_library or self.proxy or self.umfd_lib + ): bin.append("bin") if self.shared_library: bin.append("bin/umf.dll") + if self.umfd_lib: + bin.append("bin/umfd.dll") if self.proxy: bin.append("bin/umf_proxy.dll") @@ -101,6 +107,8 @@ def _create_match_list(self) -> List[str]: lib.append(f"lib/{lib_prefix}{pool}.{lib_ext_static}") if self.shared_library: lib.append(f"lib/{lib_prefix}umf.{lib_ext_shared}") + if platform.system() == "Windows" and self.umfd_lib: + lib.append(f"lib/{lib_prefix}umfd.{lib_ext_shared}") if platform.system() == "Linux": lib.append( @@ -283,6 +291,11 @@ def parse_arguments(self) -> argparse.Namespace: action="store", help="Current version of the UMF, e.g. 1.0.0", ) + self.parser.add_argument( + "--umfd-lib", + action="store_true", + help="Add this argument if the UMF was built with the umfd library", + ) return self.parser.parse_args() def run(self) -> None: @@ -306,6 +319,7 @@ def run(self) -> None: self.args.proxy, pools, umf_version, + self.args.umfd_lib, ) print("Installation test - BEGIN", flush=True)