cmake error: the dependency of target dos not exist

SO stack oveflow spam check says my post is MOSTLY CODE… yea it is..
But I need to demonstrate the problem with a full example that I have
extracted from a much larger set of files so I can boil it down to
an example that demonstrates the issue. GRRR…

The CMakefile:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>
# -*- mode: cmake -*-
cmake_minimum_required( VERSION 3.25 )
# Given a list of DAT files..
# Generate the .H list for the dat files
# and create targets to execute Python commands to generate the script.
set(Python_EXECUTABLE "python3")
set(EXTRACTOR_PY "some/dir/extractor.py")
# INPUT: DAT filename
# OUTPUT: Generated .H filename in the ${outdir}
function( _dat2hdr_name_h filename_dat outdir OUT_VAR )
cmake_path(GET filename_dat FILENAME tmp )
message("tmp: ${tmp}")
cmake_path(REPLACE_EXTENSION tmp ".h" OUTPUT_VARIABLE filename_h )
set(tmp2 "${filename_h}")
message("filname_h: ${filename_h}")
message("outdir: ${outdir}")
set(tmp3 "${outdir}/${tmp2}")
set( ${OUT_VAR} "${tmp3}" PARENT_SCOPE )
endfunction()
# Given a list of DAT files
# Generate the commands to convert DAT to .H via python.
# and make the EXE dependent on the H files
function( dat2hdr EXE_NAME DAT_LIST OUTPUT_DIR )
# for each DAT file name, create a matching .H filename.
foreach(tmp_dat ${DAT_LIST})
message("tmp_dat: ${tmp_dat}")
_dat2hdr_name_h( ${tmp_dat} ${OUTPUT_DIR} tmp_h )
message("tmp_h: ${tmp_h}")
message("EXTRACTOR: ${EXTRACTOR_PY}")
message("tmp_h: ${tmp_h}")
message("tmp_dat: ${tmp_dat}")
# create the command to create the .h file for this dat file.
add_custom_command(
OUTPUT "${tmp_h}"
COMMAND
${Python_EXECUTABLE}
${EXTRACTOR_PY}
"${tmp_dat}"
"${tmp_h}"
VERBATIM
)
# The EXE depends on this .H file
# so make the EXE depend on this .H file.
add_dependencies( ${EXE_NAME} "${tmp_h}")
endforeach()
endfunction()
set( exe_name "foo.elf" )
project( ${exe_name} )
add_executable( ${exe_name} "foo.c" )
set( datlist "datadir/foo.dat;datadir/bar.dat;datadir/x.dat" )
set( outdir "./generated/include" )
dat2hdr( ${exe_name} "${datlist}" "${outdir}" )
</code>
<code> # -*- mode: cmake -*- cmake_minimum_required( VERSION 3.25 ) # Given a list of DAT files.. # Generate the .H list for the dat files # and create targets to execute Python commands to generate the script. set(Python_EXECUTABLE "python3") set(EXTRACTOR_PY "some/dir/extractor.py") # INPUT: DAT filename # OUTPUT: Generated .H filename in the ${outdir} function( _dat2hdr_name_h filename_dat outdir OUT_VAR ) cmake_path(GET filename_dat FILENAME tmp ) message("tmp: ${tmp}") cmake_path(REPLACE_EXTENSION tmp ".h" OUTPUT_VARIABLE filename_h ) set(tmp2 "${filename_h}") message("filname_h: ${filename_h}") message("outdir: ${outdir}") set(tmp3 "${outdir}/${tmp2}") set( ${OUT_VAR} "${tmp3}" PARENT_SCOPE ) endfunction() # Given a list of DAT files # Generate the commands to convert DAT to .H via python. # and make the EXE dependent on the H files function( dat2hdr EXE_NAME DAT_LIST OUTPUT_DIR ) # for each DAT file name, create a matching .H filename. foreach(tmp_dat ${DAT_LIST}) message("tmp_dat: ${tmp_dat}") _dat2hdr_name_h( ${tmp_dat} ${OUTPUT_DIR} tmp_h ) message("tmp_h: ${tmp_h}") message("EXTRACTOR: ${EXTRACTOR_PY}") message("tmp_h: ${tmp_h}") message("tmp_dat: ${tmp_dat}") # create the command to create the .h file for this dat file. add_custom_command( OUTPUT "${tmp_h}" COMMAND ${Python_EXECUTABLE} ${EXTRACTOR_PY} "${tmp_dat}" "${tmp_h}" VERBATIM ) # The EXE depends on this .H file # so make the EXE depend on this .H file. add_dependencies( ${EXE_NAME} "${tmp_h}") endforeach() endfunction() set( exe_name "foo.elf" ) project( ${exe_name} ) add_executable( ${exe_name} "foo.c" ) set( datlist "datadir/foo.dat;datadir/bar.dat;datadir/x.dat" ) set( outdir "./generated/include" ) dat2hdr( ${exe_name} "${datlist}" "${outdir}" ) </code>

# -*- mode: cmake -*-
cmake_minimum_required( VERSION 3.25 )
# Given a list of DAT files..
#  Generate the .H list for the dat files
#  and create targets to execute Python commands to generate the script.

set(Python_EXECUTABLE "python3")
set(EXTRACTOR_PY "some/dir/extractor.py")

# INPUT: DAT filename
# OUTPUT:  Generated .H filename in the ${outdir}
function( _dat2hdr_name_h filename_dat outdir OUT_VAR )
  cmake_path(GET filename_dat FILENAME tmp )
  message("tmp: ${tmp}")
  cmake_path(REPLACE_EXTENSION tmp ".h" OUTPUT_VARIABLE filename_h )
  set(tmp2 "${filename_h}")
  message("filname_h: ${filename_h}")
  message("outdir: ${outdir}")
  set(tmp3 "${outdir}/${tmp2}")
  set( ${OUT_VAR} "${tmp3}" PARENT_SCOPE )
