@@ -418,9 +418,9 @@ macro(HANDLE_SOURCES target useCommon)
418418
419419 # Gather:
420420 # * src/[<target>,common]/include/*.fpp
421- # * (if any) < build> /include/<target>/*.fpp
422- file (GLOB ${target} _incs CONFIGURE_DEPENDS "${${target} _DIR}/include/*.fpp"
423- " ${ CMAKE_BINARY_DIR } /include/ ${ target}/*.fpp" )
421+ # * generated includes from build/include/<target>/ (explicit list, not a GLOB)
422+ file (GLOB ${target} _incs CONFIGURE_DEPENDS "${${target} _DIR}/include/*.fpp" )
423+ list ( APPEND ${target} _incs ${_mfc_gen_files_${ target}} )
424424
425425 if (${useCommon} )
426426 file (GLOB common_incs CONFIGURE_DEPENDS "${common_DIR} /include/*.fpp" )
@@ -494,6 +494,47 @@ if(_mfc_needs_regen)
494494 file (TOUCH "${_mfc_gen_stamp} " )
495495endif ()
496496
497+ # Enumerate the 10 generated .fpp files explicitly so ninja can track them as
498+ # build-time outputs and so HANDLE_SOURCES does not need a configure-time GLOB
499+ # of ${CMAKE_BINARY_DIR}/include/<target>/ (which fails when the dir is empty).
500+ set (_mfc_gen_inc "${CMAKE_BINARY_DIR } /include" )
501+ set (_mfc_gen_files_pre_process
502+ "${_mfc_gen_inc} /pre_process/generated_namelist.fpp"
503+ "${_mfc_gen_inc} /pre_process/generated_decls.fpp"
504+ "${_mfc_gen_inc} /pre_process/generated_constants.fpp"
505+ )
506+ set (_mfc_gen_files_simulation
507+ "${_mfc_gen_inc} /simulation/generated_namelist.fpp"
508+ "${_mfc_gen_inc} /simulation/generated_decls.fpp"
509+ "${_mfc_gen_inc} /simulation/generated_constants.fpp"
510+ "${_mfc_gen_inc} /simulation/generated_case_opt_decls.fpp"
511+ )
512+ set (_mfc_gen_files_post_process
513+ "${_mfc_gen_inc} /post_process/generated_namelist.fpp"
514+ "${_mfc_gen_inc} /post_process/generated_decls.fpp"
515+ "${_mfc_gen_inc} /post_process/generated_constants.fpp"
516+ )
517+ set (_mfc_gen_files_syscheck)
518+ set (_mfc_all_gen_files
519+ ${_mfc_gen_files_pre_process}
520+ ${_mfc_gen_files_simulation}
521+ ${_mfc_gen_files_post_process}
522+ )
523+
524+ # Build-time regeneration: ninja re-runs cmake_gen.py and re-preprocesses
525+ # any .fpp that includes a generated file whenever a params .py changes.
526+ add_custom_command (
527+ OUTPUT ${_mfc_all_gen_files}
528+ COMMAND "${Python3_EXECUTABLE} "
529+ "${CMAKE_CURRENT_SOURCE_DIR } /toolchain/mfc/params/generators/cmake_gen.py"
530+ "${CMAKE_BINARY_DIR } "
531+ DEPENDS ${_mfc_gen_inputs}
532+ WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR } "
533+ COMMENT "Regenerating Fortran parameter includes"
534+ VERBATIM
535+ )
536+ add_custom_target (mfc_params_gen DEPENDS ${_mfc_all_gen_files} )
537+
497538HANDLE_SOURCES (pre_process ON )
498539HANDLE_SOURCES (simulation ON )
499540HANDLE_SOURCES (post_process ON )
0 commit comments