Re: [CMake] write file if different?

2013-06-03 Thread Matthew Woehlke

On 2013-05-28 16:07, Matthew Woehlke wrote:

Is there a built-in way to write a string to a file (a la FILE(WRITE))
that will only write the file if the content would be different? (Or
does FILE(WRITE) already work this way despite no obvious hint in the
documentation that it does?)

Right now I am writing to a temporary file and running cmake -E
copy_if_different, then removing the temporary file, but this seems
inelegant and I am wondering if there is a better solution.


Not strictly built-in, but it looks like the best way is:

  set(CMAKE_CONFIGURABLE_FILE_CONTENT ${CONTENT})
  configure_file(
${CMAKE_ROOT}/Modules/CMakeConfigurableFile.in
${PATH} @ONLY
  )

--
Matthew

--

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] write file if different?

2013-05-30 Thread j s
You are entitled to your opinion, but there are several system
utilities that are available by default on many systems, including
rsync.  rsync has a well known interface, and is available by default
on Linux and Mac OS X.  The way CMake does things is often kludgy and
just feels wrong.  I often write scripts in more effective languages
and then run from within CMake on Windows, Linux, and Mac OS X.  Perl
and Python are often a much better way to go than trying to do
everything in CMake.


On Wed, May 29, 2013 at 11:14 PM, them...@gmail.com them...@gmail.com wrote:
 - Reply message -
 From: j s j.s4...@gmail.com
 To: Michael Wild them...@gmail.com
 Cc: CMake mailing list cmake@cmake.org
 Subject: [CMake] write file if different?
 Date: Wed, May 29, 2013 20:44

 On Wed, May 29, 2013 at 2:32 AM, Michael Wild them...@gmail.com wrote:

 On 28.05.2013 22:07, Matthew Woehlke wrote:
  Is there a built-in way to write a string to a file (a la FILE(WRITE))
  that will only write the file if the content would be different? (Or
  does FILE(WRITE) already work this way despite no obvious hint in the
  documentation that it does?)
 
  Right now I am writing to a temporary file and running cmake -E
  copy_if_different, then removing the temporary file, but this seems
  inelegant and I am wondering if there is a better solution.
 
 You can always use the rsync command, which is available for all
 systems, including Windows.

 That's probably the worst possible solution... CMake has everything that iy
 required to accomplish this built-in, so adding a unnecessary dependency
 that is only needed by the build system is a really bad idea...
--

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] write file if different?

2013-05-30 Thread J Decker
Rsync would be no different than writing the file and using
copy_if_different; it would still be two steps, but require additional
things to be installed on linux and windows systems.  Same with
python/perl/bash as appropriate.  If you're using those other things
you should just use configure so windows people don't attempt to build
it with JUST cmake and their favorite compiler installed.

On Thu, May 30, 2013 at 9:11 AM, j s j.s4...@gmail.com wrote:
 You are entitled to your opinion, but there are several system
 utilities that are available by default on many systems, including
 rsync.  rsync has a well known interface, and is available by default
 on Linux and Mac OS X.  The way CMake does things is often kludgy and
 just feels wrong.  I often write scripts in more effective languages
 and then run from within CMake on Windows, Linux, and Mac OS X.  Perl
 and Python are often a much better way to go than trying to do
 everything in CMake.


 On Wed, May 29, 2013 at 11:14 PM, them...@gmail.com them...@gmail.com wrote:
 - Reply message -
 From: j s j.s4...@gmail.com
 To: Michael Wild them...@gmail.com
 Cc: CMake mailing list cmake@cmake.org
 Subject: [CMake] write file if different?
 Date: Wed, May 29, 2013 20:44

 On Wed, May 29, 2013 at 2:32 AM, Michael Wild them...@gmail.com wrote:

 On 28.05.2013 22:07, Matthew Woehlke wrote:
  Is there a built-in way to write a string to a file (a la FILE(WRITE))
  that will only write the file if the content would be different? (Or
  does FILE(WRITE) already work this way despite no obvious hint in the
  documentation that it does?)
 
  Right now I am writing to a temporary file and running cmake -E
  copy_if_different, then removing the temporary file, but this seems
  inelegant and I am wondering if there is a better solution.
 
 You can always use the rsync command, which is available for all
 systems, including Windows.

 That's probably the worst possible solution... CMake has everything that iy
 required to accomplish this built-in, so adding a unnecessary dependency
 that is only needed by the build system is a really bad idea...
 --

 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] write file if different?

2013-05-30 Thread Matthew Woehlke

On 2013-05-30 12:11, j s wrote:

On Wed, May 29, 2013 at 11:14 PM, them...@gmail.com wrote:

j s wrote:

On 28.05.2013 22:07, Matthew Woehlke wrote:

Is there a built-in way to write a string to a file (a la FILE(WRITE))
that will only write the file if the content would be different? (Or
does FILE(WRITE) already work this way despite no obvious hint in the
documentation that it does?)


You can always use the rsync command, which is available for all
systems, including Windows.


That's probably the worst possible solution... CMake has everything that iy
required to accomplish this built-in, so adding a unnecessary dependency
that is only needed by the build system is a really bad idea...


You are entitled to your opinion, but there are several system
utilities that are available by default on many systems, including
rsync.


Really? I have yet to encounter a Windows system that has rsync by 
default. (For that matter, even on Linux it is not required, and I 
wouldn't put a lot of faith in finding it on a 'stock' non-Linux/BSD 
UNIX platform.)


Besides, using rsync for a single file where cmake -E copy_if_different 
(or even configure_file as elsewhere mentioned) is clearly overkill. Not 
to mention that rsync is not guaranteed to be present even on UNIX 
systems, much less Windows, whereas CMake is already being used.



The way CMake does things is often kludgy and just feels wrong.  I
often write scripts in more effective languages and then run from
within CMake on Windows, Linux, and Mac OS X.  Perl and Python are
often a much better way to go than trying to do everything in CMake.


Sure, and where a) it makes sense and b) I *already require the relevant 
tools for other reasons*, I do also. But I try to avoid it, because 
these dependencies are usually NOT present on Windows, especially for 
end users that want to build from a tarball. (Which is why, when I wrote 
test discovery for gtest, I did it in pure CMake. It may not be the 
easiest/cleanest, but I strongly prefer to avoid large external 
dependencies without much stronger motivation for needing them.)


--
Matthew

--

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] write file if different?

2013-05-30 Thread j s
On Thu, May 30, 2013 at 12:36 PM, Matthew Woehlke
matthew.woeh...@kitware.com wrote:
 On 2013-05-30 12:11, j s wrote:

 On Wed, May 29, 2013 at 11:14 PM, them...@gmail.com wrote:

 j s wrote:

 On 28.05.2013 22:07, Matthew Woehlke wrote:

 Is there a built-in way to write a string to a file (a la FILE(WRITE))
 that will only write the file if the content would be different? (Or
 does FILE(WRITE) already work this way despite no obvious hint in the
 documentation that it does?)


 You can always use the rsync command, which is available for all
 systems, including Windows.


 That's probably the worst possible solution... CMake has everything that
 iy
 required to accomplish this built-in, so adding a unnecessary dependency
 that is only needed by the build system is a really bad idea...


 You are entitled to your opinion, but there are several system
 utilities that are available by default on many systems, including
 rsync.


 Really? I have yet to encounter a Windows system that has rsync by
 default. (For that matter, even on Linux it is not required, and I wouldn't
 put a lot of faith in finding it on a 'stock' non-Linux/BSD UNIX platform.)

It is available by default on both Mac OS X and Ubuntu Linux, and is
readily available as a package on many others.  In fact, many package
management software require rsync to even run.  It is readily
available on Windows by installing Cygwin.


 Besides, using rsync for a single file where cmake -E copy_if_different (or
 even configure_file as elsewhere mentioned) is clearly overkill. Not to
 mention that rsync is not guaranteed to be present even on UNIX systems,

The original poster's test case may not be the best example for using
an external utility.  In fact, they'd be better off using something
like a custom target having the appropriate dependencies.  Barring
that they should use a script written in a real scripting language
that unambigously performs the steps needed.



 The way CMake does things is often kludgy and just feels wrong.  I
 often write scripts in more effective languages and then run from
 within CMake on Windows, Linux, and Mac OS X.  Perl and Python are
 often a much better way to go than trying to do everything in CMake.


 Sure, and where a) it makes sense and b) I *already require the relevant
 tools for other reasons*, I do also. But I try to avoid it, because these
 dependencies are usually NOT present on Windows, especially for end users
 that want to build from a tarball. (Which is why, when I wrote test
 discovery for gtest, I did it in pure CMake. It may not be the
 easiest/cleanest, but I strongly prefer to avoid large external dependencies
 without much stronger motivation for needing them.)

Standard system utilities are the cleanest, and easiest.  These tools
are readily available on Windows via Cygwin.  Most every program I
write requires already Boost, Bison, Flex and a Python interpreter, so
a Unix like environment is going to be required anyways.  I use cmake
because it is an accurate Makefile and Visual Studio generator.  It's
main fault is it's domain specific language.

 --
 Matthew


 --

 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] write file if different?

2013-05-30 Thread J Decker
On Tue, May 28, 2013 at 1:07 PM, Matthew Woehlke
matthew.woeh...@kitware.com wrote:
 Is there a built-in way to write a string to a file (a la FILE(WRITE)) that
 will only write the file if the content would be different? (Or does
 FILE(WRITE) already work this way despite no obvious hint in the
 documentation that it does?)

 Right now I am writing to a temporary file and running cmake -E
 copy_if_different, then removing the temporary file, but this seems
 inelegant and I am wondering if there is a better solution.


I would add a minor note; this seems to be a good way, but you don't
really need to delete the temp file, if you build it in the
${CMAKE_BINARY_DIR}, so it's not laying around in source trees.


It would be nice if such a simple thing didn't require launching a
seperate instance of cmake to do; since it's already in cmake, would
think there would be a way to just 'EXEC( ... )' instead of 'cmake -E
(...)'

 --
 Matthew

 --

 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] write file if different?

