Re: [CMake] Adding a custom line to CMake's makefiles?

2011-09-09 Thread Clifford Yapp
I can finally give a good concrete case where I might need to do this (or
need some other very clever solution).

I have created a distcheck command for BRL-CAD that has a lot of
responsibilities, including doing a complete configure and build of BRL-CAD
from a source archive expanded from a CPack tarball.  The distcheck rule
uses cmake to fire off the build (this is to try and be future proof against
using other tools than Make to do a distcheck) but I need to pass the
parallel build setting -j from Make down to the ${CMAKE_COMMAND} build
launched by the distcheck rule, and there doesn't seem to be any way to do
it.

This is the subset of the distcheck rule (somewhat edited for clarity):

   ADD_CUSTOM_TARGET(distcheck
  COMMAND ${CMAKE_COMMAND} -E echo Stage 1:  Create source tgz, tbz2
and zip archives from toplevel archive.
  COMMAND cpack --config
${CMAKE_CURRENT_BINARY_DIR}/CPackSourceConfig.cmake
  COMMAND ${CMAKE_COMMAND} -E echo Stage 2:  Expand tgz archive and
prepare to build from archive sources.
  COMMAND ${CMAKE_COMMAND} -E tar xvzf
${CPACK_SOURCE_PACKAGE_FILE_NAME}.tar.gz
  COMMAND ${CMAKE_COMMAND} -E make_directory
_${CPACK_SOURCE_PACKAGE_FILE_NAME}-build
  COMMAND ${CMAKE_COMMAND} -E make_directory
_${CPACK_SOURCE_PACKAGE_FILE_NAME}-install
  COMMAND ${CMAKE_COMMAND} -E chdir
_${CPACK_SOURCE_PACKAGE_FILE_NAME}-build ${CMAKE_COMMAND}
../${CPACK_SOURCE_PACKAGE_FILE_NAME}
-DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/_${CPACK_SOURCE_PACKAGE_FILE_NAME}-install
  COMMAND ${CMAKE_COMMAND} -E echo Stage 3:  Compile using source from
tgz archive.
  COMMAND ${CMAKE_COMMAND} --build
_${CPACK_SOURCE_PACKAGE_FILE_NAME}-build
  )

This can be successfully fired off by make distcheck, which is the desired
behavior.  However, the --build option doesn't respect (naturally) any -jN
options fed to make, since they aren't specified at CMake time when the
distcheck Makefile target is being generated.

Perversely enough, if I'm understanding the issue correctly I won't be able
to use the -jN value itself in any case, even if the Makefile can be taught
to do something smart:
http://old.nabble.com/MAKEFLAGS-var-does-not-show-%22-j%22-param-td15983337.html

The best idea I can come up with so far is for the CMake generated Makefile
to write out a variable containing some CPU related variable (e.g. make
CPUS=8 and write the value of $(CPUS) to CMakeFiles/make_cpu_flag or some
such) and then convert the distcheck commands above into a series of
EXECUTE_PROCESS lines in a rundistcheck.cmake file that is launched by the
distcheck rule with a ${CMAKE_COMMAND}.  In rundistcheck.cmake, I can check
for the presence of the make_cpu_flag file and if found add the -j parallel
flag to the --build line before running it.  That will mean a parallel
distcheck will have to use a different make syntax than the standard make
-j, but at least it would be something.  Unfortunately, that means I still
need the Makefile to let me know what was passed in up front, which means
tweaking the CMake generated output somehow (not really sure how yet).

Does anybody else have a mechanism for passing parallel build instructions
from make down to child ${CMAKE_COMMAND} --build instances?

Cheers,
CY


On Wed, Feb 2, 2011 at 4:32 PM, Michael Hertling mhertl...@online.dewrote:

 On 02/02/2011 03:34 PM, Clifford Yapp wrote:
  Is there any way to customize the Makefile output from CMake to
  include user-defined lines (say, something like #include
  Makefile.inc) at the end of each Make file?


 [snip]


 However, this approach is neither portable nor clean
 nor your-expectation-here, so I would ask Eric's questions, too. ;)

 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

Re: [CMake] Adding a custom line to CMake's makefiles?

2011-09-09 Thread Mike Wittman

If you are building on Linux, try
MAKEFLAGS=j8 make distcheck

