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

Fix SOURCE_DIR in HandleGTest.cmake #703

Merged
merged 2 commits into from
Oct 13, 2018
Merged

Fix SOURCE_DIR in HandleGTest.cmake #703

merged 2 commits into from
Oct 13, 2018

Conversation

olzhabay
Copy link
Contributor

If benchmark added as cmake subproject, HandleGTest throws an error as ${CMAKE_SOURCE_DIR} does return absolute source dir.
Change it to ${CMAKE_CURRENT_SOURCE_DIR}, so it will be refering to it's own source dir.

If benchmark added as cmake subproject, HandleGTest throws an error as  does return absolute source dir.
Change it to , so it will be refering to it's own source dir.
@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

@olzhabay
Copy link
Contributor Author

CLA signed

@googlebot
Copy link

CLAs look good, thanks!

Copy link
Collaborator

@LebedevRI LebedevRI left a comment

Choose a reason for hiding this comment

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

I think this is correct.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 89.224% when pulling 62809ea on olzhabay:master into 8503dfe on google:master.

@AppVeyorBot
Copy link

Build benchmark 1521 completed (commit 15ead5e9da by @olzhabay)

@LebedevRI
Copy link
Collaborator

@olzhabay hm, thinking about it a bit more, you placed googletest into the benchmark/googletest?
And it is looking in yourproject'sroot/googletest.
I think the solution here is slightly incorrect.
I think there should be an option that will specify the path to the googletest directory.

@olzhabay
Copy link
Contributor Author

@olzhabay hm, thinking about it a bit more, you placed googletest into the benchmark/googletest?
And it is looking in yourproject'sroot/googletest.
I think the solution here is slightly incorrect.
I think there should be an option that will specify the path to the googletest directory.

Yes, googletest is place in benchmark/googletest.
If it would be place outside of benchmark directory, then it cannot execute add_subdirectory.
Elif it fails to find googletest in benchmark subdir, it will simply download gtest or find it in among system installs.
What you think @LebedevRI ?

@LebedevRI
Copy link
Collaborator

If it would be place outside of benchmark directory, then it cannot execute add_subdirectory.

I'm not sure i follow. add_subdirectory() works with both the absolute and relative paths.
Currently; it expects googletest to be placed in the root of top-level project.
You expect it to look for googletest in it's own subdirectory.
Those are two expectations, and both of them might be the expected thing to happen.

I think the location where it looks for googletest should be a config option, thus any expectation can be valid. Also, i think you need to pass ${CMAKE_CURRENT_BINRY_DIR}/googletest as binary_dir into that add_subdirectory() call.

@EricWF
Copy link
Contributor

EricWF commented Oct 13, 2018

This patch is correct.

CMAKE_SOURCE_DIR seems to always refer to the top level project directory,
while CMAKE_CURRENT_SOURCE_DIR refers to the most recent CMakeLists.txt being processed via add_subdirectory. Consider the following directory layout:

my_project/
  CMakeLists.txt
  benchmark/
    googletest/

Assuming my_project uses add_subdirectory(benchmark), then, when evaluating HandleGTest.cmake, the value of CMAKE_SOURCE_DIR will be my_project/ and CMAKE_CURRENT_SOURCE_DIR will be my_project/benchmark.

@LebedevRI
Copy link
Collaborator

I think i'm failing to convey my thoughts here.
The patch is correct if you, who use googlebenchmark as a subproject, expect for the googlebenchmark to look for the googletest in yourproject/googlebenchmark/googletest
The patch is not correct if you, who use googlebenchmark as a subproject, expect for the googlebenchmark to look for the googletest in yourproject/googletest.
I can see both cases being the expected behavior, thus i'm suggesting a config option.

@EricWF
Copy link
Contributor

EricWF commented Oct 13, 2018

I think i'm failing to convey my thoughts here.

Ah, OK. Yes we could do a lot better in supporting other configurations for googletest. But that's a separate discussion, and we should file a bug to track it.