2013-05-30 Thread Matthew Woehlke

On 2013-05-30 17:24, J Decker wrote:

On Tue, May 28, 2013 at 1:07 PM, Matthew Woehlke
matthew.woeh...@kitware.com wrote:

Is there a built-in way to write a string to a file (a la FILE(WRITE)) that
will only write the file if the content would be different? (Or does
FILE(WRITE) already work this way despite no obvious hint in the
documentation that it does?)

Right now I am writing to a temporary file and running cmake -E
copy_if_different, then removing the temporary file, but this seems
inelegant and I am wondering if there is a better solution.


I would add a minor note; this seems to be a good way, but you don't
really need to delete the temp file, if you build it in the
${CMAKE_BINARY_DIR}, so it's not laying around in source trees.


Sure, but it offends my sense of tidiness to leave it ;-).


It would be nice if such a simple thing didn't require launching a
seperate instance of cmake to do; since it's already in cmake, would
think there would be a way to just 'EXEC( ... )' instead of 'cmake -E
(...)'


As pointed out, configure_file would probably also do the job. What I 
was hoping for, however, was a solution where I don't have to much about 
with the temporary file myself.


I had two main reasons for posting: to ask if there was an elegant way 
to do this that I didn't know about (I haven't heard one), and at some 
point ('now', apparently) to inquire if this would be a useful addition 
to CMake. A file(WRITE_IF_DIFFERENT) perhaps?


--
Matthew

--

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] write file if different?

2013-05-30 Thread Matthew Woehlke

On 2013-05-29 03:32, Michael Wild wrote:

On 28.05.2013 22:07, Matthew Woehlke wrote:

Is there a built-in way to write a string to a file (a la FILE(WRITE))
that will only write the file if the content would be different? (Or
does FILE(WRITE) already work this way despite no obvious hint in the
documentation that it does?)

Right now I am writing to a temporary file and running cmake -E
copy_if_different, then removing the temporary file, but this seems
inelegant and I am wondering if there is a better solution.


AFAIK the file is written unconditionally, but you can then use
configure_file(... COPYONLY) instead of a round-about execute_process()
that calls cmake -E copy_if_different.


Actually... no. Well, I could (it would technically work), but because I 
always write the file, it causes the build rules to always be out of 
date (i.e. CMake is re-run every time), which is decidedly sub-optimal :-).


(Didn't realize that until I finally decided to try it, just now. 
Although I wonder now if I had actually tried configure_file originally 
and switched to execute_process for exactly this reason...)


So... stronger argument for maybe adding this as an enhancement to CMake.

--
Matthew

--

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] write file if different?

2013-05-29 Thread j s
On Wed, May 29, 2013 at 2:32 AM, Michael Wild them...@gmail.com wrote:

 On 28.05.2013 22:07, Matthew Woehlke wrote:
  Is there a built-in way to write a string to a file (a la FILE(WRITE))
  that will only write the file if the content would be different? (Or
  does FILE(WRITE) already work this way despite no obvious hint in the
  documentation that it does?)
 
  Right now I am writing to a temporary file and running cmake -E
  copy_if_different, then removing the temporary file, but this seems
  inelegant and I am wondering if there is a better solution.
 
You can always use the rsync command, which is available for all
systems, including Windows.



 AFAIK the file is written unconditionally, but you can then use
 configure_file(... COPYONLY) instead of a round-about execute_process()
 that calls cmake -E copy_if_different.

 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
--

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] write file if different?

2013-05-29 Thread them...@gmail.com


- Reply message -
From: j s j.s4...@gmail.com
To: Michael Wild them...@gmail.com
Cc: CMake mailing list cmake@cmake.org
Subject: [CMake] write file if different?
Date: Wed, May 29, 2013 20:44

On Wed, May 29, 2013 at 2:32 AM, Michael Wild them...@gmail.com wrote:

 On 28.05.2013 22:07, Matthew Woehlke wrote:
  Is there a built-in way to write a string to a file (a la FILE(WRITE))
  that will only write the file if the content would be different? (Or
  does FILE(WRITE) already work this way despite no obvious hint in the
  documentation that it does?)
 
  Right now I am writing to a temporary file and running cmake -E
  copy_if_different, then removing the temporary file, but this seems
  inelegant and I am wondering if there is a better solution.
 
You can always use the rsync command, which is available for all
systems, including Windows.
That's probably the worst possible solution... CMake has everything that iy 
required to accomplish this built-in, so adding a unnecessary dependency that 
is only needed by the build system is a really bad idea...--

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

[CMake] write file if different?

2013-05-28 Thread Matthew Woehlke
Is there a built-in way to write a string to a file (a la FILE(WRITE)) 
that will only write the file if the content would be different? (Or 
does FILE(WRITE) already work this way despite no obvious hint in the 
documentation that it does?)


Right now I am writing to a temporary file and running cmake -E 
copy_if_different, then removing the temporary file, but this seems 
inelegant and I am wondering if there is a better solution.


--
Matthew

--

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