I have successfully used the MAKEFLAGS environment variable to propagate 
parallel build invocations through scripts that invoke make with fixed 
options.


-Mike

On 09/09/2011 09:21 AM, Clifford Yapp wrote:
I can finally give a good concrete case where I might need to do this 
(or need some other very clever solution).


I have created a distcheck command for BRL-CAD that has a lot of 
responsibilities, including doing a complete configure and build of 
BRL-CAD from a source archive expanded from a CPack tarball.  The 
distcheck rule uses cmake to fire off the build (this is to try and be 
future proof against using other tools than Make to do a distcheck) 
but I need to pass the parallel build setting -j from Make down to the 
${CMAKE_COMMAND} build launched by the distcheck rule, and there 
doesn't seem to be any way to do it.


This is the subset of the distcheck rule (somewhat edited for clarity):

   ADD_CUSTOM_TARGET(distcheck
  COMMAND ${CMAKE_COMMAND} -E echo Stage 1:  Create source tgz, 
tbz2 and zip archives from toplevel archive.
  COMMAND cpack --config 
${CMAKE_CURRENT_BINARY_DIR}/CPackSourceConfig.cmake
  COMMAND ${CMAKE_COMMAND} -E echo Stage 2:  Expand tgz archive 
and prepare to build from archive sources.
  COMMAND ${CMAKE_COMMAND} -E tar xvzf 
${CPACK_SOURCE_PACKAGE_FILE_NAME}.tar.gz
  COMMAND ${CMAKE_COMMAND} -E make_directory 
_${CPACK_SOURCE_PACKAGE_FILE_NAME}-build
  COMMAND ${CMAKE_COMMAND} -E make_directory 
_${CPACK_SOURCE_PACKAGE_FILE_NAME}-install
  COMMAND ${CMAKE_COMMAND} -E chdir 
_${CPACK_SOURCE_PACKAGE_FILE_NAME}-build ${CMAKE_COMMAND} 
../${CPACK_SOURCE_PACKAGE_FILE_NAME} 
-DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/_${CPACK_SOURCE_PACKAGE_FILE_NAME}-install
  COMMAND ${CMAKE_COMMAND} -E echo Stage 3:  Compile using source 
from tgz archive.
  COMMAND ${CMAKE_COMMAND} --build 
_${CPACK_SOURCE_PACKAGE_FILE_NAME}-build

  )

This can be successfully fired off by make distcheck, which is the 
desired behavior.  However, the --build option doesn't respect 
(naturally) any -jN options fed to make, since they aren't specified 
at CMake time when the distcheck Makefile target is being generated.


Perversely enough, if I'm understanding the issue correctly I won't be 
able to use the -jN value itself in any case, even if the Makefile can 
be taught to do something smart: 
http://old.nabble.com/MAKEFLAGS-var-does-not-show-%22-j%22-param-td15983337.html


The best idea I can come up with so far is for the CMake generated 
Makefile to write out a variable containing some CPU related variable 
(e.g. make CPUS=8 and write the value of $(CPUS) to 
CMakeFiles/make_cpu_flag or some such) and then convert the distcheck 
commands above into a series of EXECUTE_PROCESS lines in a 
rundistcheck.cmake file that is launched by the distcheck rule with a 
${CMAKE_COMMAND}.  In rundistcheck.cmake, I can check for the presence 
of the make_cpu_flag file and if found add the -j parallel flag to the 
--build line before running it.  That will mean a parallel distcheck 
will have to use a different make syntax than the standard make -j, 
but at least it would be something.  Unfortunately, that means I still 
need the Makefile to let me know what was passed in up front, which 
means tweaking the CMake generated output somehow (not really sure how 
yet).


Does anybody else have a mechanism for passing parallel build 
instructions from make down to child ${CMAKE_COMMAND} --build instances?


Cheers,
CY


On Wed, Feb 2, 2011 at 4:32 PM, Michael Hertling mhertl...@online.de 
mailto:mhertl...@online.de wrote:


On 02/02/2011 03:34 PM, Clifford Yapp wrote:
 Is there any way to customize the Makefile output from CMake to
 include user-defined lines (say, something like #include
 Makefile.inc) at the end of each Make file?


 [snip]

