[CMake] add_dependency on a custom target

2010-09-15 Thread Nick Davidson
Dear List,

I'm using a file glob to extract a list of xml files to pass to a custom
target to generate
a pot file with getttext, most of the heavy lifting is handled by a
Macro.

include(FindMsgfmt)
macro (MakePot BIN_NAME CPP_SOURCES XML_SOURCES)
 set(CPP_SRCS ${CPP_SOURCES})
 set(XML_SRCS ${XML_SOURCES})
 set(POT_FILE ${BIN_NAME}.pot)
 if (XGETTEXT_FOUND)
 message(STATUS Adding Target Potfile: ${POT_FILE})
 if (XML_SRCS)
 add_custom_target(${POT_FILE} ALL
 COMMAND ${XGETTEXT_EXECUTABLE} --language=C++ --force-po
-kN_ -kNN_:1,2 -o
 ${POT_FILE} ${CPP_SRCS}
 COMMAND ${XGETTEXT_EXECUTABLE} --language=Glade --force-po
-j -o
 ${POT_FILE} ${XML_SRCS} )
 else (XML_SRCS) add_custom_target(${POT_FILE} ALL
 COMMAND ${XGETTEXT_EXECUTABLE} --language=C++ --force-po
-kN_ -kNN_:1,2 -o
 ${POT_FILE} ${CPP_SRCS})
 endif(XML_SRCS)
 add_dependencies(${POT_FILE} ${XML_SOURCES} ${CPP_SRCS})
 else (XGETTEXT_FOUND)
 message(STATUS Cannot find xgettext)
 endif(XGETTEXT_FOUND)
endmacro (MakePot POT_NAME) 

The only problem is, if the list of xml files changes (e.g. a deletion)
the cmake
cache doesn't get regenerated and thus the xml files are not reglobbed
and so the
custom command fails.

Any suggestions?

Thanks,

Nick Davidson

__
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
__
___
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


Re: [CMake] add_dependency on a custom target

2010-09-15 Thread Andreas Pakulat
On 15.09.10 12:34:43, Nick Davidson wrote:
 Dear List,
 
 I'm using a file glob to extract a list of xml files to pass to a custom
 target to generate
 a pot file with getttext, most of the heavy lifting is handled by a
 Macro.
 
 include(FindMsgfmt)
 macro (MakePot BIN_NAME CPP_SOURCES XML_SOURCES)
  set(CPP_SRCS ${CPP_SOURCES})
  set(XML_SRCS ${XML_SOURCES})
  set(POT_FILE ${BIN_NAME}.pot)
  if (XGETTEXT_FOUND)
  message(STATUS Adding Target Potfile: ${POT_FILE})
  if (XML_SRCS)
  add_custom_target(${POT_FILE} ALL
  COMMAND ${XGETTEXT_EXECUTABLE} --language=C++ --force-po
 -kN_ -kNN_:1,2 -o
  ${POT_FILE} ${CPP_SRCS}
  COMMAND ${XGETTEXT_EXECUTABLE} --language=Glade --force-po
 -j -o
  ${POT_FILE} ${XML_SRCS} )
  else (XML_SRCS) add_custom_target(${POT_FILE} ALL
  COMMAND ${XGETTEXT_EXECUTABLE} --language=C++ --force-po
 -kN_ -kNN_:1,2 -o
  ${POT_FILE} ${CPP_SRCS})
  endif(XML_SRCS)
  add_dependencies(${POT_FILE} ${XML_SOURCES} ${CPP_SRCS})
  else (XGETTEXT_FOUND)
  message(STATUS Cannot find xgettext)
  endif(XGETTEXT_FOUND)
 endmacro (MakePot POT_NAME) 
 
 The only problem is, if the list of xml files changes (e.g. a deletion)
 the cmake
 cache doesn't get regenerated and thus the xml files are not reglobbed
 and so the
 custom command fails.
 
 Any suggestions?

Don't use a glob (list the files individually) or remember to touch the
cmakelists.txt file after adding new files. I don't think there's a way to
have cmake re-run when calling just make within cmakelists.txt.

Andreas

-- 
You will be imprisoned for contributing your time and skill to a bank robbery.
___
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


Re: [CMake] add_dependency on a custom target

