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

FindSQLite3.cmake shadows a module with the same name in upstream CMake with differnt target name #312

Open
traversaro opened this issue Sep 29, 2022 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@traversaro
Copy link
Contributor

Since CMake 3.14, CMake provides a find_package(SQLite3 REQUIRED) module that is used if one calls find_package(SQLite3 REQUIRED), that defines the SQLite::SQLite3 imported target. If one calls find_package(ignition-cmake2 REQUIRED) before find_package(SQLite3 REQUIRED), the find_package(SQLite3 REQUIRED) of ign-cmake is used instead, that defines SQLite3::SQLite3 instead.

This can leads to tricky issues, such as when find_package(VTK) is called after find_package(gazebo) (see traversaro/vtk-gazebo-cross-talking#1).

Environment

  • OS Version: Ubuntu 22.04
  • Source or binary build?
    Binary upstream from Ubuntu 22.04 2.10.0-2

Description

  • Expected behavior: After find_package(ignition-cmake2 REQUIRED), find_package(SQLite3 REQUIRED) does not provide SQLite::SQLite3
  • Actual behavior: Even if find_package(ignition-cmake2 REQUIRED) is called before, find_package(SQLite3 REQUIRED) should provide SQLite::SQLite3

Steps to reproduce

See traversaro/vtk-gazebo-cross-talking#1 and https://github.com/traversaro/vtk-gazebo-cross-talking/blob/main/.github/workflows/cmake.yml .

Output

-- Found fcl: /usr/include (found suitable version "0.7.0", minimum required is "0.5.0") 
-- Found assimp: /usr/include (found version "5.2.0") 
-- Found DART: /usr/include (Required is at least version "6.6") found components: dart 
-- Found Boost: /usr/lib/x86_64-linux-gnu/cmake/Boost-1.74.0/BoostConfig.cmake (found suitable version "1.74.0", minimum required is "1.40.0") found components: thread system filesystem program_options regex iostreams date_time 
-- Found Protobuf: /usr/lib/x86_64-linux-gnu/libprotobuf.so (found version "3.12.4") 
-- Looking for ignition-math6 -- found version 6.10.0
-- Searching for dependencies of ignition-math6
-- Looking for OGRE...
-- OGRE_PREFIX_WATCH changed.
-- Checking for module 'OGRE'
--   Found OGRE, version 1.9.0
-- Found Ogre Ghadamon (1.9.0)
-- Found OGRE: optimized;/usr/lib/x86_64-linux-gnu/libOgreMain.so;debug;/usr/lib/x86_64-linux-gnu/libOgreMain.so
-- Looking for OGRE_Paging...
-- Found OGRE_Paging: optimized;/usr/lib/x86_64-linux-gnu/libOgrePaging.so;debug;/usr/lib/x86_64-linux-gnu/libOgrePaging.so
-- Looking for OGRE_Terrain...
-- Found OGRE_Terrain: optimized;/usr/lib/x86_64-linux-gnu/libOgreTerrain.so;debug;/usr/lib/x86_64-linux-gnu/libOgreTerrain.so
-- Looking for OGRE_Property...
-- Found OGRE_Property: optimized;/usr/lib/x86_64-linux-gnu/libOgreProperty.so;debug;/usr/lib/x86_64-linux-gnu/libOgreProperty.so
-- Looking for OGRE_RTShaderSystem...
-- Found OGRE_RTShaderSystem: optimized;/usr/lib/x86_64-linux-gnu/libOgreRTShaderSystem.so;debug;/usr/lib/x86_64-linux-gnu/libOgreRTShaderSystem.so
-- Looking for OGRE_Volume...
-- Found OGRE_Volume: optimized;/usr/lib/x86_64-linux-gnu/libOgreVolume.so;debug;/usr/lib/x86_64-linux-gnu/libOgreVolume.so
-- Looking for OGRE_Overlay...
-- Found OGRE_Overlay: optimized;/usr/lib/x86_64-linux-gnu/libOgreOverlay.so;debug;/usr/lib/x86_64-linux-gnu/libOgreOverlay.so
-- Looking for ignition-math6 -- found version 6.10.0
-- Looking for ignition-transport8 -- found version 8.2.1
-- Searching for dependencies of ignition-transport8
-- Found Protobuf: /usr/lib/x86_64-linux-gnu/libprotobuf.so (found suitable version "3.12.4", minimum required is "3") 
-- Config-file not installed for ZeroMQ -- checking for pkg-config
-- Checking for module 'libzmq >= 4'
--   Found libzmq , version 4.3.4
-- Found ZeroMQ: TRUE (Required is at least version "4") 
-- Checking for module 'uuid'
--   Found uuid, version 2.37.2
-- Found UUID: TRUE  
-- Looking for ignition-msgs5 -- found version 5.8.1
-- Searching for dependencies of ignition-msgs5
-- Looking for ignition-math6 -- found version 6.10.0
-- Checking for module 'tinyxml2'
--   Found tinyxml2, version 9.0.0
-- Looking for ignition-msgs5 -- found version 5.8.1
-- Looking for ignition-common3 -- found version 3.14.0
-- Searching for dependencies of ignition-common3
-- Looking for dlfcn.h - found
-- Looking for libdl - found
-- Found DL: TRUE  
-- Found tinyobjloader: /usr/lib/x86_64-linux-gnu/cmake/tinyobjloader/tinyobjloader-config.cmake (found version "2.0.0") 
-- Searching for <ignition-common3> component [graphics]
-- Looking for ignition-common3-graphics -- found version 3.14.0
-- Searching for dependencies of ignition-common3-graphics
-- Looking for ignition-math6 -- found version 6.10.0
-- Looking for ignition-fuel_tools4 -- found version 4.4.0
-- Searching for dependencies of ignition-fuel_tools4
-- Found CURL: /usr/lib/x86_64-linux-gnu/libcurl.so (found version "7.81.0")  
-- Checking for module 'jsoncpp'
--   Found jsoncpp, version 1.9.5
-- Found JSONCPP: TRUE  
-- Checking for module 'yaml-0.1'
--   Found yaml-0.1, version 0.2.2
-- Found YAML: TRUE  
-- Checking for module 'libzip'
--   Found libzip, version 1.7.3
-- Found ZIP: TRUE  
-- Looking for ignition-common3 -- found version 3.14.0
-- Looking for ignition-math6 -- found version 6.10.0
-- Looking for ignition-msgs5 -- found version 5.8.1
-- Found Threads: TRUE  
-- Found GLEW: /usr/lib/x86_64-linux-gnu/libGLEW.so  
-- Found OpenGL: /usr/lib/x86_64-linux-gnu/libOpenGL.so  found components: OpenGL GLX 
-- Found Python3: /usr/bin/python3.10 (found suitable version "3.10.6", minimum required is "3.10") found components: Interpreter Development.Module Development.Embed 
-- Found MPI_C: /usr/lib/x86_64-linux-gnu/libmpi.so (found version "3.1") 
-- Found MPI: TRUE (found version "3.1") found components: C 
-- Found HDF5: /usr/lib/x86_64-linux-gnu/hdf5/serial/libhdf5.so;/usr/lib/x86_64-linux-gnu/libcrypto.so;/usr/lib/x86_64-linux-gnu/libcurl.so;/usr/lib/x86_64-linux-gnu/libpthread.a;/usr/lib/x86_64-linux-gnu/libsz.so;/usr/lib/x86_64-linux-gnu/libz.so;/usr/lib/x86_64-linux-gnu/libdl.a;/usr/lib/x86_64-linux-gnu/libm.so (found version "1.10.7") found components: C HL 
-- Found NetCDF: /usr/include (found version "4.8.1") 
-- Found OGG: /usr/lib/x86_64-linux-gnu/libogg.so  
-- Found THEORA: /usr/lib/x86_64-linux-gnu/libtheora.so  
-- Found JsonCpp: /usr/lib/x86_64-linux-gnu/libjsoncpp.so (found suitable version "1.9.5", minimum required is "0.7.0") 
-- Found LibXml2: /usr/lib/x86_64-linux-gnu/libxml2.so (found version "2.9.13") 
-- Found ZLIB: /usr/lib/x86_64-linux-gnu/libz.so (found version "1.2.11") 
-- Found GL2PS: /usr/lib/x86_64-linux-gnu/libgl2ps.so (found suitable version "1.4.2", minimum required is "1.4.2") 
-- Found PNG: /usr/lib/x86_64-linux-gnu/libpng.so (found version "1.6.37") 
-- Checking for module 'sqlite'
--   No package 'sqlite' found
-- Could not find the VTK package due to a missing dependency: SQLite3
-- Found LibPROJ: /usr/lib/x86_64-linux-gnu/libproj.so (found version "8.2.1") 
-- Found Eigen3: /usr/include/eigen3 (found version "3.4.0") 
-- Found X11: /usr/include   
-- Looking for XOpenDisplay in /usr/lib/x86_64-linux-gnu/libX11.so;/usr/lib/x86_64-linux-gnu/libXext.so
-- Looking for XOpenDisplay in /usr/lib/x86_64-linux-gnu/libX11.so;/usr/lib/x86_64-linux-gnu/libXext.so - found
-- Looking for gethostbyname
-- Looking for gethostbyname - found
-- Looking for connect
-- Looking for connect - found
-- Looking for remove
-- Looking for remove - found
-- Looking for shmat
-- Looking for shmat - found
-- Looking for IceConnectionNumber in ICE
-- Looking for IceConnectionNumber in ICE - found
-- Found EXPAT: /usr/lib/x86_64-linux-gnu/libexpat.so (found version "2.4.7") 
-- Found double-conversion: /usr/lib/x86_64-linux-gnu/libdouble-conversion.so  
-- Found LZ4: /usr/lib/x86_64-linux-gnu/liblz4.so (found version "1.9.3") 
-- Found LZMA: /usr/lib/x86_64-linux-gnu/liblzma.so (found version "5.2.5") 
-- Found JPEG: /usr/lib/x86_64-linux-gnu/libjpeg.so (found version "80") 
-- Found TIFF: /usr/lib/x86_64-linux-gnu/libtiff.so (found version "4.3.0")  
-- Found Freetype: /usr/lib/x86_64-linux-gnu/libfreetype.so (found version "2.11.1") 
-- Found utf8cpp: /usr/include/utf8cpp  
-- VTK_VERSION: 9.1.0
-- Configuring done
CMake Error at /usr/lib/x86_64-linux-gnu/cmake/vtk-9.1/VTK-targets.cmake:1268 (set_target_properties):
-- Generating done
  The link interface of target "VTK::sqlite" contains:

    SQLite::SQLite3

  but the target was not found.  Possible reasons include:

    * There is a typo in the target name.
    * A find_package call is missing for an IMPORTED target.
    * An ALIAS target is missing.

Call Stack (most recent call first):
  /usr/lib/x86_64-linux-gnu/cmake/vtk-9.1/vtk-config.cmake:138 (include)
  CMakeLists.txt:10 (find_package)
@traversaro traversaro added the bug Something isn't working label Sep 29, 2022
traversaro added a commit to traversaro/gz-cmake that referenced this issue Sep 29, 2022
@mjcarroll
Copy link
Contributor

So for gz-cmake3, I think the thing that drives CMake version the most are:

  • Ubuntu Focal (CMake 3.16.3-1ubuntu1)
  • Ubuntu Jammy (3.22.1-1ubuntu1)

We should probably update the logic to take into account that find_package(SQLite3) is available without any additional logic.

I agree that the cross-talk is definitely unintended and a bug in this case.

@traversaro
Copy link
Contributor Author

In #313 I provided a minimally invasive change. The tricky aspect is that (as far as I know) once you shadowed a Find<package>.cmake module, there is no way to call via find_package(<package>) the shadowed module. One thing that we could try is to include it via include(<location_of_cmake_modules>/FindSQLite3.cmake) I am not sure how to robustly get <location_of_cmake_modules> or if this does not have strange side effects (CMake scopes rules can be really counterintuitive).

A long term plan could for gz-cmake3 could be to bump the minimum cmake version to 3.14 or 3.16, invert the logic added in traversaro@a61bfc5, i.e. make SQLite::SQLite3 the imported library and SQLite3::SQLite3 the ALIAS library, and mark SQLite3::SQLite3 as deprecated (but unfortunatly the support for deprecating targets is only available since CMake 3.17 : ( https://cmake.org/cmake/help/latest/prop_tgt/DEPRECATION.html ), and eventually remove FindSQLite3.cmake from gz-cmake in gz-cmake4, if that will ever happens.

scpeters added a commit that referenced this issue Oct 21, 2022
Workaround for #312. Improves compatibility with CMake's
upstream FindSQLite3 module.

Signed-off-by: Silvio <[email protected]>
Co-authored-by: Steve Peters <[email protected]>
@azeey
Copy link
Contributor

azeey commented Nov 21, 2022

Since Focal is on 3.16, we can probably deprecate the old functionality.

@azeey azeey self-assigned this Feb 13, 2023
@azeey azeey moved this to In review in Core development Jul 24, 2023
@scpeters
Copy link
Member

A long term plan could for gz-cmake3 could be to bump the minimum cmake version to 3.14 or 3.16, invert the logic added in traversaro@a61bfc5, i.e. make SQLite::SQLite3 the imported library and SQLite3::SQLite3 the ALIAS library, and mark SQLite3::SQLite3 as deprecated (but unfortunatly the support for deprecating targets is only available since CMake 3.17 : ( https://cmake.org/cmake/help/latest/prop_tgt/DEPRECATION.html ), and eventually remove FindSQLite3.cmake from gz-cmake in gz-cmake4, if that will ever happens.

We have bumped the minimum cmake version to 3.22.1 in gz-cmake4 on the main branch, and I've added this issue to #350 tracking things to do with the new cmake features.

@azeey azeey moved this from In review to To do in Core development Jan 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: To do
Development

No branches or pull requests

4 participants