External Dependencies

FIND_PACKAGE()

  • Pulling in parameters for SQLite3

Toplevel CMakeLists.txt
FIND_PACKAGE(SQLite3)      # <--- continues if not found
$ cmake /home/jfasch/work/jfasch-home/trainings/material/soup/cmake/13-external-dependencies/
...
-- Could NOT find SQLite3 (missing: SQLite3_INCLUDE_DIR SQLite3_LIBRARY)
...

FIND_PACKAGE(... REQUIRED)

Note

A requirement appears to only fail if at least one target depends on the imported target

libhello/CMakeLists.txt
TARGET_LINK_LIBRARIES(hello SQLite::SQLite3)
  • Requiring SQLite3 ⟶ failing if not found

    FIND_PACKAGE(SQLite3 REQUIRED)
    
    $ cmake /home/jfasch/work/jfasch-home/trainings/material/soup/cmake/13-external-dependencies/
    ...
    CMake Error at libhello/CMakeLists.txt:8 (TARGET_LINK_LIBRARIES):
      Target "hello" links to:
    
        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.
    
  • Success after installing sqlite-devel

    $ sudo dnf install sqlite-devel
    $ cmake /home/jfasch/work/jfasch-home/trainings/material/soup/cmake/13-external-dependencies/
    ...
    -- Found SQLite3: /usr/include (found version "3.36.0")
    ...
    

SQLite3 Parameters

  • Find-modules usually set variables

  • FindSQLite3 is documented to set those (put in toplevel CMakeLists.txt)

    MESSAGE(DEBUG "SQLite3_INCLUDE_DIRS ${SQLite3_INCLUDE_DIRS}")
    MESSAGE(DEBUG "SQLite3_LIBRARIES ${SQLite3_LIBRARIES}")
    MESSAGE(DEBUG "SQLite3_VERSION ${SQLite3_VERSION}")
    MESSAGE(DEBUG "SQLite3_FOUND ${SQLite3_FOUND}")
    
    $ cmake --log-level=debug /home/jfasch/work/jfasch-home/trainings/material/soup/cmake/13-external-dependencies/
    ...
    -- SQLite3_INCLUDE_DIRS /usr/include
    -- SQLite3_LIBRARIES /usr/lib64/libsqlite3.so
    -- SQLite3_VERSION 3.36.0
    -- SQLite3_FOUND TRUE
    ...
    

Using SQLite3 Parameters

  • With “Modern CMake” (that with targets, and propagated properties) not necessary anymore

  • Used to be necessary in olden days

  • Only say TARGET_LINK_LIBRARIES(hello SQLite::SQLite3)

  • ⟶ All is fine

Demo Time