Running a batch script before object files are compiled

I have a batch script which generates a .c file (fsdata_custom.c)
I need to run this script every time I build my aplication but before the application object files are built.

So far I have:

Build FS data for display webpage

add_custom_target(createCustomFSOnChange DEPEND ALL
COMMAND ${CMAKE_SOURCE_DIR}/Scripts/create_fsdata_custom.bat ${CMAKE_BUILD_TYPE}
COMMENT “Validating HMTL FS”)

add_executable(${EXECUTABLE} ./core/src/main.c)
add_dependencies(${EXECUTABLE} createCustomFSOnChange)

The script runs but after the fsdata_custom.c had been built into an object so the old version is linked into the executable.
I would really apreciate some help on where I’m going wrong!

You want to use add_custom_command.

add_custom_command(
  OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/fsdata_custom.$<CONFIG>.c"
  DEPENDS "${CMAKE_SOURCE_DIR}/Scripts/create_fsdata_custom.bat"
  COMMAND "${CMAKE_SOURCE_DIR}/Scripts/create_fsdata_custom.bat" "$<CONFIG>"
  COMMENT "Validating HMTL FS")
add_executable("${EXECUTABLE}" core/src/main.c "${CMAKE_CURRENT_BINARY_DIR}/fsdata_custom.$<CONFIG>.c")

@ben.boeckel CONFIG is not a known keyword for the add_custom_command() command. I think you probably mean COMMAND instead?

D’oh, yes. Updated.