file manipulation at configure time or generate time?

It’s not immediately obvious which functions run at which time. For example file(WRITE | APPEND) runs at configure time, file(CONFIGURE) at generate time.

This code runs at configure time:

file(WRITE eval.cmake ...)
include(eval.cmake)

This code runs at generate time:

file(CONFIGURE OUTPUT  eval.cmake CONTENT ...)
# error: include could not find requested file
# include(eval.cmake)

file(WRITE) creates the file in the source directory and file(CONFIGURE) in the binary directory. This is hard to remember. Shouldn’t the creation of any file default to the binary directory? I know it makes sense the way it is but it makes it much harder to write CMake code.

Is there any resource get an overview, or a way to make it easier to memorize which functions are used at which time?

ah, for file(GENERATE) the documentation draws attention to it:

Note also that file(GENERATE) does not create the output file until the generation phase.

Perhaps it is easier to notice when all functions are listed there. Are file(GENERATE) and file(CONFIGURE) the only one running at generate time?

file(CONFIGURE) seems like it’d run at configure, not generate, time to me.

Note that OUTPUT will treat relative paths as being relative to ${CMAKE_CURRENT_BINARY_DIR} while include() will look in CMAKE_MODULE_PATH. Try doing include("${CMAKE_CURRENT_BINARY_DIR}/eval.cmake") instead.