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.
${...}
constructs in the file and dont want those expanded you can also use @CMAKE_BUILD_TYPE@
and add the @ONLY
argument to configure_file
target_compile_definitions
.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.