Hi,

I have a possible solution, but at the cost of a different CMake problem then.

INTERMEDIATE SOLUTION:
======================
If the generator creates one file "everything.cpp", which contains the source 
code of all separately created *.cpp files, I could use "everything.cpp" as a 
defined filename.

The example below seems to work at first glance. The generator is only called 
once. CMake seems to notice that "everything.cpp" is already built, when 
calling 'make' for the second time.

----------------------
ADD_CUSTOM_COMMAND(
  OUTPUT  everything.cpp
  COMMAND generator.rb --output everything.cpp
  VERBATIM
)

# Define a target shared object library
ADD_LIBRARY( xyz.generated SHARED everything.cpp )

# Additional libraries to be linked to the target
TARGET_LINK_LIBRARIES(
  xyz.generated
  lib1
  lib2
  ...
)
----------------------

NEW PROBLEM:
============
The generator runs in its own directory. "everything.cpp" is created and needed 
in a different directory.

The generator now is called EVERY TIME I run make, because
- I need two separate CMakeLists.txt files now,
- I have to make a custom target, otherwise CMake does not know 
"everything.cpp" and quits with an error.
- the custom target is ALWAYS considered out-of-date.

--- File1: generator/CMakeLists.txt ---
ADD_CUSTOM_COMMAND(
  OUTPUT  everything.cpp
  COMMAND generator.rb --output everything.cpp
  VERBATIM
)
ADD_CUSTOM_TARGET( generate_it DEPENDS everything.cpp )
---------------------------------

--- File2: libxyz.so/CMakeLists.txt ---
# Define a target shared object library
ADD_LIBRARY( xyz.generated SHARED everything.cpp )

# Let CMake know that everything.cpp is a generated file
SET_SOURCE_FILES_PROPERTIES( everything.cpp PROPERTIES GENERATED TRUE )

# Add dependencies between the library here and the custom target
# from the other CMakeLists.txt file
ADD_DEPENDENCIES( xyz.generated generate_it )

# Additional libraries to be linked to the target
TARGET_LINK_LIBRARIES(
  xyz.generated
  lib1
  lib2
  ...
)
---------------------------------

How can I have a custom target which is NOT built every time I call 'make'?
How can I use a target from another directory, which is only build if it's 
necessary?

Best Regards,
Joerg
_______________________________________________
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