Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to configure CMakeLists.txt files of projects for have separated projects in Qt Creator instead one project
Forum Updated to NodeBB v4.3 + New Features

How to configure CMakeLists.txt files of projects for have separated projects in Qt Creator instead one project

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 4.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Alexander Symonenko
    wrote on last edited by
    #1

    I have 2 executable projects each of which depends from 2 libraries in one solution (root CMakeLists.txt). Build is ok and as result I have 2 libraries and 2 executable. But when I try to open root CMakeLists.txt in Qt creator instead 4 projects (src1, src2, subproject1, subproject2) & CMakeLists.txt in the root as result I have only 1 project with name "Project" which includes my 4 projects in "Project" container like this is include folders.

    Also I cannot select project for run (Set project "Project" as Active Project) since this is only one project. After run from Qt the MainProject1 was run.

    StackOverflow and google propoused to use add_subdirectory for this but this does not work. In my CMakeLists's for make depends and several projects I already had used add_subdirectory.

    Qt version: 5.7.0.
    Qt Creator version: 4.0.2.
    Ubuntu
    

    Please help me for fix this. Thanks in advance.

    Project structure & manual build & results: Succeed

    Project structure:

    root
        src1                    (executable which depends from subproject1 and subproject2)
            CMakeLists.txt
            main.cpp
        src2                    (executable which depends from subproject1 and subproject2)
            CMakeLists.txt
            main.cpp
        subproject1             (library)
            CMakeLists.txt
            hellow.cpp
            hellow.h
        subproject2             (library)
            CMakeLists.txt
            hellow.cpp
            hellow.h
        CMakeLists.txt          (the root CMakeLists)
    

    Build & show results:

    mkdir -p build && cd build && cmake .. && make &&
    ll src1/MainProject1 && ll src2/MainProject2 && ll subproject1/libsubproject1.a && ll subproject2/libsubproject2.a
    

    Results:

    -rwxrwxr-x 1 qqq qqq 13570 Jun  1 10:45 src1/MainProject1*
    -rwxrwxr-x 1 qqq qqq 13570 Jun  1 10:45 src2/MainProject2*
    -rw-rw-r-- 1 qqq qqq 2820 Jun  1 10:45 subproject1/libsubproject1.a
    -rw-rw-r-- 1 qqq qqq 2828 Jun  1 10:45 subproject2/libsubproject2.a 
    

    All is ok

    CMakeLists.txt

    Root CMakeLists.txt

    cmake_minimum_required(VERSION 2.8)
    add_subdirectory( src1 )
    add_subdirectory( src2 )
    

    subproject1/CMakeLists.txt

    cmake_minimum_required(VERSION 2.8)
    project(subproject1)
    
    set (sources
            ./hellow.cpp
            ./hellow.h
        )
    add_library(subproject1 STATIC ${sources})
    

    subproject2/CMakeLists.txt

    Is the same but instead subproject1: subproject2

    src1/CMakeLists.txt

    cmake_minimum_required(VERSION 2.8)
    project(MainProject1)
    
    set (sources
            ./main.cpp
        )
    
    if (NOT TARGET subproject1)
         add_subdirectory( ./../subproject1 "${CMAKE_CURRENT_BINARY_DIR}/../subproject1" )
         add_subdirectory( ./../subproject2 "${CMAKE_CURRENT_BINARY_DIR}/../subproject2" )
    endif() 
    
    add_executable(MainProject1 ${sources})
    target_link_libraries (MainProject1 subproject1)
    target_link_libraries (MainProject1 subproject2)
    add_dependencies( MainProject1 subproject1 )
    add_dependencies( MainProject1 subproject2 )
    

    src2/CMakeLists.txt

    Is the same but instead MainProject1: MainProject2

    Open in Qt Creator: Failed

    Open root CMakeLists.txt & configure for build in build folder.

    Result of project structure (only 1 project):

    root
        Project
            CMakeLists.txt
            src1
            src2
            subproject1
            subproject2
    

    Expect (4 projects):

    root
        src1
        src2
        subproject1
        subproject2
        CMakeLists.txt
    

    Result of build:

    cd build && ll src1/MainProject1 && ll src2/MainProject2 && ll subproject1/libsubproject1.a && ll subproject2/libsubproject2.a
    
    -rwxrwxr-x 1 qqq qqq 38670 Jun  1 11:10 src1/MainProject1*
    -rwxrwxr-x 1 qqq qqq 38670 Jun  1 11:10 src2/MainProject2*
    -rw-rw-r-- 1 qqq qqq 21900 Jun  1 11:10 subproject1/libsubproject1.a
    -rw-rw-r-- 1 qqq qqq 21908 Jun  1 11:10 subproject2/libsubproject2.a
    

    Build is ok.

    Run project

    MainProject1 was run. Cannot select project for run since Qt Creator perceives root CMakeLists as if it's only one project.

    Note

    Correspound link to question in StackOverflow

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      First thing you should do is to update Qt Creator. 4.3 just got released with a revamped and improved support for cmake.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • A Offline
        A Offline
        Alexander Symonenko
        wrote on last edited by Alexander Symonenko
        #3

        Thank you. After discovering I see that Qt Creator cannot have several projects using cmake like in Visual Studio solutions ;-( It can have only one root project from root CMakeLists.txt. But Qt Creator allow to select which executiable should be run after build of root project:

        You should add multiple projects to the root cmake file with help of "add_subdirectory()". Then in Qt Creator you should open the root cmake file. After that you could choose which project to run in the select a kit for running (3) or debugging (4) application pane (check the link).
        It sad that you can't (or I don't know how) build only one project. You have to build all projects are added to the root cmake file and then choose which one of them you want to run.
        I use Qt Creator 4.0.
        https://stackoverflow.com/questions/19466141/how-to-load-cmake-script-with-more-than-one-project-with-qt-creator

        As result of restrict support of multiple projects you cannot select which subproject to compile but can select executiable for run.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Thanks for the feedback, you should take a look at the bug report system to see if there's something related and maybe consider a feature request about that matter if nothing already exists.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved