Pergunta

I have a Qt based program with Qxt library. Previously I used the default Qt .pro file to configure the header and library directories, and everything is OK. Now I want to immigrate the thing to build with Cmake, it seems OK to include line by line in the Cmake file. But I saw this:

https://dev.libqxt.org/libqxt/src/a5a0614e4cc4/features/QxtConfig.cmake

Qxt is not built with Cmake as a perquisite. I was wondering how to use this file to find the Qxt like Cmake find qt as a package?

Julio

Foi útil?

Solução

In the top level of your directory tree for your project, add a cmake folder with a Modules subfolder:

your_project_dir/
    |-src/
    |-cmake/
    |   |-Modules/
    |-CMakeLists.txt

Put the QxtConfig.cmake file in cmake/Modules/. In your CMakeLists.txt, add the following lines:

SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules/")
INCLUDE(${CMAKE_MODULE_PATH}/QxtConfig.cmake)

This will run the code in the QxtConfig.cmake file.

Note that if the file were called FindQxt.cmake, you could call FIND_PACKAGE(Qtx) instead of INCLUDE(${CMAKE_MODULE_PATH}/QxtConfig.cmake).

Note

Of course, you don't need to do the whole cmake/Modules/ thing. You could just put the QxtConfig.cmake file next to CMakeLists.txt and omit everything about CMAKE_MODULE_PATH, but it's good practice to have a Modules directory because the number of extra module files can grow in a big project.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top