-3
if (WITH_TEST)
    add_subdirectory(test/unitTesting)
endif(WITH_TEST)

How do you read the with_test variable in a .cpp file?

2

1 Answer 1

0

A solution could be to add preprocessor definition.

in your CMakeLists :

add_definitions(-DWITH_TEST_VALUE ="${WITH_TEST}")

And in you source code you could do something like this :

#ifdef WITH_TEST_VALUE
constexpr auto WITH_TEST = WITH_TEST_VALUE;
#else
 // something 
#endif
Sign up to request clarification or add additional context in comments.

1 Comment

cmake -DWITH_TEST=ON ../ when it compiles it gives error i.e c++: error: =ON: No such file or directory

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.