-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[cmake] Refactor DIA SDK detection into FindDIASDK module #160354
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,77 @@ | ||||||||
| # Finds the Microsoft DIA SDK and sets DIASDK_FOUND and related variables. | ||||||||
| # | ||||||||
| # This module is intended to be used both internally by LLVM's build system and | ||||||||
| # by consuming projects when loading LLVMConfig.cmake. | ||||||||
| # | ||||||||
| # LLVM_WINSYSROOT may be set for locating the DIA SDK. | ||||||||
| # | ||||||||
| # If successful, the following variables will be defined: | ||||||||
| # DIASDK_FOUND | ||||||||
| # DIASDK_INCLUDE_DIR | ||||||||
| # DIASDK_LIBRARIES | ||||||||
| # | ||||||||
| # Additionally, the following import target will be defined: | ||||||||
| # DIASDK::Diaguids | ||||||||
|
|
||||||||
| if(NOT WIN32) | ||||||||
| set(DIASDK_FOUND FALSE) | ||||||||
| return() | ||||||||
| endif() | ||||||||
|
|
||||||||
| if(LLVM_WINSYSROOT) | ||||||||
| set(MSVC_DIA_SDK_DIR "${LLVM_WINSYSROOT}/DIA SDK" CACHE PATH | ||||||||
| "Path to the DIA SDK") | ||||||||
| elseif($ENV{VSINSTALLDIR}) | ||||||||
| set(MSVC_DIA_SDK_DIR "$ENV{VSINSTALLDIR}DIA SDK" CACHE PATH | ||||||||
compnerd marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
| "Path to the DIA SDK") | ||||||||
| elseif(NOT DEFINED MSVC_DIA_SDK_DIR) | ||||||||
| message(STATUS "MSVC_DIA_SDK_DIR not set, and could not be inferred. DIA SDK " | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this use
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO probably not, because the usage of By "speculative" I mean a user without DIA SDK installed may have relevant variables unset, yet control still enters this module from this part of the code: llvm-project/llvm/cmake/config-ix.cmake Lines 628 to 630 in 46c98b8
|
||||||||
| "may not be found.") | ||||||||
| endif() | ||||||||
|
|
||||||||
| find_path(DIASDK_INCLUDE_DIR | ||||||||
| NAMES dia2.h | ||||||||
| PATHS "${MSVC_DIA_SDK_DIR}/include" | ||||||||
| NO_DEFAULT_PATH | ||||||||
| NO_CMAKE_FIND_ROOT_PATH | ||||||||
| ) | ||||||||
|
|
||||||||
| if(IS_DIRECTORY "${MSVC_DIA_SDK_DIR}") | ||||||||
| set(_DIA_SDK_LIB_DIR "${MSVC_DIA_SDK_DIR}/lib") | ||||||||
|
|
||||||||
| if("$ENV{VSCMD_ARG_TGT_ARCH}" STREQUAL "arm64") | ||||||||
| set(_DIA_SDK_LIB_DIR "${_DIA_SDK_LIB_DIR}/arm64") | ||||||||
| elseif("$ENV{VSCMD_ARG_TGT_ARCH}" STREQUAL "arm") | ||||||||
| set(_DIA_SDK_LIB_DIR "${_DIA_SDK_LIB_DIR}/arm") | ||||||||
| elseif(CMAKE_SIZEOF_VOID_P EQUAL 8) | ||||||||
| set(_DIA_SDK_LIB_DIR "${_DIA_SDK_LIB_DIR}/amd64") | ||||||||
| endif() | ||||||||
|
|
||||||||
| find_library(DIASDK_LIBRARIES | ||||||||
| NAMES diaguids | ||||||||
| PATHS "${_DIA_SDK_LIB_DIR}" | ||||||||
| NO_DEFAULT_PATH | ||||||||
| NO_CMAKE_FIND_ROOT_PATH | ||||||||
| ) | ||||||||
| endif() | ||||||||
|
|
||||||||
| include(FindPackageHandleStandardArgs) | ||||||||
| find_package_handle_standard_args( | ||||||||
| DIASDK | ||||||||
| FOUND_VAR | ||||||||
| DIASDK_FOUND | ||||||||
| REQUIRED_VARS | ||||||||
| DIASDK_INCLUDE_DIR | ||||||||
| DIASDK_LIBRARIES | ||||||||
| ) | ||||||||
| mark_as_advanced(DIASDK_INCLUDE_DIR DIASDK_LIBRARIES) | ||||||||
|
|
||||||||
| if(DIASDK_FOUND) | ||||||||
| if(NOT TARGET DIASDK::Diaguids) | ||||||||
| add_library(DIASDK::Diaguids UNKNOWN IMPORTED) | ||||||||
| set_target_properties(DIASDK::Diaguids PROPERTIES | ||||||||
| IMPORTED_LOCATION "${DIASDK_LIBRARIES}" | ||||||||
| INTERFACE_INCLUDE_DIRECTORIES "${DIASDK_INCLUDE_DIR}" | ||||||||
| ) | ||||||||
| endif() | ||||||||
| endif() | ||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be restricted to WIN32?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't have to, because DIA SDK will not be found anyway if we're not building for WIN32 (which, despite its name, covers the entire set of Windows targets). As far as this project is concerned, all
find(DIASDK)logic is guarded byLLVM_ENABLE_DIA_SDK(as it should), which in turn is conditioned onMSVC, so I don't really expect this early return to take effect.Open to remove/update this if you find this unnecessary/inaccurate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that conditional on
MSVCis correct, this is not dependent on the MSVC generator nor the MSVC compiler, but rather if we are building for Windows. That said, the guard here is just avoid the unnecessary stats, which is a nice touch.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There seems to be some old discussion about this back when the relevant part of the code was introduced:
I agree that technically it's only the target platform that's relevant, but having played with it a bit more, it seems that the problem is not with DIA SDK, but rather with LLVM's DIA implementation (see cffff26 and its commit message). It relies on the ATL (
<atlbase.h>) which is largely dependent on MS syntax like SEH__try/__except. (Though it could technically work if the non-MSVC-like compiler happens to support it?)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason I raised this is the cross-compiling scenario—that is building LLVM for Windows on other platforms—which is something we're actively experimenting with. However, based on my experiments
WIN32should be set if CMake is configured correctly so this check shouldn't pose a problem.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the context and confirmation! Yes, I believe that should be the case, which is suggested by CMake's documentation on this variable 1. I'll keep the
WIN32guard here then.Footnotes
https://cmake.org/cmake/help/latest/variable/WIN32.html ↩