[CMake] set_source_files_properties and custom targets
Pentecost, Caleb
Caleb.Pentecost at cognex.com
Thu Mar 1 17:13:41 EST 2018
Howdy,
I'm running into an issue with a custom target dependency that I want to assign to all source files. In this case, I have a helper library (lets call it utils) that builds a couple source files that each depend on an output file from a separate process. It would look something like this:
System/libs/utils/CMakeLists.txt:
# Show CMake how to build the file we need
add_custom_command(
OUTPUT
out.txt
DEPENDS
C:/in.txt
COMMAND
<makeOutputFileFromInputFile>
)
# Create a target that requires the output file
add_custom_target(customTarget DEPENDS out.txt
# Create a list of source files
set (SOURCE_FILES
utils.cpp
helpers.cpp
)
# Make all source files depend on the new target
set_source_files_properties(
${SOURCE_FILES}
OBJECT_DEPENDS
customTarget
)
# Assign source files to utils library, etc.
<...>
When CMake runs, two folders are created (in the folder bin/obj/system/libs/utils/CMakeFiles). They are called utils.dir and customTarget.dir. In utils.dir, we find our build.make file and see the rules to produce the compiled object as well as the custom target:
bin/obj/system/libs/utils/CMakeFiles/build.make:
# Miscellaneous assignments at the top
<...>
# Rule to make custom target
system/libs/utils/CMakeFiles/customTarget: out.txt
out.txt: C:/in.txt
<makeOutputFileFromInputFile>
# Rules to make the files
system/libs/utils/CMakeFiles/utils.dir/utils.o: customTarget
<compilerToBuildObject>
system/libs/utils/CMakeFiles/utils.dir/helpers.o: customTarget
<compilerToBuildObject>
# Other rules, assignments, etc.
<...>
The problem seems to be how the custom target is defined. For the object files, its simply the target name. The target itself appears to have a fully qualified path. This is giving me the following error:
gmake[2]: *** No rule to make target `customTarget, needed by ` system/libs/utils/CMakeFiles/utils.dir/helpers.o'. Stop.
If I manually edit the make file and change the target to the fully qualified name (and manually execute make) then the compilation succeeds. Is there something that I am doing wrong that is incorrectly assigning the target name? Is there an alternative to the "set_source_files_properties" command that would behave better?
Thank you in advance for your help!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20180301/16b4f18b/attachment.html>
More information about the CMake
mailing list