Connecting CMakeLists.txt with project



  • Hello,
    I work with UHD Driver (for USRP device) and I have already written some code. My project contains main.cpp and CMakeLists.txt. I would like to plot samples which i recieve from the device. I thought QT would be the best choice.
    The main problem is I don't know how can I open the files which already exist and expand the project with GUI using QT.
    When I try to open this project defaultly I recieve plain C++ mode and I can't use QT's cpabilities.
    I work on Ubuntu and I have installed newest Cmake version.

    CMakeLists.txt looks like this

    cmake_minimum_required(VERSION 2.8)
    
    
    option(UHD_USE_STATIC_LIBS OFF)
    
    
    set(BOOST_REQUIRED_COMPONENTS
        program_options
        system
        thread
    )
    if(MSVC)
        set(BOOST_ALL_DYN_LINK "${BOOST_ALL_DYN_LINK}" CACHE BOOL "boost enable dynamic linking")
        if(BOOST_ALL_DYN_LINK)
            add_definitions(-DBOOST_ALL_DYN_LINK) #setup boost auto-linking in msvc
        else(BOOST_ALL_DYN_LINK)
            set(BOOST_REQUIRED_COMPONENTS) #empty components list for static link
        endif(BOOST_ALL_DYN_LINK)
    endif(MSVC)
    find_package(Boost "1.46" REQUIRED ${BOOST_REQUIRED_COMPONENTS})
    
    if(CMAKE_VERSION VERSION_LESS "3.1")
        if(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
            set(CMAKE_CXX_FLAGS "--std=gnu++11 ${CMAKE_CXX_FLAGS}")
        elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
            if("${IS_APPLE}" STREQUAL "")
                set(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
            else()
                set(CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++ ${CMAKE_CXX_FLAGS}")
            endif()
        endif()
    else()
        set(CMAKE_CXX_STANDARD 11)
    endif()
    
    if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" AND ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
        set(CMAKE_EXE_LINKER_FLAGS "-lthr ${CMAKE_EXE_LINKER_FLAGS}")
        set(CMAKE_CXX_FLAGS "-stdlib=libc++ ${CMAKE_CXX_FLAGS}")
    endif()
    
    include_directories(
        ${Boost_INCLUDE_DIRS}
        ${UHD_INCLUDE_DIRS}
    )
    link_directories(${Boost_LIBRARY_DIRS})
    
    
    add_executable(projekt projekt.cpp)
    
    set(CMAKE_BUILD_TYPE "Release")
    message(STATUS "******************************************************************************")
    message(STATUS "* NOTE: When building your own app, you probably need all kinds of different  ")
    message(STATUS "* compiler flags. This is just an example, so it's unlikely these settings    ")
    message(STATUS "* exactly match what you require. Make sure to double-check compiler and     ")
    message(STATUS "* linker flags to make sure your specific requirements are included.          ")
    message(STATUS "******************************************************************************")
    
    
    if(NOT UHD_USE_STATIC_LIBS)
        message(STATUS "Linking against shared UHD library.")
        target_link_libraries(projekt ${UHD_LIBRARIES} ${Boost_LIBRARIES})
    
    else(NOT UHD_USE_STATIC_LIBS)
        message(STATUS "Linking against static UHD library.")
        target_link_libraries(projekt
    
        )
    endif(NOT UHD_USE_STATIC_LIBS)
    

    I use that in my project:

    #include <uhd/utils/thread.hpp>
    #include <uhd/utils/safe_main.hpp>
    #include <uhd/usrp/multi_usrp.hpp>
    #include <uhd/exception.hpp>
    #include <uhd/types/tune_request.hpp>
    #include <boost/program_options.hpp>
    #include <boost/format.hpp>
    #include <boost/thread.hpp>
    

    Thanks for answeres :)


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Here you have the Qt CMake manual that should get you started.



  • Honestly I have already read it and it isn't clear for me at all.


  • Lifetime Qt Champion

    To get started, did you try to build a simple Qt application using the information of that guide ?


  • Qt Champions 2018

    @JayJay said in Connecting CMakeLists.txt with project:

    and I can't use QT's cpabilities

    Are you saying you can't use Qt or you can't use Qt Creator?



  • I mean, when I open my project by CMakeLists it doesnt't give me the opurtinity to using QT like I would use it with .pro file. When I right click on the project the option "Add new" is blanked.


  • Lifetime Qt Champion

    @JayJay
    That is normal as far as i know.
    With cmake, you must manually add new files.


Log in to reply