-
Notifications
You must be signed in to change notification settings - Fork 438
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
[BUILD] Fixing CMake to build GTest on Windows #1887
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #1887 +/- ##
==========================================
+ Coverage 87.15% 87.17% +0.03%
==========================================
Files 166 166
Lines 4777 4777
==========================================
+ Hits 4163 4164 +1
+ Misses 614 613 -1 |
well it seems that even with this change the code still doesn't compile, it can't seem to find the vcpkg libraries afterwards. I might just experiment with including GTest manually like how it is done for linux (just including .so files instead of .a files) |
Wondering whether the vcpkg packages were installed correctly to <repo_root>\tools\vcpkg? The vcpkg is added to current CMake search path as below. |
@ThomsonTan the vcpkg root was the issue, it would find it on first install but not on consecutive runs. Now I got my code to compile, but the test cases fail. Most likely due to GMOCK_LIB dependency. I couldn't find a vcpkg dependency of something that is similar to libgmock-dev that allowed me to get it to work on linux... |
What is the failure error in tests ? gmock should be installed as part of gtest installation using vcpkg. |
It works now. Only one failed test, which is also what showed up in my linux tests. Setting the toolchain file so late in the build process seems to not have an effect on finding proper packages, so I just set it manually under cmake-gui. Not ideal, but if there are any better solutions let me know! |
@bachittle - Can you fix the CLA, so that it can be reviewed and merged? |
It says that EasyCLA check passed, but now there are other CICD issues... |
CMakeLists.txt
Outdated
# set(CMAKE_TOOLCHAIN_FILE | ||
# ${CMAKE_CURRENT_SOURCE_DIR}/tools/vcpkg/scripts/buildsystems/vcpkg.cmake | ||
# PARENT_SCOPE) | ||
message("Make sure that vcpkg.cmake is set as the CMAKE_TOOLCHAIN_FILE at the START of the cmake build process! |
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.
Can we print this message only when we do not set toolchain file?
if(NOT CMAKE_TOOLCHAIN_FILE)
message(WARNING "Make sure that vcpkg.cmake is set as the CMAKE_TOOLCHAIN_FILE at the START of the cmake build process!
Can be command-line arg (cmake -DCMAKE_TOOLCHAIN_FILE=...) or set in your editor of choice.")
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.
The issue is the cmakefile tries to set the CMAKE_TOOLCHAIN_FILE in the cache at the start. This does not work unless its at the very start of the build process.
So its set, but it wasn't detecting my vcpkg unless I set it manually using cmake -DCMAKE_TOOLCHAIN_FILE=...
It may have to do with the submodules thinking the source directory is different, but gtest was not getting detected even after running install_windows_deps()
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.
If we use cmake -DCMAKE_TOOLCHAIN_FILE=...
to set toolchain, we should also replace NOT DEFINED CMAKE_TOOLCHAIN_FILE
by (NOT DEFINED CMAKE_TOOLCHAIN_FILE AND NOT DEFINED CACHE{CMAKE_TOOLCHAIN_FILE})
, or maybe NOT CMAKE_TOOLCHAIN_FILE
for short.
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 can also just be removed entirely since it doesn't work
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.
Sorry for my mistake, DEFINED <VAR NAME>
can also be used to check cached variables.
LGTM after format problem is solved.Thanks for your contribution.
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.
hmm the ci format is still failing, any reason as to why?
Hi @bachittle, could you please also take a look at my comment here?
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.
sorry I didn't see this, will take a look. The ci format isn't failing anymore, though.
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 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 @bachittle. This does confirm that OTLP is not enabled. Instead of commenting out the set of CMAKE_TOOLCHAIN_FILE
, can we add a line like below in the call after find_package(GTest REQUIRED)
in the same file?
opentelemetry-cpp/CMakeLists.txt
Line 331 in 5046443
include(${CMAKE_TOOLCHAIN_FILE}) |
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 tried this and it still failed, check latest commit: 2bd872b. Let me know if I should try putting this somewhere else.
hmm the ci format is still failing, any reason as to why? |
Here is the diff. Have you run cmake-format on code? If so, the version of cmake-format could make a difference. |
Please fix the remaining CI failure about cmake-format. This can be done by:
In this case, there are just two lines to adjust. |
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.
Almost there, cmake-format needs 2 more spaces.
Changes
Trying to compile with CMake on Windows. It breaks because of the Required clause. Removing it gets it working and installs required vcpkg files.
some improvements to consider:
CHANGELOG.md
updated for non-trivial changes (change is trivial)