However, this approach is neither portable nor clean
nor your-expectation-here, so I would ask Eric's questions, too. ;)

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


___
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] Adding a custom line to CMake's makefiles?

2011-09-09 Thread Jean-Christophe Fillion-Robin
Reading through make documentation, seems setting -jx to MAKEFLAGS is a
no-op.

*The `-j' option is a special case (see section Parallel
Executionhttp://theory.uwinnipeg.ca/localfiles/infofiles/make/make_47.html#SEC46).
If you set it to some numeric value, `-j 1' is always put into
MAKEFLAGSinstead of the value you specified. This is because if the
`-j' option were passed down to sub-makes, you would get many more jobs
running in parallel than you asked for. If you give `-j' with no numeric
argument, meaning to run as many jobs as possible in parallel, this is
passed down, since multiple infinities are no more than one. *

Source: http://theory.uwinnipeg.ca/localfiles/infofiles/make/make_53.html

Jc

On Fri, Sep 9, 2011 at 3:37 PM, Mike Wittman
michael.witt...@headwave.comwrote:

 **
 If you are building on Linux, try
 MAKEFLAGS=j8 make distcheck

 I have successfully used the MAKEFLAGS environment variable to propagate
 parallel build invocations through scripts that invoke make with fixed
 options.

 -Mike


 On 09/09/2011 09:21 AM, Clifford Yapp wrote:

 I can finally give a good concrete case where I might need to do this (or
 need some other very clever solution).

 I have created a distcheck command for BRL-CAD that has a lot of
 responsibilities, including doing a complete configure and build of BRL-CAD
 from a source archive expanded from a CPack tarball.  The distcheck rule
 uses cmake to fire off the build (this is to try and be future proof against
 using other tools than Make to do a distcheck) but I need to pass the
 parallel build setting -j from Make down to the ${CMAKE_COMMAND} build
 launched by the distcheck rule, and there doesn't seem to be any way to do
 it.

 This is the subset of the distcheck rule (somewhat edited for clarity):

ADD_CUSTOM_TARGET(distcheck
   COMMAND ${CMAKE_COMMAND} -E echo Stage 1:  Create source tgz, tbz2
 and zip archives from toplevel archive.
   COMMAND cpack --config
 ${CMAKE_CURRENT_BINARY_DIR}/CPackSourceConfig.cmake
   COMMAND ${CMAKE_COMMAND} -E echo Stage 2:  Expand tgz archive and
 prepare to build from archive sources.
   COMMAND ${CMAKE_COMMAND} -E tar xvzf
 ${CPACK_SOURCE_PACKAGE_FILE_NAME}.tar.gz
   COMMAND ${CMAKE_COMMAND} -E make_directory
 _${CPACK_SOURCE_PACKAGE_FILE_NAME}-build
   COMMAND ${CMAKE_COMMAND} -E make_directory
 _${CPACK_SOURCE_PACKAGE_FILE_NAME}-install
   COMMAND ${CMAKE_COMMAND} -E chdir
 _${CPACK_SOURCE_PACKAGE_FILE_NAME}-build ${CMAKE_COMMAND}
 ../${CPACK_SOURCE_PACKAGE_FILE_NAME}
 -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/_${CPACK_SOURCE_PACKAGE_FILE_NAME}-install
   COMMAND ${CMAKE_COMMAND} -E echo Stage 3:  Compile using source from
 tgz archive.
   COMMAND ${CMAKE_COMMAND} --build
 _${CPACK_SOURCE_PACKAGE_FILE_NAME}-build
   )

 This can be successfully fired off by make distcheck, which is the
 desired behavior.  However, the --build option doesn't respect (naturally)
 any -jN options fed to make, since they aren't specified at CMake time when
 the distcheck Makefile target is being generated.

 Perversely enough, if I'm understanding the issue correctly I won't be able
 to use the -jN value itself in any case, even if the Makefile can be taught
 to do something smart:
 http://old.nabble.com/MAKEFLAGS-var-does-not-show-%22-j%22-param-td15983337.html

 The best idea I can come up with so far is for the CMake generated Makefile
 to write out a variable containing some CPU related variable (e.g. make
 CPUS=8 and write the value of $(CPUS) to CMakeFiles/make_cpu_flag or some
 such) and then convert the distcheck commands above into a series of
 EXECUTE_PROCESS lines in a rundistcheck.cmake file that is launched by the
 distcheck rule with a ${CMAKE_COMMAND}.  In rundistcheck.cmake, I can check
 for the presence of the make_cpu_flag file and if found add the -j parallel
 flag to the --build line before running it.  That will mean a parallel
 distcheck will have to use a different make syntax than the standard make
 -j, but at least it would be something.  Unfortunately, that means I still
 need the Makefile to let me know what was passed in up front, which means
 tweaking the CMake generated output somehow (not really sure how yet).

 Does anybody else have a mechanism for passing parallel build instructions
 from make down to child ${CMAKE_COMMAND} --build instances?

 Cheers,
 CY


 On Wed, Feb 2, 2011 at 4:32 PM, Michael Hertling mhertl...@online.dewrote:

  On 02/02/2011 03:34 PM, Clifford Yapp wrote:
  Is there any way to customize the Makefile output from CMake to
  include user-defined lines (say, something like #include
  Makefile.inc) at the end of each Make file?


  [snip]


 However, this approach is neither portable nor clean
 nor your-expectation-here, so I would ask Eric's questions, too. ;)

 Regards,

 Michael



 ___
 Powered by www.kitware.com


 Visit other Kitware open-source projects at 
 

