Working with to executable targets in CMake
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?
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.
@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.cppand I try to Build & Run
target1it fails even though it's possible to compile
target1manually by itself.
What version of CMake are you using ?
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.