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

GOOGLETEST_VERSION is not defined in CMakeLists.txt #2950

Open
zhaoyang-star opened this issue Jul 16, 2020 · 14 comments
Open

GOOGLETEST_VERSION is not defined in CMakeLists.txt #2950

zhaoyang-star opened this issue Jul 16, 2020 · 14 comments
Assignees

Comments

@zhaoyang-star
Copy link

GOOGLETEST_VERSION is not defined in CMakeLists.txt. But it is used. So if I run command mkdir mybuild && cd mybuild && cmake .. the error happened:

CMake Warning at CMakeLists.txt:55 (project):
  VERSION keyword not followed by a value or was followed by a value that
  expanded to nothing.


CMake Error at CMakeLists.txt:130 (set_target_properties):
  set_target_properties called with incorrect number of arguments.


CMake Error at CMakeLists.txt:132 (set_target_properties):
  set_target_properties called with incorrect number of arguments.


-- Configuring incomplete, errors occurred!

So is there no GOOGLETEST_VERSION been defined in repo? I inserted one line set(GOOGLETEST_VERSION 1.9.0) and the error disappeared.

@ghost
Copy link

ghost commented Jul 18, 2020

Hello

I'm not sure the exact context
But I think that the error looks like you omitted the project version not googletest version

If you want to check googletest version
FindPkgConfig is a nice option because current FindGTest in CMake doesn't seems enough for this

You can find how to use FindPkgConfig as below and once you find the package with it then you might refer its version with variable GTest_VERSION

https://cmake.org/cmake/help/v3.0/module/FindPkgConfig.html

@derekmauro derekmauro self-assigned this Jul 21, 2020
@ghost
Copy link

ghost commented Aug 14, 2020

I'm sorry for the above comment
I could find GOOGLETEST_VERSION in https://github.com/google/googletest/blob/master/CMakeLists.txt#L11

(here in googletest/CMakeLists.txt, not in googletest/googletest/CMakeLists.txt)

@DinoStray
Copy link

always, I use XXX_VERSION like:

find_package(Libevent REQUIRED)
message(STATUS "Libevent version: ${Libevent_VERSION}")
find_package(ZeroMQ REQUIRED)
message(STATUS "ZeroMQ version: ${ZeroMQ_VERSION}")

But for gtest

find_package(GTest REQUIRED)
message(STATUS "GoogleTest version: ${GTest_VERSION}")

The GTest_VERSION is empty @hyukmyeong

@ghost
Copy link

ghost commented Aug 30, 2020

I'm not sure whether you can get GTest_VERSION with find_package()
How about checking if pkg_check_modules() works well for you first?

$ pkg-config gtest --modversion
1.9.0

$ cat /usr/local/lib/pkgconfig/gtest.pc  (or somewhere else)
libdir=/usr/local/lib
includedir=/usr/local/include

Name: gtest
Description: GoogleTest (without main() function)
Version: 1.9.0
URL: https://github.com/google/googletest
Libs: -L${libdir} -lgtest -pthread
Cflags: -I${includedir} -DGTEST_HAS_PTHREAD=1 -pthread

Additionally,
You even cannot get the version information with pkg-config in some cases
(this must be a very rare case..)

It's because as you see https://github.com/google/googletest/blob/master/googletest/cmake/gtest.pc.in
The version information in .pc comes from the variable PROJECT_VERSION
But it didn't work well with lower version cmake
until 60cf033 was merged

@justapig9020
Copy link

I am facing the same issue. The variable GOOGLETEST_VERSION defined in the CMakeLists.txt at the project root. The error will occur when trying to build project by cmake inside the googletest/googletest directory.

@ghost
Copy link

ghost commented Aug 31, 2020

Hello, @justapig9020

I think that you can build googletest only by turning off a build option (1.10.0 base)

$ cmake -DBUILD_GMOCK=OFF

And as zhaoyang-star said,
if you want to build from googletest/googletest
it looks like GOOGLETEST_VERSION should be added in the file googletest/googletest/CMakeLists.txt

@justapig9020
Copy link

Thanks, @hyukmyeong !
I followed a tutorial to build inside the googletest/googletest directory.
After your response I figure out that build from the root directory seems to be the right way.
Thanks a lot for your help on the very beginning of my googletest journey!

@ghost
Copy link

ghost commented Sep 10, 2020

@DinoStray

How about using CONFIG option like below?
(Because It seems like FindGTest module in CMake does not provide the version information)

find_package(GTest CONFIG REQUIRED)
message(STATUS "GTest_VERSION: ${GTest_VERSION}"

I hope that this works
and before that please check if you have config files or you should build and install googletest

$ ls -l /usr/local/lib/cmake/GTest/
GTestConfig.cmake  GTestConfigVersion.cmake  GTestTargets-noconfig.cmake  GTestTargets.cmake

@romanwerpachowski
Copy link

Thanks, @hyukmyeong !
I followed a tutorial to build inside the googletest/googletest directory.

The tutorial should be updated to avoid misleading users.

@ghost
Copy link

ghost commented Sep 14, 2020

@romanwerpachowski

Could you please review #3008 ?
whether it provides the proper information what we have discussed in this issue

@romanwerpachowski
Copy link

Done, thanks.

@Ionic
Copy link

Ionic commented Nov 30, 2020

And as zhaoyang-star said,
if you want to build from googletest/googletest
it looks like GOOGLETEST_VERSION should be added in the file googletest/googletest/CMakeLists.txt

I believe that the versioning information should be split out into a separate file which can then be include()d in all CMakeLists.txt files.

I'm too lazy to actually make a PR, but something like this should work:

FORMAT: path: content

/ (for reference only, is ${CMAKE_SOURCE_DIR})
/ProjectVersion.txt: set(GOOGLETEST_VERSION ...)
/CMakeLists.txt: include("${CMAKE_SOURCE_DIR}/ProjectVersion.txt")
/googlemock/CMakeLists.txt: include("${CMAKE_SOURCE_DIR}/../ProjectVersion.txt")
/googletest/CMakeLists.txt: include("${CMAKE_SOURCE_DIR}/../ProjectVersion.txt")

This should allow sub-projects to be built individually and still only requires changing the version in one common place. (N.B.: there are other places hard-coding the version, so these will still need to be updated manually, but my main point is that this approach won't add to proliferation of version numbers all over the place.)

The drawback is that you can't split out the googletest or googlemock "modules" from the main source, but that's a.) probably not something supported and b.) not actually possible even right now anyway, so that's really a non-problem.

@OTTFFIVE
Copy link

OTTFFIVE commented May 7, 2022

sudo apt-get install libgmock-dev

@tobbi
Copy link
Contributor

tobbi commented May 14, 2024

I tried to fix this warning in #4539.

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

No branches or pull requests

8 participants