The following issue has been SUBMITTED. ====================================================================== http://www.cmake.org/Bug/view.php?id=15614 ====================================================================== Reported By: FlorianM Assigned To: ====================================================================== Project: CMake Issue ID: 15614 Category: CCMake Reproducibility: always Severity: minor Priority: normal Status: new ====================================================================== Date Submitted: 2015-06-12 16:03 EDT Last Modified: 2015-06-12 16:03 EDT ====================================================================== Summary: add_custom_target/command: Can't give Target the same name as one of the Outputs Description: Let's say you want to transfer the following makefile into a CMake equivalent:
foo_in: foo.c $(CC) $< -o $@ foo_out: foo_in post_process $< > $@ And you don't want to add the second step as a post-build step. You still want to be able to build foo_in or foo_out separately. Steps to Reproduce: I'm using the "MSYS Makefiles" generator with the following test script: --- cmake_minimum_required(VERSION 2.8) project(MakeTargetTest C) file(WRITE foo.c "#include <windows.h>\nint main() {}") file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/post_process "echo Process something") add_executable(foo_in foo.c) set_target_properties(foo_in PROPERTIES SUFFIX "") add_custom_command( OUTPUT foo_out COMMAND post_process foo_in > foo_out DEPENDS foo_in ) add_custom_target(foo_out DEPENDS foo_out) --- $ make foo_out Built target foo_out --- [build.make] ... CMakeFiles/foo_out: foo_out: CMakeFiles/foo_out foo_out: CMakeFiles/foo_out.dir/build.make .PHONY : foo_out --- If I rename the custom target to something like "foo_out_test" it works correctly: $ make foo_out_test Scanning dependencies of target foo_in [ 50%] Building C object CMakeFiles/foo_in.dir/foo.c.obj Linking C executable foo_in. [ 50%] Built target foo_in [100%] Generating foo_out [100%] Built target foo_out_test --- [build.make] ... CMakeFiles/foo_out_test: foo_out foo_out: foo_in. $(CMAKE_COMMAND) -E cmake_progress_report CMakeFiles $(CMAKE_PROGRESS_1) @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --blue --bold "Generating foo_out" post_process foo_in > foo_out foo_out_test: CMakeFiles/foo_out_test foo_out_test: foo_out foo_out_test: CMakeFiles/foo_out_test.dir/build.make .PHONY : foo_out_test Additional Information: I understand that the Makefile generator could get confused by dependency that could be a file and a target dependency, but why should this be possible for executables and not for custom commands? And why could I not at least get a warning or error by CMake during generation (since the rule generated is just empty, see "Steps to Reproduce")? I can see 3 possible solutions: 1. The generator detects that there is a file and a target with the same name and does add a suffix or prefix to its internal build rules for that file. 2. The add_custom_target() command is extended to allow to define its "final" output which is then handled the same way a and add_executable() command output file. 3. Add an GENERIC (linker) language. So you could use files with any extensions with add_executable() that are directly given to a definable "linker". ====================================================================== Issue History Date Modified Username Field Change ====================================================================== 2015-06-12 16:03 FlorianM New Issue ====================================================================== -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake-developers