googletest
googletest copied to clipboard
GOOGLETEST_VERSION is not defined in CMakeLists.txt
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.
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
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
)
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
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 https://github.com/google/googletest/pull/2113/commits/60cf03313da2bf615cbc5c535105afb7aa310431 was merged
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.
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
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!
@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
Thanks, @hyukmyeong ! I followed a tutorial to build inside the
googletest/googletest
directory.
The tutorial should be updated to avoid misleading users.
@romanwerpachowski
Could you please review https://github.com/google/googletest/pull/3008 ? whether it provides the proper information what we have discussed in this issue
Done, thanks.
And as zhaoyang-star said, if you want to build from
googletest/googletest
it looks likeGOOGLETEST_VERSION
should be added in the filegoogletest/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.
sudo apt-get install libgmock-dev
I tried to fix this warning in #4539.