endfunction()

# Given a list of DAT files
#   Generate the commands to convert DAT to .H via python.
#   and make the EXE dependent on the H files
function( dat2hdr EXE_NAME   DAT_LIST  OUTPUT_DIR )

    # for each DAT file name, create a matching .H filename.
    foreach(tmp_dat ${DAT_LIST})
      message("tmp_dat: ${tmp_dat}")
      _dat2hdr_name_h( ${tmp_dat} ${OUTPUT_DIR} tmp_h )
      message("tmp_h: ${tmp_h}")

      message("EXTRACTOR: ${EXTRACTOR_PY}")
      message("tmp_h: ${tmp_h}")
      message("tmp_dat: ${tmp_dat}")
      # create the command to create the .h file for this dat file.
      add_custom_command(
    OUTPUT "${tmp_h}"
        COMMAND
            ${Python_EXECUTABLE}      
            ${EXTRACTOR_PY}
            "${tmp_dat}"
            "${tmp_h}"
          VERBATIM
      )

      # The EXE depends on this .H file
      # so make the EXE depend on this .H file.
      add_dependencies( ${EXE_NAME} "${tmp_h}")

      endforeach()
endfunction()

set( exe_name "foo.elf" )
project( ${exe_name} )
add_executable( ${exe_name} "foo.c" )

set( datlist "datadir/foo.dat;datadir/bar.dat;datadir/x.dat" )

set( outdir "./generated/include" )

dat2hdr( ${exe_name} "${datlist}" "${outdir}" )

The error output I get

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>
bash-4.2$ cmake ..
tmp_dat: datadir/foo.dat
tmp: foo.dat
filname_h: foo.h
outdir: ./generated/include
tmp_h: ./generated/include/foo.h
EXTRACTOR: some/dir/extractor.py
tmp_h: ./generated/include/foo.h
tmp_dat: datadir/foo.dat
tmp_dat: datadir/bar.dat
tmp: bar.dat
filname_h: bar.h
outdir: ./generated/include
tmp_h: ./generated/include/bar.h
EXTRACTOR: some/dir/extractor.py
tmp_h: ./generated/include/bar.h
tmp_dat: datadir/bar.dat
tmp_dat: datadir/x.dat
tmp: x.dat
filname_h: x.h
outdir: ./generated/include
tmp_h: ./generated/include/x.h
EXTRACTOR: some/dir/extractor.py
tmp_h: ./generated/include/x.h
tmp_dat: datadir/x.dat
-- Configuring done
CMake Error at CMakeLists.txt:48 (add_dependencies):
The dependency target "./generated/include/bar.h" of target "foo.elf" does
not exist.
Call Stack (most recent call first):
CMakeLists.txt:61 (dat2hdr)
...[snip] more errors ...
</code>
<code> bash-4.2$ cmake .. tmp_dat: datadir/foo.dat tmp: foo.dat filname_h: foo.h outdir: ./generated/include tmp_h: ./generated/include/foo.h EXTRACTOR: some/dir/extractor.py tmp_h: ./generated/include/foo.h tmp_dat: datadir/foo.dat tmp_dat: datadir/bar.dat tmp: bar.dat filname_h: bar.h outdir: ./generated/include tmp_h: ./generated/include/bar.h EXTRACTOR: some/dir/extractor.py tmp_h: ./generated/include/bar.h tmp_dat: datadir/bar.dat tmp_dat: datadir/x.dat tmp: x.dat filname_h: x.h outdir: ./generated/include tmp_h: ./generated/include/x.h EXTRACTOR: some/dir/extractor.py tmp_h: ./generated/include/x.h tmp_dat: datadir/x.dat -- Configuring done CMake Error at CMakeLists.txt:48 (add_dependencies): The dependency target "./generated/include/bar.h" of target "foo.elf" does not exist. Call Stack (most recent call first): CMakeLists.txt:61 (dat2hdr) ...[snip] more errors ... </code>

bash-4.2$ cmake ..
tmp_dat: datadir/foo.dat
tmp: foo.dat
filname_h: foo.h
outdir: ./generated/include
tmp_h: ./generated/include/foo.h
EXTRACTOR: some/dir/extractor.py
tmp_h: ./generated/include/foo.h
tmp_dat: datadir/foo.dat
tmp_dat: datadir/bar.dat
tmp: bar.dat
filname_h: bar.h
outdir: ./generated/include
tmp_h: ./generated/include/bar.h
EXTRACTOR: some/dir/extractor.py
tmp_h: ./generated/include/bar.h
tmp_dat: datadir/bar.dat
tmp_dat: datadir/x.dat
tmp: x.dat
filname_h: x.h
outdir: ./generated/include
tmp_h: ./generated/include/x.h
EXTRACTOR: some/dir/extractor.py
tmp_h: ./generated/include/x.h
tmp_dat: datadir/x.dat
-- Configuring done
CMake Error at CMakeLists.txt:48 (add_dependencies):
  The dependency target "./generated/include/bar.h" of target "foo.elf" does
  not exist.
Call Stack (most recent call first):
  CMakeLists.txt:61 (dat2hdr)

 ...[snip] more errors ...

The target: ‘foo.elf’ exists, I create it via “add_executable()”
The H file does not exist becuase I need to run Python to create it from a dat file.

I’m confused why this does not work.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật