-1

Currently, I have Qt dlls and include headers as a dependency in my repo. I wanted to make use of CMake's CMAKE_AUTOMOC functionality providing a moc.exe binary along with dlls and include files. CMake allows to set a custom path to binary but it fails to use CMAKE_AUTOMOC functionality.

CMake Warning (dev) in myproj/CMakeLists.txt:
  AUTOGEN: No valid Qt version found for target myproj_QT.  AUTOMOC
  disabled.  Consider adding:

    find_package(Qt<QTVERSION> COMPONENTS Core)

  to your CMakeLists.txt file.

I don't want to use find_package all stuff like that. I want to make dependency management as much straightforward and explicit as it can be. Is there a way to enable automoc/autouic/autorcc features with my approach?

IC_
  • 1,624
  • 1
  • 23
  • 57
  • 2
    Avoiding using `find_package` looks weird (it is most straightforward and verbose way for specify dependency in CMake). But, according to [AUTOMOC](https://cmake.org/cmake/help/latest/prop_tgt/AUTOMOC.html#qt-version-detection) documentation, you could try to set any pair of **directory properties** listed in it correspondingly to the major and minor parts of QT version. E.g they have an example of setting `Qt5Core_VERSION_MAJOR` and `Qt5Core_VERSION_MINOR` directory properties. – Tsyvarev Dec 17 '21 at 16:21
  • @tsyvarev IMO, `find_package` looks weird and works the same. Where it searches for packages, which variables it exposes, how to search on windows platform? It is clear where it searches on unix system and how to get a dependency (system-wide which is another source of problems and development-portability issues) but how to install say boost on windows and make it `find_package`-aware i don't know. I like when dependencies are clearly defined and any developer can just pull and not be bothered with their management – IC_ Dec 17 '21 at 16:44
  • 1
    "but how to install say boost on windows and make it `find_package`-aware i don't know." - You may e.g. set add installation prefix of Boost to variable [CMAKE_PREFIX_PATH](https://cmake.org/cmake/help/latest/variable/CMAKE_PREFIX_PATH.html). This variable affects on `find_package`. – Tsyvarev Dec 17 '21 at 16:48
  • so, i guess, it'll either break on other user's environment due to custom installation path or would force each developer to follow strict rules – IC_ Dec 17 '21 at 17:02
  • This may help with customization: [https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html](https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html) – drescherjm Dec 17 '21 at 17:19
  • For the love of $DEITY use `find_package`! There is no way to be _more_ straightforward than to use _the primary and first-party supported mechanism for using Qt_... to use Qt! – Alex Reinking Dec 17 '21 at 19:12

1 Answers1

-1

Adding that code helped me. Thanks @Tsyvarev for pointing out

set(PROGRAM_EXTENSION)
if (WIN32)
    set(PROGRAM_EXTENSION .exe)
endif()
set(AUTOMOC_EXECUTABLE ${CMAKE_SOURCE_DIR}/3rdparty/qt5/bin/${OS}/moc${PROGRAM_EXTENSION})
add_executable(Qt5::moc IMPORTED)
set_target_properties(Qt5::moc PROPERTIES IMPORTED_LOCATION "${AUTOMOC_EXECUTABLE}")
set(Qt5Core_VERSION_MAJOR 5)
set(Qt5Core_VERSION_MINOR 15)
set(CMAKE_AUTOMOC TRUE)

Qt5CoreMacros.cmake must be included before

IC_
  • 1,624
  • 1
  • 23
  • 57