This patch is "correct" because it brings the implementation inline with the currently documented behavior, which says:

This dependency can be provided two ways:

  • Checkout the Google Test sources into benchmark/googletest as above.
  • Otherwise, if -DBENCHMARK_DOWNLOAD_DEPENDENCIES=ON is specified during configuration, > the library will automatically download and build any required dependencies.

I'm merging this patch to make the behavior inline with the documentation. Lets continue the broader discussion elsewhere.

@EricWF EricWF merged commit 6097523 into google:master Oct 13, 2018
EricWF added a commit that referenced this pull request Oct 13, 2018
EricWF added a commit that referenced this pull request Oct 13, 2018
@EricWF
Copy link
Contributor

EricWF commented Oct 13, 2018

@olzhabay Could you re-open this with your latest changeset?

@olzhabay
Copy link
Contributor Author

@LebedevRI Totally got your point. I added this option. So, now it can look to both myproject's dir and googlebenchmark's dir, if one of them has an googletest

@olzhabay
Copy link
Contributor Author

@EricWF sure

@LebedevRI
Copy link
Collaborator

This patch is "correct" because it brings the implementation inline with the currently documented behavior, which says:

This dependency can be provided two ways:

  • Checkout the Google Test sources into benchmark/googletest as above.
  • Otherwise, if -DBENCHMARK_DOWNLOAD_DEPENDENCIES=ON is specified during configuration, > the library will automatically download and build any required dependencies.

I'm merging this patch to make the behavior inline with the documentation. Lets continue the broader discussion elsewhere.

Oh, i forgot about those docs. Ok, then that patch as it was is ok to go.

@LebedevRI Totally got your point. I added this option. So, now it can look to both myproject's dir and googlebenchmark's dir, if one of them has an googletest

Not really what i meant.
I was really talking about a config options, not hardcoding looking in two places.
But as @EricWF points out, that is not the scope of this PR.

@EricWF
Copy link
Contributor

EricWF commented Oct 13, 2018

@olzhabay OK, so lets land your original fix first. And then we can explore improvements as a follow up PR.

olzhabay added a commit to olzhabay/benchmark that referenced this pull request Oct 13, 2018
olzhabay added a commit to olzhabay/benchmark that referenced this pull request Oct 13, 2018
EricWF pushed a commit that referenced this pull request Oct 13, 2018
If benchmark added as cmake subproject, HandleGTest throws an error as  does return absolute source dir.
Change it to , so it will be refering to it's own source dir.

Also see PR #703.
EricWF pushed a commit to efcs/benchmark that referenced this pull request Nov 29, 2018
* Fix SOURCE_DIR in HandleGTest.cmake

If benchmark added as cmake subproject, HandleGTest throws an error as  does return absolute source dir.
Change it to , so it will be refering to it's own source dir.
EricWF added a commit to efcs/benchmark that referenced this pull request Nov 29, 2018
EricWF pushed a commit to efcs/benchmark that referenced this pull request Nov 29, 2018
If benchmark added as cmake subproject, HandleGTest throws an error as  does return absolute source dir.
Change it to , so it will be refering to it's own source dir.

Also see PR google#703.
JBakamovic pushed a commit to JBakamovic/benchmark that referenced this pull request Dec 6, 2018
* Fix SOURCE_DIR in HandleGTest.cmake

If benchmark added as cmake subproject, HandleGTest throws an error as  does return absolute source dir.
Change it to , so it will be refering to it's own source dir.
JBakamovic pushed a commit to JBakamovic/benchmark that referenced this pull request Dec 6, 2018
JBakamovic pushed a commit to JBakamovic/benchmark that referenced this pull request Dec 6, 2018
If benchmark added as cmake subproject, HandleGTest throws an error as  does return absolute source dir.
Change it to , so it will be refering to it's own source dir.

Also see PR google#703.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants