The following issue has been SUBMITTED. 
====================================================================== 
http://public.kitware.com/Bug/view.php?id=13846 
====================================================================== 
Reported By:                szx
Assigned To:                
====================================================================== 
Project:                    CMake
Issue ID:                   13846
Category:                   (No Category)
Reproducibility:            have not tried
Severity:                   minor
Priority:                   normal
Status:                     new
====================================================================== 
Date Submitted:             2013-01-11 20:23 EST
Last Modified:              2013-01-11 20:23 EST
====================================================================== 
Summary:                    Custom commands not working  when comamnd output
used in another directory
Description: 
At least for the Unix Makefile generator (haven't tried others) custom commands
are not called when their output file is specified as a source file for a target
defined in the parent directory. As soon as I move both add_custom_command() and
the target to the same file, everything works fine.

Steps to Reproduce: 
============ Case 1 =============

1. Create CMakeLists.txt with the following contents

cmake_minimum_required(VERSION 2.8.9)
project(test)

add_subdirectory("src")
set_source_files_properties("src/test.c" PROPERTIES GENERATED TRUE)
add_executable(test "src/test.c")

2. Create a directory called "src" and another CMakeLists.txt in it:

add_custom_command(
        OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/test.c"
        COMMAND echo "int main\\(\\) \\{\\}" > 
"${CMAKE_CURRENT_SOURCE_DIR}/test.c"
        WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
)

3. You will get the following error from make:

test1-build$ make
make[2]: *** No rule to make target `src/test.c', needed by
`CMakeFiles/test.dir/src/test.c.o'.  Stop.
make[1]: *** [CMakeFiles/test.dir/all] Error 2
make: *** [all] Error 2

============ Case 2 =============

1. Create a CMakeLists.txt with the following contents:

cmake_minimum_required(VERSION 2.8.9)
project(test)

file(MAKE_DIRECTORY "src")
add_custom_command(
        OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/src/test.c"
        COMMAND echo "int main\\(\\) \\{\\}" > 
"${CMAKE_CURRENT_SOURCE_DIR}/src/test.c"
        WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
)
set_source_files_properties("src/test.c" PROPERTIES GENERATED TRUE)
add_executable(test "src/test.c")

2. make will complete without errors:

test2-build$ make
[ 50%] Generating /home/asd/Desktop/fuck-cmake/test2/src/test.c
Scanning dependencies of target test
[100%] Building C object CMakeFiles/test.dir/src/test.c.o
Linking C executable test
[100%] Built target test

====================================================================== 

Issue History 
Date Modified    Username       Field                    Change               
====================================================================== 
2013-01-11 20:23 szx            New Issue                                    
2013-01-11 20:23 szx            File Added: test.zip                         
======================================================================

--

Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/cgi-bin/mailman/listinfo/cmake-developers

Reply via email to