This is an archive of the discontinued LLVM Phabricator instance.

[cmake] Add LLVM_ENABLE_DIA_SDK option, and expose it in LLVMConfig
ClosedPublic

Authored by mgorny on Nov 2 2016, 12:15 PM.

Details

Summary

Add an explicit LLVM_ENABLE_DIA_SDK option to control building support
for DIA SDK-based debugging. Control its value to match whether DIA SDK
support was found and expose it in LLVMConfig (alike LLVM_ENABLE_ZLIB).

Its value is needed for LLDB to determine whether to run tests requiring
DIA support. Currently it is obtained from llvm/Config/config.h;
however, this file is not available for standalone builds. Following
this change, LLDB will be modified to use the value from LLVMConfig.

Diff Detail

Repository
rL LLVM

Event Timeline

mgorny updated this revision to Diff 76765.Nov 2 2016, 12:15 PM
mgorny retitled this revision from to [cmake] Rename HAVE_DIA_SDK to LLVM_ENABLE_DIA_SDK, and expose in LLVMConfig.
mgorny updated this object.
mgorny added reviewers: zturner, beanz.
mgorny added a subscriber: llvm-commits.
zturner added inline comments.Nov 4 2016, 10:44 PM
include/llvm/Config/config.h.cmake
42 ↗(On Diff #76765)

What's the difference between #cmakedefine01 and the syntax you've used here?

mgorny added inline comments.Nov 5 2016, 12:42 AM
include/llvm/Config/config.h.cmake
42 ↗(On Diff #76765)
  1. #cmakedefine01 converts any CMake bool to 0/1, mine relies on the 0/1 being set in CMake (it was already done like this).
  2. #cmakedefine01 does not support different #define and CMake variable name (or at least doesn't mention it in the docs). So if I were to continue using #cmakedefine01, I'd either have to define additional HAVE_DIA_SDK var in CMake, or rename the #define.
beanz edited edge metadata.Nov 7 2016, 1:21 PM

I think you're conflating two different types of variables, and I don't understand why.

LLVM_ENABLE_* variables are intended to be used for people to opt in or out of functionality. HAVE_* variables are for compiler checks against the system capabilities. Generally system capabilities shouldn't be captured in LLVM installed bits, which is what you're doing here.

I think the correct solution would be for you to perform the HAVE_DIA_SDK check in LLDB as well as LLVM. If the code is sufficiently complex, the LLVM version of the code could be abstracted into a module and re-used.

mgorny added a comment.Nov 7 2016, 1:48 PM

I think you're conflating two different types of variables, and I don't understand why.

LLVM_ENABLE_* variables are intended to be used for people to opt in or out of functionality. HAVE_* variables are for compiler checks against the system capabilities. Generally system capabilities shouldn't be captured in LLVM installed bits, which is what you're doing here.

I was considering this issue, and I've decided having user control over DIA SDK a worthwhile future effort. While this patch doesn't add it, it prepares the stuff to use it when it's added.

I think the correct solution would be for you to perform the HAVE_DIA_SDK check in LLDB as well as LLVM. If the code is sufficiently complex, the LLVM version of the code could be abstracted into a module and re-used.

DIA support enables some PDB debug format support in LLVM, that is unavailable otherwise. LLDB doesn't use DIA at all but the PDB tests require DIA support enabled during LLVM build. In this regard, it's similar to zlib support, upon which I based my patch.

mgorny updated this revision to Diff 78023.Nov 15 2016, 9:57 AM
mgorny retitled this revision from [cmake] Rename HAVE_DIA_SDK to LLVM_ENABLE_DIA_SDK, and expose in LLVMConfig to [cmake] Add LLVM_ENABLE_DIA_SDK option, and expose it in LLVMConfig.
mgorny updated this object.
mgorny edited edge metadata.

@beanz, how about this one? I've added an explicit LLVM_ENABLE_DIA_SDK option to let people control this explicitly.

If LLVM_ENABLE_DIA_SDK is On and you don't have a the SDK available that should be a fatal error. Treating it this way will also allow you to clean up some of the logic you're modifying in config-ix.cmake. Also gate the option under WIN32 so it only shows up if you're targeting windows.

With those changes I think this looks reasonable.

If LLVM_ENABLE_DIA_SDK is On and you don't have a the SDK available that should be a fatal error. Treating it this way will also allow you to clean up some of the logic you're modifying in config-ix.cmake.

I was thinking about that but it seems that other options (like LLVM_ENABLE_ZLIB) also are non-fatal like this. While I don't mind changing this, I'm not sure how to do it properly so that it doesn't suddenly fail for a lot of users.

One option would be to detect DIA SDK first, and base the default off it. However, I don't see doing that cleanly without moving the option to config-ix. Another would be to make the option 'trinary', and put some special default like 'AUTO' — i.e. AUTO meaning use if present, ON meaning fail if non-present.

Also gate the option under WIN32 so it only shows up if you're targeting windows.

WIN32 or MSVC? The code is currently using the latter.

beanz added a comment.Nov 15 2016, 1:09 PM

Moving the option into config-ix is fine, and basing the default off whether or not the SDK is present seems like a good way to handle this.

I'll defer to you whether WIN32 or MSVC is correct. WIN32 is for if you are targeting Windows, and MSVC is if your compiler is MSVC-compatible. WIN32 seems right to me, but I don't know.

zturner edited edge metadata.Nov 15 2016, 1:29 PM

Whether or not to use WIN32 or MSC_VER is always a tricky question. I would probably use MSC_VER in this case. Because WIN32 can be defined if you're using GCC / MinGW for example, and DIA won't won't work under those scenarios.

beanz added a comment.Nov 15 2016, 1:32 PM

Seems like MSVC is the right way to go. That will be defined if your compiler is MSVC or clang-cl.

mgorny updated this revision to Diff 78071.Nov 15 2016, 1:48 PM
mgorny updated this object.
mgorny edited edge metadata.

Ok, I think that'd be the best version so far.

The option is now exposed on MSVC only, and defaults to autodetection result. If it is forced ON and DIA SDK is not available, it errors out verbosely and explains the potential problem (based on comment above the check). On non-MSVC platforms, LLVM_ENABLE_DIA_SDK is set to 0 for interoperability.

I've also went ahead and changed the #define name. The LLDB patch is already approved, so I can commit both simultaneously.

mgorny marked 2 inline comments as done.Nov 15 2016, 1:49 PM

Oh, since I don't have MSVC, could someone test this on MSVC?

mgorny added a reviewer: rnk.Dec 29 2016, 9:44 AM
compnerd accepted this revision.Jan 2 2017, 9:53 AM
compnerd edited edge metadata.
compnerd added inline comments.
cmake/config-ix.cmake
443 ↗(On Diff #78071)

No spaces inside the parenthesis.

This revision is now accepted and ready to land.Jan 2 2017, 9:53 AM
mgorny marked an inline comment as done.Jan 2 2017, 10:29 AM
This revision was automatically updated to reflect the committed changes.