2010-09-15 Thread Nick Davidson
Whoops, forgot to reply on list, sorry!

 From: cmake-boun...@cmake.org
 [mailto:cmake-boun...@cmake.org] On Behalf Of Andreas Pakulat
 Sent: 15 September 2010 13:03
 To: cmake@cmake.org
 Subject: Re: [CMake] add_dependency on a custom target
 
 On 15.09.10 12:34:43, Nick Davidson wrote:
  Dear List,
  
  I'm using a file glob to extract a list of xml files to pass to a 
  custom target to generate a pot file with getttext, most of
 the heavy
  lifting is handled by a Macro.
  
  include(FindMsgfmt)
  macro (MakePot BIN_NAME CPP_SOURCES XML_SOURCES)
   set(CPP_SRCS ${CPP_SOURCES})
   set(XML_SRCS ${XML_SOURCES})
   set(POT_FILE ${BIN_NAME}.pot)
   if (XGETTEXT_FOUND)
   message(STATUS Adding Target Potfile: ${POT_FILE})
   if (XML_SRCS)
   add_custom_target(${POT_FILE} ALL
   COMMAND ${XGETTEXT_EXECUTABLE} --language=C++
 --force-po
  -kN_ -kNN_:1,2 -o  ${POT_FILE} ${CPP_SRCS}
   COMMAND ${XGETTEXT_EXECUTABLE} --language=Glade 
  --force-po -j -o  ${POT_FILE} ${XML_SRCS} )
   else (XML_SRCS) 
 add_custom_target(${POT_FILE} ALL
   COMMAND ${XGETTEXT_EXECUTABLE} --language=C++
 --force-po
  -kN_ -kNN_:1,2 -o  ${POT_FILE} ${CPP_SRCS})
   endif(XML_SRCS)
   add_dependencies(${POT_FILE} ${XML_SOURCES} ${CPP_SRCS})
   else (XGETTEXT_FOUND)
   message(STATUS Cannot find xgettext)
   endif(XGETTEXT_FOUND)
  endmacro (MakePot POT_NAME)
  
  The only problem is, if the list of xml files changes (e.g. a
  deletion) the cmake cache doesn't get regenerated and thus the xml 
  files are not reglobbed and so the custom command fails.
  
  Any suggestions?
 
 Don't use a glob (list the files individually) or remember to touch 
 the cmakelists.txt file after adding new files. I don't think there's 
 a way to have cmake re-run when calling just make within 
 cmakelists.txt.

Ok, but why doesn't adding the files as dependencies work? 
The glob is stored in the cache - fine, there isn't a way for Cmake to
automatically figure out what files it should check to see if anything
has changed. Having added those files as dependencies of the target that
uses the glob manually then surely it's just a list of files?


Is there a fundamental difference between a list variable made from
a globbed set of files and a list made from a manually specified set?

 
 Andreas
 
 --

Nickd

__
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
__
___
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


Re: [CMake] add_dependency on a custom target

2010-09-15 Thread David Cole
On Wed, Sep 15, 2010 at 11:15 AM, Nick Davidson n...@toby-churchill.comwrote:

 Whoops, forgot to reply on list, sorry!

  From: cmake-boun...@cmake.org
  [mailto:cmake-boun...@cmake.org] On Behalf Of Andreas Pakulat
  Sent: 15 September 2010 13:03
  To: cmake@cmake.org
  Subject: Re: [CMake] add_dependency on a custom target
 
  On 15.09.10 12:34:43, Nick Davidson wrote:
   Dear List,
  
   I'm using a file glob to extract a list of xml files to pass to a
   custom target to generate a pot file with getttext, most of
  the heavy
   lifting is handled by a Macro.
  
   include(FindMsgfmt)
   macro (MakePot BIN_NAME CPP_SOURCES XML_SOURCES)
set(CPP_SRCS ${CPP_SOURCES})
set(XML_SRCS ${XML_SOURCES})
set(POT_FILE ${BIN_NAME}.pot)
if (XGETTEXT_FOUND)
message(STATUS Adding Target Potfile: ${POT_FILE})
if (XML_SRCS)
add_custom_target(${POT_FILE} ALL
COMMAND ${XGETTEXT_EXECUTABLE} --language=C++
  --force-po
   -kN_ -kNN_:1,2 -o  ${POT_FILE} ${CPP_SRCS}
COMMAND ${XGETTEXT_EXECUTABLE} --language=Glade
   --force-po -j -o  ${POT_FILE} ${XML_SRCS} )
else (XML_SRCS)
  add_custom_target(${POT_FILE} ALL
COMMAND ${XGETTEXT_EXECUTABLE} --language=C++
  --force-po
   -kN_ -kNN_:1,2 -o  ${POT_FILE} ${CPP_SRCS})
endif(XML_SRCS)
add_dependencies(${POT_FILE} ${XML_SOURCES} ${CPP_SRCS})
else (XGETTEXT_FOUND)
message(STATUS Cannot find xgettext)
endif(XGETTEXT_FOUND)
   endmacro (MakePot POT_NAME)
  
   The only problem is, if the list of xml files changes (e.g. a
   deletion) the cmake cache doesn't get regenerated and thus the xml
   files are not reglobbed and so the custom command fails.
  
   Any suggestions?
 
  Don't use a glob (list the files individually) or remember to touch
  the cmakelists.txt file after adding new files. I don't think there's
  a way to have cmake re-run when calling just make within
  cmakelists.txt.

 Ok, but why doesn't adding the files as dependencies work?
 The glob is stored in the cache - fine, there isn't a way for Cmake to
 automatically figure out what files it should check to see if anything
 has changed. Having added those files as dependencies of the target that
 uses the glob manually then surely it's just a list of files?


 Is there a fundamental difference between a list variable made from
 a globbed set of files and a list made from a manually specified set?


