[Cmake] Two (related) questions

Andy Cedilnik andy.cedilnik at kitware.com
Tue Aug 27 11:04:22 EDT 2002


Oh, I see what you are trying to do...
You do this like this:

SET(FOO_LIB_SUFFIX ${CMAKE_SHLIB_SUFFIX})
SET(FOO_LIB_PREFIX "lib")
IF(WIN32)
  IF(NOT CYGWIN)
    SET(FOO_LIB_PREFIX "")
    SET(FOO_LIB_SUFFIX ".dll")
  ENDIF(NOT CYGWIN)
ENDIF(WIN32)

SET(FOO_LIB_NAME ${FOO_LIB_PREFIX}Foo${FOO_LIB_SUFFIX})

ADD_CUSTOM_COMMAND( 
  SOURCE Foo
  COMMAND ${CMAKE_COMMAND}
  ARGS -E copy
  ${FOO_OUTPUT_PATH}/${CMAKE_CFG_INTDIR}/${FOO_LIB_NAME}
 
${FOO_OUTPUT_PATH}/${CMAKE_CFG_INTDIR}/${FOO_LIB_PREFIX}Bar${FOO_LIB_SUFFIX}
  TARGET Foo )

This will take library on any platform and rename it to Bar, for example
on Linux it will take libFoo.so and rename it to libBar.so.

				Andy

On Tue, 2002-08-27 at 10:50, Andy Cedilnik wrote:
> Hi Geoffrey,
> 
> There are two good sources to figure that out in VTK (if you have
> source):
> 1. vtktiff (VTK/Utilities/tiff)
>    uses ADD_CUSTOM_COMMAND to run a binary that is being created by
>    build process and generate a source code that is then used in 
>    the rest of the build
> 
> ADD_CUSTOM_COMMAND(
>       SOURCE ${EXECUTABLE_OUTPUT_PATH}/mkg3states
>       COMMAND ${EXECUTABLE_OUTPUT_PATH}/mkg3states
>       ARGS -c const ${VTKTIFF_BINARY_DIR}/tif_fax3sm.c
>       TARGET mkg3states
>       OUTPUTS ${VTKTIFF_BINARY_DIR}/tif_fax3sm.c)
> 
> 2. VTKJava (VTK/Wrapping/Java)
>    uses it to build java classes even though CMake does not support that
>    directly:
> 
>   ADD_CUSTOM_COMMAND(SOURCE VTKJava
>                      COMMAND ${JAVA_COMPILE} 
> 		     ARGS ${VTK_BINARY_DIR}/java/vtk/vtk*.java
>                      TARGET VTKJava
> 		     OUTPUTS ${VTK_BINARY_DIR}/java/vtk/vtkObject.class)
>   ADD_CUSTOM_COMMAND(SOURCE VTKJava
> 	             COMMAND ${CMAKE_COMMAND}
>                      ARGS -E chdir 
>                             ${VTK_BINARY_DIR}/java ${JAVA_ARCHIVE}
>                             -cvf ${LIBRARY_OUTPUT_PATH}/vtk.jar
>                             vtk
> 		       TARGET VTKJava
> 		       OUTPUTS ${LIBRARY_OUTPUT_PATH}/vtk.jar)
> 
> So, in general, what this is:
> 
>  SOURCE - something that will be build to trigger this command
>  COMMAND - command that will be executed
>  ARGS - arguments for command
>  TARGET - target which the command will be part of 
>  OUTPUTS - what the command generates
> 
> 				Andy
> 
> On Tue, 2002-08-27 at 10:09, Geoffrey Cross wrote:
> > 
> > 
> > > For the renaming problem, you can use a custom command to copy the
> > > shared library after it is built to a new name.
> > 
> > How does this ADD_CUSTOM_COMMAND thing work?  The documentation baffles
> > me... :).





More information about the CMake mailing list