1

I have created small project for using catch2 testing framework. I set the specific command line option called --use-colour to yes in terminal like below:

root@ramil-instance:~/testing/build# ./testing --use-colour yes

How can I define this command line option in CMakeLists.txt file instead of terminal

This is my CMakeLists.txt file:

cmake_minimum_required(VERSION 3.0)

set(CMAKE_BUILD_TYPE Debug)

project(testing)

add_executable(
    testing
    test.cpp
)
Alex Reinking
  • 16,724
  • 5
  • 52
  • 86
  • One solution is to define it in the cmake cache via `ccmake .` . – Vorac Jun 21 '21 at 08:36
  • I've fixed your formatting. Note that setting `CMAKE_BUILD_TYPE` in the CMakeLists.txt file is _**highly discouraged**_. It is meant to be set at the `cmake` command line via `-DCMAKE_BUILD_TYPE=` – Alex Reinking Jun 21 '21 at 08:41
  • Voting to reopen. I don't think the marked duplicate is in fact a duplicate of this question. Moreover, the answer on that duplicate is... horrifying. Nobody should do that. – Alex Reinking Jun 21 '21 at 08:59
  • You're welcome. Please be sure to "edit" your question to see how formatting works if you choose to open a different question later on. – Alex Reinking Jun 21 '21 at 09:08
  • @AlexReinking: The **questions** are essentially **similar**, that is why I marked them as duplicate. "Moreover, the answer on that duplicate is... horrifying." - No problem, you are free to provide your own answer to the duplicated question... Oh, you have already done that. – Tsyvarev Jun 21 '21 at 10:22
  • @Tsyvarev - Indeed I have, but any solution to _that_ question is _not_ an answer to this one. I would have liked to post an answer demonstrating CTest and/or Catch2's CTest bindings, which would have been appropriate for this question. The fundamental difference between the two is that here OP does not control the `main()` function for the program in question. – Alex Reinking Jun 21 '21 at 10:27
  • @AlexReinking: "The fundamental difference between the two is that here OP does not control the `main()` function for the program in question." - But why do you think that OP of the other question has a control over `main` function? "I would have liked to post an answer demonstrating CTest and/or Catch2's CTest bindings" - Then your answer would better fit for [that question](https://stackoverflow.com/questions/34896891/catch-lib-unit-testing-and-ctest-cmake-integration), which asks specifically about CTest and Ctach integration. – Tsyvarev Jun 21 '21 at 10:41
  • @Tsyvarev - [The question you just referenced](https://stackoverflow.com/questions/34896891/catch-lib-unit-testing-and-ctest-cmake-integration) is a _much_ better duplicate for this one. – Alex Reinking Jun 21 '21 at 10:43
  • @AlexReinking: Note, that a single question could have more than one duplicate target, and gold-badge users (like me) are able to edit list of duplicate targets at any time. If you think you know another (or better) duplicate target, just write that in the comment. – Tsyvarev Jun 21 '21 at 10:44
  • In that case, would you please be so kind as to edit the list of duplicate targets to include the question you found? Or do you disagree it is a better duplicate? – Alex Reinking Jun 21 '21 at 10:45
  • @AlexReinking: Already done. Your previous comment ("The question you just referenced is a much better duplicate for this one.") was sufficient. – Tsyvarev Jun 21 '21 at 10:46
  • @Tsyvarev - I believe we posted our two comments simultaneously. – Alex Reinking Jun 21 '21 at 10:46

0 Answers0