Search code examples
c++qtcmakecontinuous-integrationconan

Installing Qt5Svg with Conan


So I'm trying to port this project I've been working on from qmake to cmake. I also plan to get my qt dependencies through Conan and get a CI service going. Getting most of the qt libraries was fairly easy using qt/5.12.4@bincrafters/stable. Except one. For some reason, the Qt5Svg module is not included with this package and I couldn't find a good solution for this so I've hit a dead end. Bellow are the error messages and the relevant cmake files.

Error message

[CMake] CMake Error at src/analysis_tool/CMakeLists.txt:33 (find_package):
[CMake] By not providing "FindQt5Svg.cmake" in CMAKE_MODULE_PATH this project has
[CMake] asked CMake to find a package configuration file provided by "Qt5Svg", but
[CMake] CMake did not find one.
[CMake]
[CMake] Could not find a package configuration file provided by "Qt5Svg" with any
[CMake] of the following names:
[CMake]
[CMake] Qt5SvgConfig.cmake
[CMake] qt5svg-config.cmake
[CMake]
[CMake] Add the installation prefix of "Qt5Svg" to CMAKE_PREFIX_PATH or set
[CMake] "Qt5Svg_DIR" to a directory containing one of the above files. If "Qt5Svg"
[CMake] provides a separate development package or SDK, be sure it has been
[CMake] installed.

Conan.cmake (which is called from the top level CMakeLists.txt file)

macro(run_conan)
  # Download automatically, you can also just copy the conan.cmake file
  if(NOT EXISTS "${CMAKE_BINARY_DIR}/conan.cmake")
    message(STATUS "Downloading conan.cmake from https://github.com/conan-io/cmake-conan")
    message(${CMAKE_BINARY_DIR};)
    file(DOWNLOAD "https://github.com/conan-io/cmake-conan/raw/v0.15/conan.cmake" "${CMAKE_BINARY_DIR}/conan.cmake")

  endif()

  include(${CMAKE_BINARY_DIR}/conan.cmake)

  conan_add_remote(
    NAME
    bincrafters
    URL
    https://api.bintray.com/conan/bincrafters/public-conan)
    
  conan_cmake_run(
    REQUIRES
    qt/5.12.4@bincrafters/stable
    OPTIONS
    ${CONAN_EXTRA_OPTIONS}
    BASIC_SETUP
    CMAKE_TARGETS # individual targets to link to
    BUILD
    missing)
endmacro()

Executable CMake

cmake_minimum_required(VERSION 3.8)
project(codego)

file(GLOB CODEGO_SOURCES "src/*.cpp")
file(GLOB CODEGO_HEADERS "include/*.h")
file(GLOB CODEGO_UIS "ui/*.ui")
file(GLOB CODEGO_RES "res/*.qrc")

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)

set(CMAKE_AUTOUIC_SEARCH_PATHS ui)

add_executable(${PROJECT_NAME} src/main.cpp ${CODEGO_UIS})

target_include_directories(${PROJECT_NAME} PUBLIC include)
target_include_directories(${PROJECT_NAME} PUBLIC ui)
target_include_directories(${PROJECT_NAME} PUBLIC res)

find_package(Qt5Core REQUIRED)
find_package(Qt5Gui REQUIRED)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Xml REQUIRED)
find_package(Qt5Svg REQUIRED)

# Add the include directories for the Qt 5 modules to the compile lines.
include_directories(${Qt5Core_INCLUDE_DIRS}/QtCore)
include_directories(${Qt5Gui_INCLUDE_DIRS}/QtGui)
include_directories(${Qt5Widgets_INCLUDE_DIRS}/QtWidgets)
include_directories(${Qt5Xml_INCLUDE_DIRS}/QtXml)
include_directories(${Qt5Xml_INCLUDE_DIRS}/QtSvg)

# Use the compile definitions defined in the Qt 5 modules
add_definitions(${Qt5Core_DEFINITIONS})
add_definitions(${Qt5Gui_DEFINITIONS})
add_definitions(${Qt5Widgets_DEFINITIONS})
add_definitions(${Qt5Xml_DEFINITIONS})
add_definitions(${Qt5Svg_DEFINITIONS})

qt5_wrap_ui(WRAP_UI_MOC ${CODEGO_UIS})
qt5_wrap_cpp(WRAP_HEADER_MOC ${CODEGO_HEADERS})

include_directories(${PROJECT_SOURCE_DIR})
include_directories(${PROJECT_BINARY_DIR})
include_directories(${CMAKE_BINARY_DIR})

include_directories(include)

add_library(PROJECT_LIBRARIES SHARED
    ${CODEGO_SOURCES}
    ${WRAP_UI_MOC}
    ${WRAP_HEADER_MOC})

target_link_libraries(${PROJECT_NAME} 
                        Qt5::Core 
                        Qt5::Gui
                        Qt5::Widgets
                        Qt5::Xml
                        Qt5::Svg)

target_link_libraries(${PROJECT_NAME} PROJECT_LIBRARIES)

All the other modules seem to be installing just fine (Qt5Core Qt5Widgets etc) and I can find them in the .conan folder but not the Qt5Svg one. Thanks for taking the time to read through this.


Solution

  • You need to provide and option to build qtsvg with qt package. Your conan_cmake_run should look as follow:

    cmake_minimum_required(VERSION 3.8)
    project(codego)
    
    set(CMAKE_AUTOMOC ON)
    set(CMAKE_AUTORCC ON)
    set(CMAKE_AUTOUIC ON)
    
    set(CMAKE_AUTOUIC_SEARCH_PATHS ui)
    
    if(NOT EXISTS "${CMAKE_BINARY_DIR}/conan.cmake")
        message(STATUS "Downloading conan.cmake from https://github.com/conan-io/cmake-conan")
        message(${CMAKE_BINARY_DIR};)
        file(DOWNLOAD "https://github.com/conan-io/cmake-conan/raw/v0.15/conan.cmake" "${CMAKE_BINARY_DIR}/conan.cmake")
    
      endif()
    
      include(${CMAKE_BINARY_DIR}/conan.cmake)
    
      conan_add_remote(
        NAME
        bincrafters
        URL
        https://api.bintray.com/conan/bincrafters/public-conan)
    
    conan_cmake_run(
           REQUIRES qt/5.14.1@bincrafters/stable
           OPTIONS qt:qtsvg=True
           BASIC_SETUP
           CMAKE_TARGETS
           BUILD missing
    )
    

    EDIT: I used qt 5.14.1 as 5.12.4 was failing to build on my osx machine due to some outdated packages. Now when I do ls:

    ls ~/.conan/data/qt/5.14.1/bincrafters/stable/package/<package_id>/lib/cmake/
    

    gives me Qt5Svg among folders