-
Notifications
You must be signed in to change notification settings - Fork 131
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
Find g mock #130
Find g mock #130
Conversation
Why have you inserted all those spaces in if() and else() ? |
@konserw I edited the files with CLion and the spaces sneaked in when I reformated the file. I didn't recognize it because whitespace differences are turned of in my diff tool. If this is a problem I will reformat the files. |
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 contribution. I have added a few questions in this review.
In open source it is important to respect the same coding conventions, spaces, etc. as the rest of the project.
@konserw given that you contributed the latest changes to this file, can you take a look at this PR?
${CMAKE_THREAD_LIBS_INIT} | ||
) | ||
GTest::GTest | ||
) |
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.
Why this change?
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.
'Threads' is set as interface link library for GTest therefore the dependency is already set and it's not necessary to specify it again.
For the GTest driver the GTest main is not needed, therefore only the GTest library is set as dependency.
GTest::GTest | ||
GMock::GMock | ||
GMock::Main | ||
) |
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.
Is GMock::Main required because we require GTest for step definitions (without main) but GMock needs a main method to run our tests?
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.
Yes. A main (either gtest_main or gmock_main) is needed to run the tests and because gmock is used anyway I decided to use the gmock_main only.
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.
@meshell doesn't it make more sense to use gtest_main
/GTest::Main
in locations where GMock isn't required? I.e. do away with these variables completely and make the use of these specific to the target their linked into?
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.
@muggenhor I totally agree. I would also do it differently and would not use this variables at all. However I didn't want to change too many parts of the existing CMake files in this PR.
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 did something like that a while back as an experiment: https://github.com/muggenhor/cucumber-cpp/compare/master...link-depends-only, and it's big enough a change that it definitely belongs in a different PR. But it does depend on doing the same kind of change that you're doing happening first.
target_link_libraries(cucumber-cpp | ||
ws2_32 | ||
) | ||
endif(WIN32 AND NOT MSVC) |
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.
Is this required by MinGW or by all Windows compilers that are not MSVC like in this if statement?
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.
Actually I don't know if other compilers need this library as well. i only have MinGW and MSVC available on my windows machine. I know that MinGW requires it, but MSVC doesn't. However I think it would also work when the library is added on MSVC also. I will check that.
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'd be happy with if(MINGW)
(if I remember correctly) unless further evidence suggests that it's needed for all WIN32
compilers that are NOT MSVC
.
@paoloambrosio - Looks good to me, but I'm not CMake expert :) |
@konserw I will try to add Mingw to appveyor CI. But I will do it in a new pull request. Is this ok? |
Adding MinGW to AppVeyor makes sure that the build works on MinGW without testing is manually. I understand it's going to be quite painful and involve a lot of commits. What I suggest is to experiment with it in a separate branch in your repository, and add it to this PR when you are reasonably confident it will work :-) |
@paoloambrosio: Ok I will do that. |
If Boost is not compiled for MinGW on AppVeyor, I'd be OK without a MinGW build. Unfortunately this also means that any change might silently break it. I'm not a big fan of the build script downloading and compiling dependencies (like the current GoogleTest implementation). It is also not how the standard CMake scripts work. IMO anything related only to the CI build should be in the CI configuration ( |
After quick google search i think for we could install boost for mingw via MSYS2 pacman |
I had to do some minor changes in some CMake files as well, but finally I managed to add Mingw build to appveyor. |
This PR duplicates #109 btw. |
@muggenhor I can't see the duplication. Could you please explain. |
@meshell no duplication in code. I just meant that this PR seems to try to accomplish the same thing, so that they're mutually exclusive. |
@muggenhor I do not agree. This PR fixes the cmake files for building with MinGW under windows and it modifies the FindGMock.cmake file to only download and build googlemock and googletest when not already available (this was actually the main goal of this PR but the MinGW stuff took over a bit). PR #109 however adds ninja support and does not change the FindGMock the same way, or does 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.
I've got some questions and suggestions, but mostly it looks very well done. Nice work!
include(ExternalProject) | ||
|
||
if(MSVC) | ||
set(Suffix ".lib") |
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.
Why not use ${CMAKE_STATIC_LIBRARY_SUFFIX}
?
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.
Good point.
LOG_BUILD ON | ||
CMAKE_ARGS | ||
-Dgtest_disable_pthreads=${MINGW} | ||
${GTEST_CMAKE_ARGS} |
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.
Why don't you specify BUILD_BYPRODUCTS
here? E.g.:
BUILD_BYPRODUCTS
<BINARY_DIR>/${GTEST_LIBRARY_PREFIX}gtest${Suffix}
<BINARY_DIR>/${GTEST_LIBRARY_PREFIX}gtest_main${Suffix}
(same for other ExternalProject_Add
calls)
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 didn't want to change the existing code done by @konserw in the PR I just wanted to extend it. I could do it, but IMO it would be better to do all this CMake refactorings in a seperate PR
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 agree.
) | ||
|
||
|
||
add_dependencies(GTest::GTest gtest) |
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 you specify BUILD_BYPRODUCTS
you don't need these custom dependency declarations at all (as long as you use one of those byproducts in the library's IMPORT_LOCATION
).
PREFIX ${GMOCK_ROOT} | ||
INSTALL_COMMAND "" | ||
LOG_DOWNLOAD ON | ||
LOG_DOWNLOAD OFF |
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.
Why don't just leave it as is? It's not displayed on the terminal anyway, but if something goes wrong you'll now have a log file to look at. This is pretty relevant in e.g. containerized builds where sometimes people mess up with the networking.
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.
This is a mistake. I will fix that. Thanks
find_package_handle_standard_args(GMock DEFAULT_MSG GMOCK_LIBRARY GMOCK_INCLUDE_DIR GMOCK_MAIN_LIBRARY) | ||
|
||
include(CMakeFindDependencyMacro) | ||
find_dependency(Threads) |
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.
Just wondering here: what's the advantage of these two lines over the single: find_package(Threads REQUIRED)
(which also creates the Threads::Threads
target)? Is it maybe related to not being able to use find_package
in a FindXXX
module?
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.
Yes as far as I know you can not use find_package in FindXXX modules. This FindGMock.cmake is an adapted version of a recent FindGTest.cmake file plus the code from @konserw and this how its done in the FindGTest.cmake.
endif() | ||
|
||
set_target_properties(GMock::Main PROPERTIES | ||
INTERFACE_LINK_LIBRARIES "GMock::GMock" |
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.
Do you still want to link transitively to the non-main GMock on 1.7+ where the main version contains the same sources, just one more?
I would think that for 1.7 and beyond not specifying it on the link interface and instead only adding the same include directories as GMock::GMock
has to the interface include dirs would be the clean thing to do.
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.
This is how it's done in a recent FindGTest.cmake provided with CMake. That's why I didn't consider removing it.
@@ -35,3 +35,12 @@ endif() | |||
|
|||
add_library(cucumber-cpp-nomain STATIC ${CUKE_SOURCES}) | |||
add_library(cucumber-cpp STATIC ${CUKE_SOURCES} main.cpp) | |||
|
|||
if(MINGW) |
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 same should work for MSVC too (it does at work). So I suggest you try with if(WIN32)
instead.
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.
Please see the comments by @paoloambrosio for that.
@@ -23,7 +23,7 @@ if(GMOCK_FOUND) | |||
cuke_add_test(integration/HookRegistrationTest) | |||
cuke_add_test(integration/StepRegistrationTest) | |||
cuke_add_test(integration/TaggedHookRegistrationTest) | |||
if (NOT MSVC) | |||
if(NOT WIN32) |
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.
Have you tried running this with MinGW? Because I don't think there's anything to this test that should prevent it from running on Windows. (Just asking because I'm only noticing that this test is disabled for Windows just now).
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.
Yes I tried to run it and it failed. I suppose for the same reason as when built with MSVC, but I didn't investigate further. Maybe @paoloambrosio knows why this test fails (under MSVC)
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's been there for ages and I tried several times to understand why this fails on Windows but without success. I remember it crashes but can't remember how to be honest :-) Maybe we should create an issue on GitHub and put the link in a comment to that if statement.
) | ||
mark_as_advanced(GMOCK_INCLUDE_DIR) | ||
|
||
find_path(GTEST_INCLUDE_DIR gtest/gtest.h |
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'm assuming you're searching the content of the google-mock
Debian package here. Does this also work with the newer 1.8 google-mock
/googletest
packages (Ubuntu Trusty only provides 1.6)? Because I needed to do some hacking in the previous implementation of FindGMock.cmake
to be able to use those newer packages.
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.
Usually in a project where cucumber-cpp is used, also a unitttest framework is used, often this might be googletest/googlemock. Therefore my intention was to be able to use this existing (already compiled) version of googlemock and googletest and not compiling it again. I have to confess, that I din't try to use installed versions, i.e. debian packages. I will check that. Thanks for the hint.
@meshell because the underlying cause why Ninja builds don't work is because of a missing dependency declaration from the libraries to the Edit: actually you're right, it's not the same. #109 is making it safe to use the library filenames, your change is currently just stopping of using them. |
@@ -18,11 +42,15 @@ install: | |||
- gem install bundle | |||
- bundle install | |||
- bundle env | |||
- if "%build%"=="mingw" set PATH=%MINGW_ROOT%\bin;C:\msys64\usr\bin\;%PATH% | |||
- if "%build%"=="mingw" set MSYSTEM=%MSYSTEM% |
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 think this line does nothing (assigns variable to itself)
Once @konserw's latest comment is addressed and commits are squashed (it doesn't need to be one single commit but 10 is a bit too much) and the branch rebased (to run the CI on top of the latest master), I think it can be merged. Well done on the collaborative effort! 👍 |
6270a1f
to
96c2659
Compare
@paoloambrosio I removed the lines mentioned by @konserw and rebased it. It is ready to merge. |
This pull request fixes the cmake files for building with MinGW under windows. Further it modifies the FindGMock.cmake file to only download and build googlemock and googletest when not already available.
This pull request fixes the cmake files for building with MinGW under windows. Further it modifies the FindGMock.cmake file to only download and build googlemock and googletest when not already available.
Thanks everyone! @meshell for the great PR, @muggenhor and @konserw for the reviews |
This pull request fixes the cmake files for building with MinGW under windows.
Further it modifies the FindGMock.cmake file to only download and build googlemock and googletest when not already available. This is IMHO helpful, because usually you already have googletest and/or googlemock installed for your unit tests.