Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Working with to executable targets in CMake
Forum Updated to NodeBB v4.3 + New Features

Working with to executable targets in CMake

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
5 Posts 2 Posters 1.1k 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.
  • F Offline
    F Offline
    flashmozzg
    wrote on last edited by
    #1

    Hello, I'm having trouble understanding whether the behaviour I'm experiencing is qtc bug or just badly written CMakeLists.txt

    My problem: I've created a simple CmakeLists.txt for my project. I have one header and to cpps with main(). I wanted to create to targets, so that it'd be easier to switch between each cpp as a main().

    So I just did add_executable(target1 "header.h" "main1.cpp") and add_executable add_executable(target2 "header.h" "main2.cpp"). It created two targets and is recognized by QtC (I can see both target1 and target2 in Build & Run run category and in project view).

    However the problem I'm having is: whether I try to Build or Run the current target (Ctrl+R or Ctrl+B), it tries to build all code anyway (and fails, since the second cpp is not yet finished). If I try to build targets using Project view it works, but I can't run them this way and it's not convenient anyway.

    So what am I doing wrong?

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

      Hi,

      You should add which version of Qt Creator you are using as well as CMake version. You might also want to put a minimal sample that allows to reproduce this behaviour.

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

      F 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        You should add which version of Qt Creator you are using as well as CMake version. You might also want to put a minimal sample that allows to reproduce this behaviour.

        F Offline
        F Offline
        flashmozzg
        wrote on last edited by
        #3

        @SGaist Oh, completely forgot. I'm using Qt Creator 4.5.1 on Win10 x64

        The CMakeLists.txt sample is really basic:

        cmake_minimum_required(VERSION 2.8.12)
        
        project(foo)
        
        add_executable(target1 "header.hpp" "main1.cpp")
        add_executable(target2 "header.hpp" "main2.cpp")
        

        So if there are errors in main2.cpp and I try to Build & Run target1 it fails even though it's possible to compile target1 manually by itself.

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

          What version of CMake are you using ?

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

          F 1 Reply Last reply
          0
          • SGaistS SGaist

            What version of CMake are you using ?

            F Offline
            F Offline
            flashmozzg
            wrote on last edited by
            #5

            @SGaist 3.10.2

            Btw, I've found a "fix" for my problem: changing target to "current executable" in build settings, though not sure why it wasn't a default.

            1 Reply Last reply
            2

            • Login

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