All,
I’m not sure how to do what I want, so I’m hoping the gurus here can help. In some code where we build Wavewatch in the model I work on, we have CMake like this:
set (WW3ESMF_F90)
foreach(src_file ${WW3ESMF_FTN})
STRING(REGEX REPLACE ".ftn" ".F90" gen_src_file ${src_file})
STRING(REGEX REPLACE "/" "_" gen_log_file ${gen_src_file})
add_custom_command(
OUTPUT ${gen_src_file}
BYPRODUCTS ${gen_src_file}
DEPENDS w3adc ${ftn_dir}/${src_file}
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/run_w3adc.sh ${ftn_dir} ${src_file} > ${gen_log_file}.w3adc.log 2>&1
COMMENT "Running w3adc ${src_file}")
list(APPEND WW3ESMF_F90 ${gen_src_file})
endforeach()
because the Wavewatch tag we currently use is the older style that had files like constants.ftn
that you then used w3adc
on to generate constants.f90
. Weird, but works. (I think Wavewatch has gotten rid of this but we still have it until the next release.)
Recently I was reminded that Ninja no longer builds our model and I tracked it down to this block and the fact that things build just fine if the BYPRODUCTS
line is not in that add_custom_command
.
Now the fun part: apparently if I want to build this with GNU plus the Unix Makefiles generator, that BYPRODUCTS
is needed!
With some testing I see that:
if (CMAKE_GENERATOR STREQUAL "Unix Makefiles")
set(BYPRODUCTS ${gen_src_file})
else()
set(BYPRODUCTS "")
endif()
add_custom_command(
OUTPUT ${gen_src_file}
BYPRODUCTS ${BYPRODUCTS}
DEPENDS w3adc ${ftn_dir}/${src_file}
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/run_w3adc.sh ${ftn_dir} ${src_file} > ${gen_log_file}.w3adc.log 2>&1
COMMENT "Running w3adc ${src_file}")
works but it seems…wrong? Works, but wrong.
So, I was wondering if there is any clever generator expression I could use to say “If CMAKE_GENERATOR
is Ninja, no BYPRODUCTS
, else yes BYPRODUCTS
?”