OlivierLDff / QtIosCMake

📱 Deploy Qt Application for iOS with a single macro when using CMake.
BSD 3-Clause "New" or "Revised" License
58 stars 15 forks source link

I should use QT_LIBRARIES instead of target_link_libraires? #3

Closed davemilter closed 4 years ago

davemilter commented 4 years ago

Thanks for project, @OlivierLDff !

I try to use it via:

cmake_minimum_required(VERSION 3.5)

project(foo LANGUAGES CXX)

find_package(Qt5 COMPONENTS Core Quick REQUIRED)

set(CMAKE_AUTORCC ON)

add_executable(foo main.cpp qml.qrc)

target_compile_definitions(foo
  PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)

# conflict with AddQtIosApp.cmake
target_link_libraries(foo PRIVATE Qt5::Core Qt5::Quick)

IF(${CMAKE_SYSTEM_NAME} STREQUAL "iOS")
#  set(QT_LIBRARIES Qt5::Core Qt5::Quick)  
  include(QtIosCMake/AddQtIosApp.cmake)

  add_qt_ios_app(foo)
ENDIF()

It fails on

cmake -DCMAKE_PREFIX_PATH=/Users/user/Qt/5.12.7/ios -DDEPLOYMENT_TARGET=11.0 -DCMAKE_TOOLCHAIN_FILE=../IosCMakeToolchain/ios.toolchain.cmake -DPLATFORM=OS64 -DENABLE_BITCODE=FALSE -G "Xcode" ..

...

CMake Error at QtIosCMake/AddQtIosApp.cmake:351 (target_link_libraries):
  The keyword signature for target_link_libraries has already been used with
  the target "foo".  All uses of target_link_libraries with a target must be
  either all-keyword or all-plain.

  The uses of the keyword signature are here:

   * CMakeLists.txt:16 (target_link_libraries)

So I have to remove target_link_libraries and set QT_LIBRARIES. Is it expected behaviour? I can not find any mention of QT_LIBRARIES in REAMDE.

Here full source if you can not reproduce problem: https://github.com/davemilter/qt_ios_libs_bug

cmake version 3.17.1, Macos 10.14.6

OlivierLDff commented 4 years ago

Ok so here is some documentation about your error : https://cmake.org/cmake/help/v3.0/policy/CMP0023.html

Turn target_link_libraries(foo PRIVATE Qt5::Core Qt5::Quick) to target_link_libraries(foo Qt5::Core Qt5::Quick)

So plain and keyword target_link_libraries cannot be mixed. I'm using the plain target_link_libraries in most of my libraries since it make more sense to carry dependencies. Especially for superbuild.

If you want to code to work you should set(CMP0023 OLD)

But reading from https://cliutils.gitlab.io/modern-cmake/chapters/basics.html it seems that keyword is now the preferred way to go. I will update the script to follow this guidance.

So wait for the next commit on QtStaticCMake, i add another comment here when it will be done.

OlivierLDff commented 4 years ago

https://github.com/OlivierLDff/QtStaticCMake/commit/4db120d668bfaa524e351eb34e19f229aa46effd should now fix your issue and https://github.com/OlivierLDff/QtIosCMake/commit/c8c5aa336f6812c8de8561a751a1ac773db9e723. I also suggest you to change set(CMAKE_AUTORCC ON) to set_target_properties(foo PROPERTIES AUTORCC TRUE), same if you would use AUTOMOC. This avoid moc to run on target that don't use qt, in superbuild.

davemilter commented 4 years ago

Thanks, @OlivierLDff!

This issue is fixed for me.

I also suggest you to change

I don't use any AUTO* stuff in real project. This is just to simplify my example.