-1

You have your own cmake c++ project, you need to create a compilation key and get information about it in the code.

I need something like this.

in CmakeLists.txt:

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -myTest")

in *.cpp

if(KEY == "myTest"){
    // testing code.
}
shaman888
  • 283
  • 1
  • 10

1 Answers1

1

in CMakeLists.txt

add_compile_definitions(TESTING)
add_compile_options(-Wall)

in *.cpp

#ifdef TESTING
    std::cout << "testing" << std::endl;
#else
#endif
Bktero
  • 722
  • 5
  • 15
shaman888
  • 283
  • 1
  • 10
  • Modern way to add compiler option is to use add_compile_option() --> https://cmake.org/cmake/help/latest/command/add_compile_options.html?highlight=add_compile_option Modern way to add preprocessor definition is to use add_compile_definitions() --> https://cmake.org/cmake/help/latest/command/add_compile_definitions.html#command:add_compile_definitions – Bktero Nov 18 '19 at 08:27