Re: [CMake] Adding a custom line to CMake's makefiles?

2011-09-09 Thread Mike Wittman
Yes, but only when setting MAKEFLAGS from within a Makefile.  It appears 
the rules do not apply when MAKEFLAGS is set by the invoking shell.  
(And actually, current GNU make handles parallel execution differently 
on Linux, using a job server that all make subprocesses use to 
coordinate execution -- the documentation below is from 1998.)


If you still don't believe :)  try putting the following in a Makefile 
and running MAKEFLAGS=j3 make


all: r1 r2 r3
r1 r2 r3:
echo rule $@; sleep 5

-Mike

On 09/09/2011 02:55 PM, Jean-Christophe Fillion-Robin wrote:
Reading through make documentation, seems setting -jx to MAKEFLAGS is 
a no-op.


/The `-j' option is a special case (see section Parallel Execution 
http://theory.uwinnipeg.ca/localfiles/infofiles/make/make_47.html#SEC46). 
If you set it to some numeric value, `-j 1' is always put into 
|MAKEFLAGS| instead of the value you specified. This is because if the 
`-j' option were passed down to sub-|make|s, you would get many more 
jobs running in parallel than you asked for. If you give `-j' with no 
numeric argument, meaning to run as many jobs as possible in parallel, 
this is passed down, since multiple infinities are no more than one. /


Source: http://theory.uwinnipeg.ca/localfiles/infofiles/make/make_53.html

Jc

On Fri, Sep 9, 2011 at 3:37 PM, Mike Wittman 
michael.witt...@headwave.com mailto:michael.witt...@headwave.com 
wrote:


If you are building on Linux, try
MAKEFLAGS=j8 make distcheck

I have successfully used the MAKEFLAGS environment variable to
propagate parallel build invocations through scripts that invoke
make with fixed options.

-Mike


On 09/09/2011 09:21 AM, Clifford Yapp wrote:

I can finally give a good concrete case where I might need to do
this (or need some other very clever solution).

I have created a distcheck command for BRL-CAD that has a lot of
responsibilities, including doing a complete configure and build
of BRL-CAD from a source archive expanded from a CPack tarball. 
The distcheck rule uses cmake to fire off the build (this is to

try and be future proof against using other tools than Make to do
a distcheck) but I need to pass the parallel build setting -j
from Make down to the ${CMAKE_COMMAND} build launched by the
distcheck rule, and there doesn't seem to be any way to do it.

