-
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
Open
ZhongRuoyu
wants to merge
3
commits into
llvm:main
Choose a base branch
from
ZhongRuoyu:cmake-diaguids
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| # 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") | ||
| else() | ||
| 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") | ||
| 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() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 ↩