79558509

Date: 2025-04-06 17:26:08
Score: 0.5
Natty:
Report link

I think @Dominik Kasewski's answer is more appropriate for what you want to do but there is also the configure_file mechanism

configure_file(myfile.h.in myfile.h)

CMake will take myfile.h.in and expand cmake variables in it:

static constexpr const char * build_type = "${CMAKE_BUILD_TYPE}";

to create a file that

static constexpr const char * build_type = "Debug";

for example.

Since this is more complicated than what @Dominik Kaszewski suggests, I would go with their answer but if you have more information that you want to pass from CMake to the source code, then this is a convenient way to do it.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @Dominik
  • User mentioned (0): @Dominik
  • Low reputation (0.5):
Posted by: Philippe Carphin