From 5c697c006f5738ce53be894fb63bf0a9675d5c1e Mon Sep 17 00:00:00 2001 From: Luke Street Date: Mon, 29 May 2023 09:55:24 -0400 Subject: [PATCH] Fix linking diaguids on Windows --- CMakeLists.txt | 2 ++ atdna/CMakeLists.txt | 9 ++++++++ cmake/FindDiaSDK.cmake | 51 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 cmake/FindDiaSDK.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 70eed37..354bddc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,8 @@ cmake_minimum_required(VERSION 3.10 FATAL_ERROR) # because of c++17 # Set MSVC runtime library flags from CMAKE_MSVC_RUNTIME_LIBRARY cmake_policy(SET CMP0091 NEW) +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake") + ################## # Athena Version # ################## diff --git a/atdna/CMakeLists.txt b/atdna/CMakeLists.txt index 361f034..af2e83a 100644 --- a/atdna/CMakeLists.txt +++ b/atdna/CMakeLists.txt @@ -64,6 +64,15 @@ else() endforeach () # Hack around link order issues target_link_libraries(clangAST INTERFACE LLVMFrontendOpenMP) + + # Fix linking diaguids on Windows + if (WIN32 AND TARGET LLVMDebugInfoPDB) + find_package(DiaSDK REQUIRED) + + get_target_property(target_dependencies LLVMDebugInfoPDB INTERFACE_LINK_LIBRARIES) + list(TRANSFORM target_dependencies REPLACE ".*diaguids.*" "${DIASDK_GUIDS_LIBRARY}") + set_property(TARGET LLVMDebugInfoPDB PROPERTY INTERFACE_LINK_LIBRARIES "${target_dependencies}") + endif () endif() # Offer the user the choice of overriding the installation directories diff --git a/cmake/FindDiaSDK.cmake b/cmake/FindDiaSDK.cmake new file mode 100644 index 0000000..b4819b7 --- /dev/null +++ b/cmake/FindDiaSDK.cmake @@ -0,0 +1,51 @@ +# From https://github.com/microsoft/DirectXShaderCompiler/blob/18c9e114f9c314f93e68fbc72ce207d4ed2e65ae/cmake/modules/FindDiaSDK.cmake +# This file is distributed under the University of Illinois Open Source + +# Find the DIA SDK path. +# It will typically look something like this: +# C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\DIA SDK\include + +# CMAKE_GENERATOR_INSTANCE has the location of Visual Studio used +# i.e. C:/Program Files (x86)/Microsoft Visual Studio/2019/Community +set(VS_PATH ${CMAKE_GENERATOR_INSTANCE}) +get_filename_component(VS_DIA_INC_PATH "${VS_PATH}/DIA SDK/include" ABSOLUTE CACHE) + +# Starting in VS 15.2, vswhere is included. +# Unclear what the right component to search for is, might be Microsoft.VisualStudio.Component.VC.DiagnosticTools +# (although the friendly name of that is C++ profiling tools). The toolset is the most likely target. +set(PROGRAMFILES_X86 "ProgramFiles(x86)") +execute_process( + COMMAND "$ENV{${PROGRAMFILES_X86}}/Microsoft Visual Studio/Installer/vswhere.exe" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath + OUTPUT_VARIABLE VSWHERE_LATEST + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE +) + +find_path(DIASDK_INCLUDE_DIR # Set variable DIASDK_INCLUDE_DIR + dia2.h # Find a path with dia2.h + HINTS "${VS_DIA_INC_PATH}" + HINTS "${VSWHERE_LATEST}/DIA SDK/include" + DOC "path to DIA SDK header files" + ) + + +if ((CMAKE_GENERATOR_PLATFORM STREQUAL "x64") OR ("${CMAKE_C_COMPILER_ARCHITECTURE_ID}" STREQUAL "x64")) + find_library(DIASDK_GUIDS_LIBRARY NAMES diaguids.lib HINTS ${DIASDK_INCLUDE_DIR}/../lib/amd64 ) +elseif ((CMAKE_GENERATOR_PLATFORM STREQUAL "ARM") OR ("${CMAKE_C_COMPILER_ARCHITECTURE_ID}" STREQUAL "ARM")) + find_library(DIASDK_GUIDS_LIBRARY NAMES diaguids.lib HINTS ${DIASDK_INCLUDE_DIR}/../lib/arm ) +elseif ((CMAKE_GENERATOR_PLATFORM MATCHES "ARM64.*") OR ("${CMAKE_C_COMPILER_ARCHITECTURE_ID}" MATCHES "ARM64.*")) + find_library(DIASDK_GUIDS_LIBRARY NAMES diaguids.lib HINTS ${DIASDK_INCLUDE_DIR}/../lib/arm64 ) +else ((CMAKE_GENERATOR_PLATFORM STREQUAL "x64") OR ("${CMAKE_C_COMPILER_ARCHITECTURE_ID}" STREQUAL "x64")) + find_library(DIASDK_GUIDS_LIBRARY NAMES diaguids.lib HINTS ${DIASDK_INCLUDE_DIR}/../lib ) +endif((CMAKE_GENERATOR_PLATFORM STREQUAL "x64") OR ("${CMAKE_C_COMPILER_ARCHITECTURE_ID}" STREQUAL "x64")) + +set(DIASDK_LIBRARIES ${DIASDK_GUIDS_LIBRARY}) +set(DIASDK_INCLUDE_DIRS ${DIASDK_INCLUDE_DIR}) + +include(FindPackageHandleStandardArgs) +# handle the QUIETLY and REQUIRED arguments and set DIASDK_FOUND to TRUE +# if all listed variables are TRUE +find_package_handle_standard_args(DiaSDK DEFAULT_MSG + DIASDK_LIBRARIES DIASDK_INCLUDE_DIR) + +mark_as_advanced(DIASDK_INCLUDE_DIRS DIASDK_LIBRARIES)