There's no indication that a set of files retrieved by glob has changed when
a file is added or removed from a directory. So if the set changes, neither
make nor cmake know that anything is out of date... and nothing re-runs.

The mod time of the file containing the list changes when the manually
specified list changes. Therefore CMake can be re-run by make.




 
  Andreas
 
  --

 Nickd

 __
 This email has been scanned by the MessageLabs Email Security System.
 For more information please visit http://www.messagelabs.com/email
 __
 ___
 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

___
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

Re: [CMake] add_dependency on a custom target

2010-09-15 Thread Michael Hertling
On 09/15/2010 05:15 PM, Nick Davidson wrote:
 Whoops, forgot to reply on list, sorry!
 
 From: cmake-boun...@cmake.org
 [mailto:cmake-boun...@cmake.org] On Behalf Of Andreas Pakulat
 Sent: 15 September 2010 13:03
 To: cmake@cmake.org
 Subject: Re: [CMake] add_dependency on a custom target

 On 15.09.10 12:34:43, Nick Davidson wrote:
 Dear List,

 I'm using a file glob to extract a list of xml files to pass to a 
 custom target to generate a pot file with getttext, most of
 the heavy
 lifting is handled by a Macro.

 include(FindMsgfmt)
 macro (MakePot BIN_NAME CPP_SOURCES XML_SOURCES)
  set(CPP_SRCS ${CPP_SOURCES})
  set(XML_SRCS ${XML_SOURCES})
  set(POT_FILE ${BIN_NAME}.pot)
  if (XGETTEXT_FOUND)
  message(STATUS Adding Target Potfile: ${POT_FILE})
  if (XML_SRCS)
  add_custom_target(${POT_FILE} ALL
  COMMAND ${XGETTEXT_EXECUTABLE} --language=C++
 --force-po
 -kN_ -kNN_:1,2 -o  ${POT_FILE} ${CPP_SRCS}
  COMMAND ${XGETTEXT_EXECUTABLE} --language=Glade 
 --force-po -j -o  ${POT_FILE} ${XML_SRCS} )
  else (XML_SRCS) 
 add_custom_target(${POT_FILE} ALL
  COMMAND ${XGETTEXT_EXECUTABLE} --language=C++
 --force-po
 -kN_ -kNN_:1,2 -o  ${POT_FILE} ${CPP_SRCS})
  endif(XML_SRCS)
  add_dependencies(${POT_FILE} ${XML_SOURCES} ${CPP_SRCS})
  else (XGETTEXT_FOUND)
  message(STATUS Cannot find xgettext)
  endif(XGETTEXT_FOUND)
 endmacro (MakePot POT_NAME)

 The only problem is, if the list of xml files changes (e.g. a
 deletion) the cmake cache doesn't get regenerated and thus the xml 
 files are not reglobbed and so the custom command fails.

 Any suggestions?

 Don't use a glob (list the files individually) or remember to touch 
 the cmakelists.txt file after adding new files. I don't think there's 
 a way to have cmake re-run when calling just make within 
 cmakelists.txt.
 
 Ok, but why doesn't adding the files as dependencies work? 
 The glob is stored in the cache - fine, there isn't a way for Cmake to
 automatically figure out what files it should check to see if anything
 has changed. Having added those files as dependencies of the target that
 uses the glob manually then surely it's just a list of files?
 
 
 Is there a fundamental difference between a list variable made from
 a globbed set of files and a list made from a manually specified set?

Don't use ADD_DEPENDENCIES() to establish a dependency of a target on
files; it's for target interdependencies only. Furthermore, you don't
need a dependency of a custom target on your XML files unless they're
generated by a custom command; custom targets are always out of date
and, thus, rebuilt when they are checked. So, when (re)building, the
target associated with the POT_FILE is (re)built anyway, but at the
moment, it works on the files collected once at configuration time.
However, you can delay the files' collection till build time:

CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR)
PROJECT(GLOB NONE)
FILE(WRITE ${CMAKE_BINARY_DIR}/glob.cmake 
FILE(GLOB_RECURSE g *.cmake)
EXECUTE_PROCESS(COMMAND echo \xgettext ...\ \${g})
)
ADD_CUSTOM_TARGET(glob ALL
  ${CMAKE_COMMAND} -P ${CMAKE_BINARY_DIR}/glob.cmake
)

The glob.cmake script is invoked by a custom target at build time,
collects the files and executes a command on them, so there is no
need to reconfigure after the set of collected files has changed.
BTW, wouldn't it be more appropriate to use a custom command for
the pot files' generation?

Regards,

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