On 2. Dec, 2009, at 20:22 , Tyler Roscoe wrote:

On Wed, Dec 02, 2009 at 07:58:43PM +0100, Jörg Förstner wrote:
I thought CMake would find the custom command and generate the file "gen.h"
Instead an error occurs, this is the output:

-- Configuring done
CMake Error in libfoo.so/CMakeLists.txt:
 Cannot find source file "gen.h".  Tried extensions .c .C .c++ .cc
 .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp .hxx .in .txx

Why doesn't CMake generate the file?

------------------
# Set variable containing all source files
SET( SRCS
 foo1.c
)

# Tell CMake that "gen.h" is a generated file
SET_SOURCE_FILE_PROPERTIES( gen.h PROPERTIES GENERATED 1 )

# Define custom command to generate "gen.h"
ADD_CUSTOM_COMMAND(
 OUTPUT  gen.h
 COMMAND echo "this command would generate 'gen.h' from data.txt"
 DEPENDS data.txt
)

# Define to build a target shared object library named "libfoo.so" from the source files "${SRCS}".
# The file "foo1.c" depends on the generated include file "gen.h"
ADD_LIBRARY( foo SHARED ${SRCS} gen.h )
------------------

Conceptually this looks correct.

Have you tried this with a custom command that actually creates gen.h?
The example you posted just echoes and doesn't generate anything.

tyler


Also, you might want to use full paths to gen.h (by e.g. prefixing $ {CMAKE_CURRENT_BINARY_DIR}, or wherever your program outputs gen.h).

Further, you don't need to set the source file property GENERATED. CMake does that for you in the ADD_CUSTOM_COMMAND(OUTPUT $ {CMAKE_CURRENT_BINARY_DIR}/gen.h ...).


Michael
_______________________________________________
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://www.cmake.org/mailman/listinfo/cmake

Reply via email to