This is an archive of the discontinued LLVM Phabricator instance.

Fix FindZ3.cmake to support static libraries and Windows
ClosedPublic

Authored by tomasz-kaminski-sonarsource on Jul 16 2021, 12:20 AM.

Details

Summary

Use absolute path to link z3 to allow builds both on windows and linux since the library name is platform dependent for Z3 (libz3 on Windows and z3 on Linux) and MSVC does not recognized -L and -l options.
Fix CMAKE_CROSSCOMPILING that does not work correctly since it uses Z3_BUILD_VERSION instead of Z3_BUILD_NUMBER
Fix building with the static version of z3 library (supersedes D80227).

  • Build the Z3 version detection code as C++, since the static library brings in libstdc++ symbols
  • Detect threading support and link against threading, in the (likely) case Z3 was built with threads

Exposed compilation error from building a program that is used to detect z3 version in the warning message, to simplify troubleshooting.

Diff Detail

Event Timeline

tomasz-kaminski-sonarsource requested review of this revision.Jul 16 2021, 12:20 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 16 2021, 12:20 AM

Removed uncessary debug message.

tomasz-kaminski-sonarsource edited the summary of this revision. (Show Details)

It looks reasonable to me, but I can't say that I'm an expert here, and I'm definitely not a frequent z3 user.

I'm also not really comfortable with CMake, thus I'm requesting review from others who might have more experience on CMake/Windows stuff.
Don't mind me if I missed someone :D
On my side, this patch works on Linux x86_64 though, it did not break anything.

llvm/cmake/modules/FindZ3.cmake
17

Do you need to change it to cpp?

43–44

Ah, nice to see such an addition.

101–102

Oh, so it never matched. What is the purpose of this in that case?
If we did not recognize this sooner, I mean...

llvm/cmake/modules/FindZ3.cmake
17

Yes, for static version of z3, it's need to be linked with C++ runtime. Changing extension is the easiest way to signal cmake that this is meant to be C++ code.

101–102

If major.minor is greater than required (e.g. 4.8) the test passes despite ending up with "#define Z3_BUILD_NUMBER 11" as patch number, so once Z3 got minor updated, this does not cause issues.

JDevlieghere accepted this revision.Jul 28 2021, 10:26 AM

Not an expert on Z3 either, but the CMake logic looks sound to me. LGTM.

llvm/cmake/modules/FindZ3.cmake
12

I was curious why you're checking CMAKE_THREAD_LIBS_INIT instead of Threads_FOUND . Maybe include a comment saying that CMAKE_THREAD_LIBS_INIT may be empty if the thread functions are provided by the system libraries and no special flags are needed.

This revision is now accepted and ready to land.Jul 28 2021, 10:26 AM

Included sugguested comment regarding CMAKE_THREAD_LIBS_INIT.

Could you be possible to merge it for me, as I do not have a commit rights?
For the author information use:
Tomasz Kamiński
tomasz.kaminski@sonarsource.com

This revision was landed with ongoing or failed builds.Jul 29 2021, 1:57 AM
This revision was automatically updated to reflect the committed changes.