This is the subset of the distcheck rule (somewhat edited for
clarity):

   ADD_CUSTOM_TARGET(distcheck
  COMMAND ${CMAKE_COMMAND} -E echo Stage 1:  Create source
tgz, tbz2 and zip archives from toplevel archive.
  COMMAND cpack --config
${CMAKE_CURRENT_BINARY_DIR}/CPackSourceConfig.cmake
  COMMAND ${CMAKE_COMMAND} -E echo Stage 2:  Expand tgz
archive and prepare to build from archive sources.
  COMMAND ${CMAKE_COMMAND} -E tar xvzf
${CPACK_SOURCE_PACKAGE_FILE_NAME}.tar.gz
  COMMAND ${CMAKE_COMMAND} -E make_directory
_${CPACK_SOURCE_PACKAGE_FILE_NAME}-build
  COMMAND ${CMAKE_COMMAND} -E make_directory
_${CPACK_SOURCE_PACKAGE_FILE_NAME}-install
  COMMAND ${CMAKE_COMMAND} -E chdir
_${CPACK_SOURCE_PACKAGE_FILE_NAME}-build ${CMAKE_COMMAND}
../${CPACK_SOURCE_PACKAGE_FILE_NAME}

-DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/_${CPACK_SOURCE_PACKAGE_FILE_NAME}-install
  COMMAND ${CMAKE_COMMAND} -E echo Stage 3:  Compile using
source from tgz archive.
  COMMAND ${CMAKE_COMMAND} --build
_${CPACK_SOURCE_PACKAGE_FILE_NAME}-build
  )

This can be successfully fired off by make distcheck, which is
the desired behavior.  However, the --build option doesn't
respect (naturally) any -jN options fed to make, since they
aren't specified at CMake time when the distcheck Makefile target
is being generated.

Perversely enough, if I'm understanding the issue correctly I
won't be able to use the -jN value itself in any case, even if
the Makefile can be taught to do something smart:

http://old.nabble.com/MAKEFLAGS-var-does-not-show-%22-j%22-param-td15983337.html

The best idea I can come up with so far is for the CMake
generated Makefile to write out a variable containing some CPU
related variable (e.g. make CPUS=8 and write the value of $(CPUS)
to CMakeFiles/make_cpu_flag or some such) and then convert the
distcheck commands above into a series of EXECUTE_PROCESS lines
in a rundistcheck.cmake file that is launched by the distcheck
rule with a ${CMAKE_COMMAND}.  In rundistcheck.cmake, I can check
for the presence of the make_cpu_flag file and if found add the
-j parallel flag to the --build line before running it.  That
will mean a parallel distcheck will have to use a different make
syntax than the standard make -j, but at least it would be
something.  Unfortunately, that means I still need the Makefile
to let me know what was passed in up front, which means 

Re: [CMake] Adding a custom line to CMake's makefiles?

2011-09-09 Thread Clifford Yapp
Thanks Mike, good to know!  David actually solved my problem for me with the
generator based conditional and the $(MAKE) variable, but that's a nifty
workaround to have tucked away.

Cheers,
CY

On Fri, Sep 9, 2011 at 3:37 PM, Mike Wittman m...@headwave.com wrote:

 **
 If you are building on Linux, try
 MAKEFLAGS=j8 make distcheck

 I have successfully used the MAKEFLAGS environment variable to propagate
 parallel build invocations through scripts that invoke make with fixed
 options.

 -Mike


___
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] Adding a custom line to CMake's makefiles?

2011-02-02 Thread Michael Hertling
On 02/02/2011 03:34 PM, Clifford Yapp wrote:
 Is there any way to customize the Makefile output from CMake to
 include user-defined lines (say, something like #include
 Makefile.inc) at the end of each Make file?

With GNU Make, you might do the following:

CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR)
PROJECT(INCLUDEMAKEFILE C)
FILE(WRITE ${CMAKE_BINARY_DIR}/main.c int main(void){return 0;}\n)
FILE(WRITE ${CMAKE_BINARY_DIR}/Makefile.inc # Makefile.inc\n)
ADD_CUSTOM_COMMAND(
OUTPUT includemarker
COMMAND ${CMAKE_COMMAND} -E touch includemarker
COMMAND ${CMAKE_COMMAND} -E echo
include ${CMAKE_BINARY_DIR}/Makefile.inc
 \$\(firstword \$\(MAKEFILE_LIST\)\)
)
ADD_EXECUTABLE(main main.c includemarker)

The $(firstword $(MAKEFILE_LIST)) provides access to the currently
processed Makefile, so you can plant additional lines from within a
custom command. However, this approach is neither portable nor clean
nor your-expectation-here, so I would ask Eric's questions, too. ;)

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