On 12/08/2010 04:50 PM, Michael Wild wrote:
On 12/08/2010 04:28 PM, Vivien Delmon wrote:
On 12/08/2010 04:13 PM, Michael Wild wrote:
On 12/08/2010 03:54 PM, Micha Renner wrote:
Am Mittwoch, den 08.12.2010, 14:55 +0100 schrieb Vivien Delmon:
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
ADD_CUSTOM_COMMAND(OUTPUT toto.h toto.c
      COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/create_totoc_totoh.sh
)
SET_SOURCE_FILES_PROPERTIES(toto.h toto.c PROPERTIES GENERATETED TRUE)

See:
http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:set_source_files_properties

and:
http://www.cmake.org/cmake/help/cmake-2-8-docs.html#prop_sf:GENERATED


INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
ADD_LIBRARY(titi toto.c)
ADD_LIBRARY(tata tata.c)

Greetings
Micha



the GENERATED property is set automatically by ADD_CUSTOM_COMMAND. But I
suspect the problem is that you used a relative path in your OUTPUT
option. *Always* specify full paths in the OUTPUT and DEPENDS options.
Also, make the custom command DEPENDS on the create_totoc_totoh.sh
script and it's input (perhaps it reads some configuration file or you
pass it another file as an argument, etc.).

Both solutions does not solve the problem.

CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/toto.h
${CMAKE_CURRENT_SOURCE_DIR}/toto.c
     COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/create_totoc_totoh.sh
)
SET_SOURCE_FILES_PROPERTIES(toto.h toto.c PROPERTIES GENERATETED TRUE)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
ADD_LIBRARY(titi toto.c)
ADD_LIBRARY(tata tata.c)

The problem is that tata.c include toto.h. cmake does not know it
because C file dependencies are constructed later by make. The result is
that CMakeFiles/tata.dir/build.make does not include the rule needed to
construct toto.h. I try to find a way to add this rule.
A workaround consists in putting toto.h in libtata dependencies but it's
not a dependency of libtata but a dependency of tata.c.

The error is :
[ 33%] Building C object CMakeFiles/tata.dir/tata.c.o
/home/vivien/tmp/cmake_deps/tata.c:1:18: fatal error: toto.h: No such
file or directory
compilation terminated.


Ah, yes. I missed the "tata"<->"toto" difference ;-) In this case you
can use

set_source_files_properties(tata.c PROPERTIES
   OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/toto.h)

Which is, of course, less than ideal because you have to know which
sources include toto.h. *BUT*: Actually, since tata.h is including
toto.h, it is likely that the tata library actually needs to be linked
against the titi library, so adding

TARGET_LINK_LIBRARIES(tata titi)

Thanks it's certainly what I need. Still have to find this titi in the bigger project ...

also solves the problem, but in a much cleaner way.

Another thin: *never* generate output in the source tree. Actually, I
start to think that the ADD_CUSTOM_COMMAND should error out if any of
the OUTPUT files is located in the source tree for out-of-source
builds... At least, it should print a big fat "developer-warning".

Yes off course, it's not the case in fact. just a fast copy/paste for the example.

Michael

Thanks for your fast answer.

--
Vivien Delmon
PhD at CREATIS, Lyon
http://www.creatis.insa-lyon.fr/rio
_______________________________________________
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