Skip to content
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

Merged
merged 0 commits into from
Jan 23, 2017
Merged

Find g mock #130

merged 0 commits into from
Jan 23, 2017

Conversation

meshell
Copy link
Contributor

@meshell meshell commented Dec 2, 2016

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.

@konserw
Copy link
Contributor

konserw commented Dec 4, 2016

Why have you inserted all those spaces in if() and else() ?

@meshell
Copy link
Contributor Author

meshell commented Dec 4, 2016

@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.

Copy link
Member

@paoloambrosio paoloambrosio left a 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
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change?

Copy link
Contributor Author

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
)
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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)
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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.

@konserw
Copy link
Contributor

konserw commented Dec 6, 2016

@paoloambrosio - Looks good to me, but I'm not CMake expert :)
@meshell - Could you add Mingw build to appveyor CI ?

@meshell
Copy link
Contributor Author

meshell commented Dec 8, 2016

@konserw I will try to add Mingw to appveyor CI. But I will do it in a new pull request. Is this ok?

@paoloambrosio
Copy link
Member

Adding MinGW to AppVeyor makes sure that the build works on MinGW without testing is manually.
Doing it as a separate PR would be like adding tests for code changes as a separate PR.

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 :-)

@meshell
Copy link
Contributor Author

meshell commented Dec 8, 2016

@paoloambrosio: Ok I will do that.
The problem are the boost libraries. I'm afraid, that the boost libraries must be built as part of the project. I already did that on an other project, but I don't know if it is the right approach for cucumber-cpp. I could do it similar to the approach done for the googlemock library, i.e. download and build in a FindBoost.cmake file, when not already available. However this means probably to copy the existing FindBoost.cmake provided with cmake. The other approach would be to have a separate target to build external dependencies. This target must than be build before everything else. What do you think, which approach I should try?

@paoloambrosio
Copy link
Member

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 (travis.yml, appveyor.yml) and scripts used by those (travis.sh). I would even move build steps in a scripts/ directory and have travis.yml and appveyor.yml call them instead of having code and configuration mixed.

@konserw
Copy link
Contributor

konserw commented Dec 12, 2016

After quick google search i think for we could install boost for mingw via MSYS2 pacman

@meshell
Copy link
Contributor Author

meshell commented Jan 3, 2017

I had to do some minor changes in some CMake files as well, but finally I managed to add Mingw build to appveyor.

@muggenhor
Copy link
Contributor

This PR duplicates #109 btw.

@meshell
Copy link
Contributor Author

meshell commented Jan 5, 2017

@muggenhor I can't see the duplication. Could you please explain.

@muggenhor
Copy link
Contributor

@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.

@meshell
Copy link
Contributor Author

meshell commented Jan 5, 2017

@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?
Why do you think it tries to accomplish the same?

Copy link
Contributor

@muggenhor muggenhor left a 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")
Copy link
Contributor

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}?

Copy link
Contributor Author

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}
Copy link
Contributor

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)

Copy link
Contributor Author

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

Copy link
Contributor

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)
Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Contributor Author

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)
Copy link
Contributor

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?

Copy link
Contributor Author

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"
Copy link
Contributor

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.

Copy link
Contributor Author

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)
Copy link
Contributor

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.

Copy link
Contributor Author

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)
Copy link
Contributor

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).

Copy link
Contributor Author

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)

Copy link
Member

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
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@muggenhor
Copy link
Contributor

muggenhor commented Jan 5, 2017

@meshell because the underlying cause why Ninja builds don't work is because of a missing dependency declaration from the libraries to the ExternalProject_Add targets. That's caused by using the ${GXXX_XXX_LIBRARIES} variables (which contain filenames, not target names) instead of the created library targets. You're fixing that part of the cause. If you additionally add the BUILD_BYPRODUCTS declarations then using the filenames would also work (and you'd also not need add_dependencies for the target case).

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%
Copy link
Contributor

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)

@paoloambrosio
Copy link
Member

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! 👍

@meshell meshell force-pushed the FindGMock branch 2 times, most recently from 6270a1f to 96c2659 Compare January 11, 2017 23:53
@meshell
Copy link
Contributor Author

meshell commented Jan 22, 2017

@paoloambrosio I removed the lines mentioned by @konserw and rebased it. It is ready to merge.
Thanks.

paoloambrosio added a commit that referenced this pull request Jan 23, 2017
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.
@paoloambrosio paoloambrosio merged commit 96c2659 into cucumber:master Jan 23, 2017
paoloambrosio added a commit that referenced this pull request Jan 23, 2017
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.
@paoloambrosio
Copy link
Member

Thanks everyone! @meshell for the great PR, @muggenhor and @konserw for the reviews

@meshell meshell deleted the FindGMock branch January 24, 2017 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants