0

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.

  • Could you check if you have a folder `~/.conan/data/qt/5.12.4/bincrafters/stable/package//lib/cmake/Qt5Svg` – ymochurad Oct 19 '20 at 18:51
  • Thank you for the reply. Yeah, I did check and nothing related to the Svg module. – Butterscotch1993 Oct 19 '20 at 20:32
  • what are your `${CONAN_EXTRA_OPTIONS}`? Did you enable `qt:qtsvg`? – ymochurad Oct 20 '20 at 07:28
  • To be honest I haven't. First time I hear about having to do that. However, even with that enabled (added to the conan_extra_options) I still don't have the Qt5Svg folder inside conan nor am I able to find_package. `set(CONAN_EXTRA_OPTIONS BASIC_SETUP CMAKE_TARGETS qt:qtsvg=true)` – Butterscotch1993 Oct 20 '20 at 13:26

1 Answers1

0

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

ymochurad
  • 941
  • 7
  • 15
  • That sounds reasonable. I copied the command 100% and this is what I get ` > [CMake] ERROR: qt/5.9.0@pivot/stable: option 'qtsvg' doesn't exist > [CMake] Possible options are [] > [CMake] CMake Error at cmake/conan.cmake:402 (message): > [CMake] Conan install failed='1' > [CMake] Call Stack (most recent call first): > [CMake] cmake/conan.cmake:497 (conan_cmake_install) > [CMake] CMakeLists.txt:25 (conan_cmake_run) > [CMake] -- Configuring incomplete, errors occurred!` – Butterscotch1993 Oct 21 '20 at 09:37
  • As a matter of fact it seems to be installing the qt packages without errors if I use capital q (Qt:qtsvg=True) but I still don't get the svg module in the conan folder. – Butterscotch1993 Oct 21 '20 at 09:51
  • added an edit to this answer, @Butterscotch1993 could you try that code? – ymochurad Oct 21 '20 at 12:24