Open kloczek opened 1 year ago
For debian based distributions, install: libgmock-dev
and for redhat based distributions install: gmock-devel
Thoughts on the fix:
Since https://github.com/Kitware/CMake/commit/50bf457a0dd857cf976b22c5be7d333493233d1e , the target GTest::gmock
is available. According to upstream, it would be CMake 3.23.0+
Some distributions have backported this patch to old versions, but that might not be the case for all distributions. On top of it, the assumption is that find_package(GTest)
should suffice, since gmock is now a part of googletest, but it might still be packaged separately by package maintainers for various distributions.
One workaround is to add a local FindGMock
module to the cmake directory.
In recent months I found many caces with buggy procedural cmake modules description. At the same time if exact library provided pkgconfig desription (wgich is declarative) it was prfectly fine. Recent case is abseil-cpp which adds in cmake modules many internal deprndencies which IMO are completly redundants and alredy caused many problems. Only by those cases currently I dislike a bit cmake modules.
I would suggest try to avoid use cmake modules if pkgconfig description is provided and gmock
has pkgconfig file .. but this is only suggestion (it is up to you decision).
Could we consider bumping cmake minimum version at least 3.18
For debian based distributions, install:
libgmock-dev
and for redhat based distributions install:gmock-devel
Thoughts on the fix:
Since Kitware/CMake@50bf457 , the target
GTest::gmock
is available. According to upstream, it would beCMake 3.23.0+
Some distributions have backported this patch to old versions, but that might not be the case for all distributions. On top of it, the assumption is thatfind_package(GTest)
should suffice, since gmock is now a part of googletest, but it might still be packaged separately by package maintainers for various distributions.One workaround is to add a local
FindGMock
module to the cmake directory.
What about the FindGTest
module, introduced in 3.20?
https://cmake.org/cmake/help/latest/module/FindGTest.html?highlight=gtest#module:FindGTest
I've used that, run it with find_package(GTest QUIET)
, then if its not found, fallback to fetchcontent
as per the GTest docs.
What about the
FindGTest
module, introduced in 3.20?
That is exactly what e.g. rawspeed did because of gtest IIRC... The problem is, Ubuntu hasn't backported CMake in their current 20.04 LTS from Debian 10/11, it's not even at 3.18 (as mentioned in https://github.com/Exiv2/exiv2/issues/2617)...
meson uses pkgconfig and tries CMake second for this reason.
In general, the only reason not to use pkg-config is out of concern that pkg-config will not be installed on Windows systems. This is not entirely accurate... but if we assume by fiat that cmake-config files shall be used because cmake says so, it still makes sense to search also via pkg-config.
On top of it, the assumption is that
find_package(GTest)
should suffice, since gmock is now a part of googletest, but it might still be packaged separately by package maintainers for various distributions.
If the concern is primarily package maintainers for linux distributions, then checking with pkg-config first nicely solves this problem. You don't need to bump the minimum cmake version, and pkg-config is always installed and available in that environment so it will successfully find both gmock and gtest. But if it doesn't, you still fall back to cmake and probably find it then anyways. :)
@kloczek does https://github.com/Exiv2/exiv2/pull/2714 fix your issue?
One sec .. let me check π
Looks like it works π
+ export ASMFLAGS CFLAGS CXXFLAGS FFLAGS FCFLAGS LDFLAGS VALAFLAGS CC CXX FC AR NM RANLIB RUSTFLAGS VALAFLAGS
+ /usr/bin/cmake -B x86_64-redhat-linux-gnu -D BUILD_SHARED_LIBS=ON -D CMAKE_AR=/usr/bin/gcc-ar -D CMAKE_BUILD_TYPE=RelWithDebInfo -D CMAKE_C_FLAGS_RELEASE=-DNDEBUG -D CMAKE_CXX_FLAGS_RELEASE=-DNDEBUG -D CMAKE_Fortran_FLAGS_RELEASE=-DNDEBUG -D CMAKE_INSTALL_PREFIX=/usr -D CMAKE_NM=/usr/bin/gcc-nm -D CMAKE_RANLIB=/usr/bin/gcc-ranlib -D CMAKE_VERBOSE_MAKEFILE=ON -D INCLUDE_INSTALL_DIR=/usr/include -D LIB_INSTALL_DIR=/usr/lib64 -D LIB_SUFFIX=64 -D SHARE_INSTALL_PREFIX=/usr/share -D SYSCONF_INSTALL_DIR=/etc -S . -D EXIV2_BUILD_DOC=ON -D EXIV2_BUILD_SAMPLES=OFF -D EXIV2_ENABLE_NLS=ON -D BUILD_SHARED_LIBS=ON -D BUILD_WITH_COVERAGE=OFF -D EXIV2_BUILD_EXIV2_COMMAND=ON -D EXIV2_BUILD_UNIT_TESTS=ON -D EXIV2_ENABLE_CURL=OFF -D EXIV2_ENABLE_DYNAMIC_RUNTIME=ON -D EXIV2_ENABLE_LENSDATA=ON -D EXIV2_ENABLE_PNG=ON -D EXIV2_ENABLE_PRINTUCS2=ON -D EXIV2_ENABLE_SSH=OFF -D EXIV2_ENABLE_VIDEO=ON -D EXIV2_ENABLE_WEBREADY=ON -D EXIV2_ENABLE_XMP=ON
-- The C compiler identification is GNU 13.1.1
-- The CXX compiler identification is GNU 13.1.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/gcc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/g++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Python3: /usr/bin/python3.8 (found version "3.8.17") found components: Interpreter
-- Looking for C++ include filesystem
-- Looking for C++ include filesystem - found
-- Performing Test CXX_FILESYSTEM_NO_LINK_NEEDED
-- Performing Test CXX_FILESYSTEM_NO_LINK_NEEDED - Success
-- Found ZLIB: /usr/lib64/libz.so (found version "1.2.13")
-- Found Brotli: /usr/lib64/libbrotlidec.so
-- Found EXPAT: /usr/lib64/libexpat.so (found version "2.5.0")
-- Found Intl: built in to C library
-- Performing Test Iconv_IS_BUILT_IN
-- Performing Test Iconv_IS_BUILT_IN - Success
-- Found Iconv: built in to C library
-- Iconv_INCLUDE_DIRS :
-- Iconv_LIBRARIES :
-- Found inih: /usr/lib64/libinih.so
-- inih_INCLUDE_DIRS : /usr/include
-- inih_LIBRARIES : /usr/lib64/libinih.so
-- inih_inireader_INCLUDE_DIRS : /usr/include
-- inih_inireader_LIBRARIES : /usr/lib64/libINIReader.so
-- Performing Test HAS_FSTACK_CLASH_PROTECTION
-- Performing Test HAS_FSTACK_CLASH_PROTECTION - Success
-- Performing Test HAS_FCF_PROTECTION
-- Performing Test HAS_FCF_PROTECTION - Success
-- Performing Test HAS_FSTACK_PROTECTOR_STRONG
-- Performing Test HAS_FSTACK_PROTECTOR_STRONG - Success
-- Looking for strerror_r
-- Looking for strerror_r - found
-- Performing Test EXV_STRERROR_R_CHAR_P
-- Performing Test EXV_STRERROR_R_CHAR_P - Success
-- Found Doxygen: /usr/bin/doxygen (found version "1.9.7") found components: doxygen dot
-- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY
-- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY - Success
-- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY
-- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY - Success
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR - Success
-- Found PkgConfig: /usr/bin/pkg-config (found version "1.9.5")
-- Checking for module 'gtest_main'
-- Found gtest_main, version 1.13.0
-- Found Gettext: /usr/bin/msgmerge (found version "0.22")
-- Install prefix: /usr
-- ------------------------------------------------------------------
-- CMake Generator: Unix Makefiles
-- CMAKE_BUILD_TYPE: RelWithDebInfo
-- Compiler info: GNU (/usr/bin/g++) ; version: 13.1.1
-- CMAKE_CXX_STANDARD:17
-- --- Compiler flags ---
-- General: -O2 -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fdata-sections -ffunction-sections -flto=auto -flto-partition=none -Os
-fstack-clash-protection
-fcf-protection
-fstack-protector-strong
-Wp,-D_GLIBCXX_ASSERTIONS
-Wall
-Wcast-align
-Wpointer-arith
-Wformat-security
-Wmissing-format-attribute
-Woverloaded-virtual
-W
-Wno-error=format-nonliteral
-- Extra:
-- Debug: -g3 -gstrict-dwarf -O0
-- Release: -DNDEBUG
-- RelWithDebInfo: -DNDEBUG
-- MinSizeRel: -DNDEBUG
-- --- Linker flags ---
-- General: -Wl,--gc-sections -Wl,--as-needed -flto=auto -flto-partition=none -fuse-linker-plugin -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,--build-id=sha1
-- Debug:
-- Release:
-- RelWithDebInfo:
-- MinSizeRel:
--
-- Compiler Options
-- Warnings as errors: NO
-- Use extra compiler warning flags: NO
--
-- ------------------------------------------------------------------
-- Building shared library: YES
-- Building PNG support: YES
-- XMP metadata support: YES
-- Building BMFF support: YES
-- Brotli support for JPEG XL: YES
-- Native language support: YES
-- Building video support: YES
-- Nikon lens database: YES
-- Building webready support: YES
-- USE Libcurl for HttpIo: NO
-- Building exiv2 command: YES
-- Building samples: NO
-- Building unit tests: YES
-- Building fuzz tests: NO
-- Building doc: YES
-- Building with coverage flags: NO
-- Using ccache: NO
-- Configuring done (5.7s)
-- Generating done (0.1s)
I think that it would be really good to change to pkgconfig all other libraries detection (just a suggestion).
Nope I was wrong .. cmake is OK however build still fails
[ 62%] Building CXX object unitTests/CMakeFiles/unit_tests.dir/test_datasets.cpp.o
cd /home/tkloczko/rpmbuild/BUILD/exiv2-0.28.0/x86_64-redhat-linux-gnu/unitTests && /usr/bin/g++ -DEXV_LOCALEDIR=\"../share/locale\" -DTESTDATA_PATH=\"/home/tkloczko/rpmbuild/BUILD/exiv2-0.28.0/test/data\" -Dexiv2lib_STATIC -I/home/tkloczko/rpmbuild/BUILD/exiv2-0.28.0/x86_64-redhat-linux-gnu -I/home/tkloczko/rpmbuild/BUILD/exiv2-0.28.0/src -I/home/tkloczko/rpmbuild/BUILD/exiv2-0.28.0/include/exiv2 -I/home/tkloczko/rpmbuild/BUILD/exiv2-0.28.0/include -O2 -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fdata-sections -ffunction-sections -flto=auto -flto-partition=none -Os -DNDEBUG -std=gnu++17 -fvisibility=hidden -fvisibility-inlines-hidden -fstack-clash-protection -fcf-protection -fstack-protector-strong -Wp,-D_GLIBCXX_ASSERTIONS -Wall -Wcast-align -Wpointer-arith -Wformat-security -Wmissing-format-attribute -Woverloaded-virtual -W -Wno-error=format-nonliteral -MD -MT unitTests/CMakeFiles/unit_tests.dir/test_datasets.cpp.o -MF CMakeFiles/unit_tests.dir/test_datasets.cpp.o.d -o CMakeFiles/unit_tests.dir/test_datasets.cpp.o -c /home/tkloczko/rpmbuild/BUILD/exiv2-0.28.0/unitTests/test_datasets.cpp
/home/tkloczko/rpmbuild/BUILD/exiv2-0.28.0/unitTests/test_datasets.cpp:3:10: fatal error: gmock/gmock.h: No such file or directory
3 | #include <gmock/gmock.h>
| ^~~~~~~~~~~~~~~
compilation terminated.
I think that you should put below on your outstanding list as well
[tkloczko@pers-jacek SPECS]$ rpmbuild -ba exiv2.spec --quiet 2>&1 | grep -- \\[-W | sed 's/.*\[//; s/\]//' | sort | uniq -c | sort -nr
3 -Wformat=
1 -Wodr
/home/tkloczko/rpmbuild/BUILD/exiv2-0.28.0/xmpsdk/src/XMPUtils.cpp: In static member function 'static XMP_Int64 XMPUtils::ConvertToInt64(XMP_StringPtr)':
/home/tkloczko/rpmbuild/BUILD/exiv2-0.28.0/xmpsdk/src/XMPUtils.cpp:1221:48: warning: format '%lld' expects argument of type 'long long int*', but argument 3 has type 'XMP_Int64*' {aka 'long int*'} [-Wformat=]
1221 | count = sscanf ( strValue, "%lld%c", &result, &nextCh );
| ~~~^ ~~~~~~~
| | |
| | XMP_Int64* {aka long int*}
| long long int*
| %ld
/home/tkloczko/rpmbuild/BUILD/exiv2-0.28.0/xmpsdk/src/XMPUtils.cpp:1223:48: warning: format '%llx' expects argument of type 'long long unsigned int*', but argument 3 has type 'XMP_Int64*' {aka 'long int*'} [-Wformat=]
1223 | count = sscanf ( strValue, "%llx%c", &result, &nextCh );
| ~~~^ ~~~~~~~
| | |
| | XMP_Int64* {aka long int*}
| long long unsigned int*
| %lx
/home/tkloczko/rpmbuild/BUILD/exiv2-0.28.0/xmpsdk/src/XMPMeta.cpp: In function 'XMP_Status DumpNodeOptions(XMP_OptionBits, XMP_TextOutputProc, void*)':
/home/tkloczko/rpmbuild/BUILD/exiv2-0.28.0/xmpsdk/src/XMPMeta.cpp:90:70: warning: format '%lX' expects argument of type 'long unsigned int', but argument 4 has type 'XMP_OptionBits' {aka 'unsigned int'} [-Wformat=]
90 | #define OutProcHexInt(num) { snprintf ( buffer, sizeof(buffer), "%lX", (num) ); /* AUDIT: Using sizeof for snprintf length is safe */ \
| ^~~~~ ~~~~~
/home/tkloczko/rpmbuild/BUILD/exiv2-0.28.0/xmpsdk/src/XMPMeta.cpp:241:17: note: in expansion of macro 'OutProcHexInt'
241 | OutProcHexInt ( options );
| ^~~~~~~~~~~~~
/home/tkloczko/rpmbuild/BUILD/exiv2-0.28.0/xmpsdk/src/XMPMeta.cpp:90:73: note: format string is defined here
90 | #define OutProcHexInt(num) { snprintf ( buffer, sizeof(buffer), "%lX", (num) ); /* AUDIT: Using sizeof for snprintf length is safe */ \
| ~~^
| |
| long unsigned int
| %X
/home/tkloczko/rpmbuild/BUILD/exiv2-0.28.0/src/minoltamn_int.cpp:1653:18: warning: type 'struct LensIdFct' violates the C++ One Definition Rule [-Wodr]
1653 | constexpr struct LensIdFct {
| ^
/home/tkloczko/rpmbuild/BUILD/exiv2-0.28.0/src/pentaxmn_int.cpp:1234:8: note: a different type is defined in another translation unit
1234 | struct LensIdFct {
| ^
/home/tkloczko/rpmbuild/BUILD/exiv2-0.28.0/src/minoltamn_int.cpp:1654:12: note: the first difference of corresponding definitions is field 'idx'
1654 | uint32_t idx;
| ^
/home/tkloczko/rpmbuild/BUILD/exiv2-0.28.0/src/pentaxmn_int.cpp:1235:8: note: a field with different name is defined in another translation unit
1235 | long id_; //!< Lens id
| ^
[ 62%] Building CXX object unitTests/CMakeFiles/unit_tests.dir/test_datasets.cpp.o cd /home/tkloczko/rpmbuild/BUILD/exiv2-0.28.0/x86_64-redhat-linux-gnu/unitTests && /usr/bin/g++ -DEXV_LOCALEDIR=\"../share/locale\" -DTESTDATA_PATH=\"/home/tkloczko/rpmbuild/BUILD/exiv2-0.28.0/test/data\" -Dexiv2lib_STATIC -I/home/tkloczko/rpmbuild/BUILD/exiv2-0.28.0/x86_64-redhat-linux-gnu -I/home/tkloczko/rpmbuild/BUILD/exiv2-0.28.0/src -I/home/tkloczko/rpmbuild/BUILD/exiv2-0.28.0/include/exiv2 -I/home/tkloczko/rpmbuild/BUILD/exiv2-0.28.0/include -O2 -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fdata-sections -ffunction-sections -flto=auto -flto-partition=none -Os -DNDEBUG -std=gnu++17 -fvisibility=hidden -fvisibility-inlines-hidden -fstack-clash-protection -fcf-protection -fstack-protector-strong -Wp,-D_GLIBCXX_ASSERTIONS -Wall -Wcast-align -Wpointer-arith -Wformat-security -Wmissing-format-attribute -Woverloaded-virtual -W -Wno-error=format-nonliteral -MD -MT unitTests/CMakeFiles/unit_tests.dir/test_datasets.cpp.o -MF CMakeFiles/unit_tests.dir/test_datasets.cpp.o.d -o CMakeFiles/unit_tests.dir/test_datasets.cpp.o -c /home/tkloczko/rpmbuild/BUILD/exiv2-0.28.0/unitTests/test_datasets.cpp /home/tkloczko/rpmbuild/BUILD/exiv2-0.28.0/unitTests/test_datasets.cpp:3:10: fatal error: gmock/gmock.h: No such file or directory 3 | #include <gmock/gmock.h> | ^~~~~~~~~~~~~~~ compilation terminated.
what is still missing is gmock
detection.
@kloczek Something fishy is going on on your machine. Any CMake detection issues aside, you're still missing this header. It should be relative to the system include directory, and compilation shouldn't fail (i.e. pkg-config --cflags gmock_main
doesn't provide any new include directories for me), CMake detection working or not (linking might fail later, but let's tackle one step a time).
Are you 100% sure you have gmock-devel
installed as @nehaljwani already suggested? What does pkg-config --cflags --libs gmock_main
give you?
Are you 100% sure you have
gmock-devel
installed as @nehaljwani already suggested? What doespkg-config --cflags --libs gmock_main
give you?
No I did't because cmake did not complained about that π
Please have look one more time on provided cmake output.
There is no single line about gmock_main
detection.
In https://github.com/Exiv2/exiv2/pull/2714 there is only gtest_main
detection .. π
That was not the question @kloczek
I know π
As I wrote first I've tested with installed gmock devel and it build correctly.
Than I've tested without gmoc devel build failed because still nothing is trying detect gmock_main
π
That bit still is missing π
So, to recap:
I don't see an issue here.
In cmake output and PR there is no anything about gmock or its header files. Issue is that cmake ends with status
-- Building unit tests: YES
which needs gmock.
IMHO it is a nice-to-have to have this fail earlier at the configure stage, rather than an issue (all the info of why it failed and how to rectify is still there). We can't know how/why every distribution split GTest when packaging...
Anyway, does https://github.com/Exiv2/exiv2/pull/2716 maybe improve it for you? (Yes, I know it fails for many other distros in our CI, just want to test options here...)
Anyway, does https://github.com/Exiv2/exiv2/pull/2716 maybe improve it for you?
Scratch that - on Fedora it looks like both gmock
and gmock-devel
ship the shared objects (the gmock-devel
just the unversioned symlinks though). The supplied config only checks for those (and won't fail because gmock
is pulled in by gtest-devel
), while it doesn't check for header files.
Again, this GTest packaging weirdness across distros is not something I personally want to invest further time in given the trivial steps needed to rectify this particular error.
There are two APIs gmock
and gtest
.
Assuming that gmock API will bi installed with gtest is not correct way of use gmock
.
Just checked my spec fiels:
[tkloczko@pers-jacek SPECS]$ grep BuildRequires:.gtest -rl | wc -l
16
[tkloczko@pers-jacek SPECS]$ grep BuildRequires:.gmock -rl | wc -l
5
this is fixed, no?
Upstream issue: https://discourse.cmake.org/t/how-to-mark-gmock-as-a-required-component/10106
I reported this on the CMake forums. It's a problem in all my projects that use GMock because it is distributed separately on Ubuntu 22 from Gtest through binaries.
cmake output:
Anf build fails with: