On Mon, Mar 17, 2008 at 7:54 PM, Ittay Dror <[EMAIL PROTECTED]> wrote:
> Hi, > > Does cmake have support for embedding version numbers in libraries and > executables? Specifically: > * generate a string with the library / executable name, containing the > version What do you want to do? Aside from support for the VERSION and SOVERSION target properties on shared libraries (see SET_TARGET_PROPERTIES command) there's really not much for CMake to do here, I think. You can of course use a CMake variable that defines the version of the library/executable that you're building and do whatever you want with it. Some possibilities might be ADD_DEFINITIONS() to define a version number as a preprocessor definition, SET_TARGET_PROPERTIES() on targets to change their names or set versions, tweaking the behavior of the INSTALL() command, etc. > * allow nightly builds to add build number > * add checksum (sha1) to uniquely identify a the library / executable > based on its source files and compilation flags If you're looking to get the revision of your current checkout repository you could use ADD_CUSTOM_TARGET() to extract the relevant information assuming that your CM system has support for revision numbers. Below is one way you can pull the revision number out of subversion (for example) using the svnversion command and use it within your source code (I'm sure someone on here has a cleaner / more platform independent way of doing this). This may be overkill for your needs, it depends on if you need the build number to be available everytime you type "make" or if you just need it at CMake configuration time. The latter is far easier to do via EXECUTE_PROCESS(). In general, CMake does a good job providing the ADD_CUSTOM_COMMAND() and ADD_CUSTOM_TARGET() to allow you to do custom things during your build. You could use the ADD_CUSTOM_COMMAND() with the POST_BUILD option for generating a sha1sum, for example. CMakeLists.txt: ============= CONFIGURE_FILE(dump_svnversion.sh.in dump_svnversion.sh) ADD_CUSTOM_TARGET(OutputSvnVersion ALL ${CMAKE_CURRENT_BINARY_DIR}/dump_svnversion.sh) # allow including the current_svnversion.h file which in this example is generated in the binary directory INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}) SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_BINARY_DIR}/current_svnversion.h PROPERTIES GENERATED true) ADD_EXECUTABLE(foo foo.cc ${CMAKE_CURRENT_BINARY_DIR}/current_svnversion.h) dump_svnversion.sh.in: ================= #!/bin/sh [EMAIL PROTECTED]@/svnversion_tmp echo "#ifndef @[EMAIL PROTECTED]" > $FILE echo "#define @[EMAIL PROTECTED]" >> $FILE echo "#define @[EMAIL PROTECTED] \"`svnversion @[EMAIL PROTECTED]"" >> $FILE echo "#endif" >> $FILE @CMAKE_COMMAND@ -E copy_if_different @CMAKE_CURRENT_BINARY_DIR@/svnversion_tmp @CMAKE_CURRENT_BINARY_DIR@/current_svnversion.h -- Philip Lowman
_______________________________________________ CMake mailing list CMake@cmake.org http://www.cmake.org/mailman/listinfo/cmake