Hi,

I am building a library project in pure cmake, as generated by qtcreator wizzard:

Qt Code:
  1. cmake_minimum_required(VERSION 3.14)
  2.  
  3. project(testlib LANGUAGES CXX)
  4.  
  5. set(CMAKE_INCLUDE_CURRENT_DIR ON)
  6. set(CMAKE_AUTOUIC ON)
  7. set(CMAKE_AUTOMOC ON)
  8. set(CMAKE_AUTORCC ON)
  9. set(CMAKE_CXX_STANDARD 11)
  10. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  11.  
  12. find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)
  13. find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED)
  14.  
  15. add_library(testlib SHARED
  16. testlib_global.h
  17. testlib.cpp
  18. testlib.h
  19. )
  20.  
  21. target_link_libraries(testlib PRIVATE Qt${QT_VERSION_MAJOR}::Core)
  22.  
  23. target_compile_definitions(testlib PRIVATE TESTLIB_LIBRARY)
To copy to clipboard, switch view to plain text mode 


Now I want to compile it from command line without qtcreator.
I do

Qt Code:
  1. cmake ..
  2. cmake --build .
To copy to clipboard, switch view to plain text mode 

But it tries to link the x86 build of qt into a x64 target, which fails. I have to add the following line, then it works:

Qt Code:
  1. set(CMAKE_PREFIX_PATH "c:\qt\msvc2019_x64")
To copy to clipboard, switch view to plain text mode 

My question: What is the correct way to specify the arch of the Qt library to be linked with cmake? What is the correct way to specify the arch for my library? (Both from pure commandline and not from within Qtcreator...)


Also ... I dont really understand how cmake can find the x86 version of Qt. How does it even know it exists?