|
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1 Hi there, I'm working on a git-versioned project that I'd like to display it's version number for development versions like this: 1.2.3-dev (commit abc1234 on devel, 12/4/10) CMake's FindGit module seems to be quite limited as it just gives me the path to git's executable file, leaving it on me to invoke the necessary EXECUTE_PROCESS() commands to find the current git branch and commit. After some googling, I found this project which added a function GIT_TREE_INFO() that provides information on the current commit: http://trac.evemu.org/browser/trunk/cmake/FindGit.cmake?rev=872 Inspired by this, I wrote another function to get the current branch: FUNCTION(GIT_BRANCH_INFO DIR PREFIX) EXECUTE_PROCESS(COMMAND "${GIT_EXECUTABLE}" branch --no-color WORKING_DIRECTORY "${DIR}" RESULT_VARIABLE GIT_RESULT OUTPUT_VARIABLE GIT_FULL_BRANCH ERROR_VARIABLE GIT_ERROR OUTPUT_STRIP_TRAILING_WHITESPACE) IF(NOT ${GIT_RESULT} EQUAL 0) MESSAGE(SEND_ERROR "Command '${GIT_EXECUTABLE} branch --no-color' failed with following output:\n${GIT_ERROR}") ENDIF(NOT ${GIT_RESULT} EQUAL 0) STRING(REGEX MATCH "^\\* *([^ ]*)$" GIT_ACTIVE_BRANCH "${GIT_FULL_BRANCH}") SET("${PREFIX}_BRANCH" "${CMAKE_MATCH_1}" PARENT_SCOPE) ENDFUNCTION(GIT_BRANCH_INFO) Any chance to get this and the function from the evemu project into official CMake's FindGit.cmake? I'm not sure about their license, but the sourcecode seems to be licensed under LGPL -- if that's too restrictive I can write another function providing the same functionality. Marvin -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAgAGBQJN60X/AAoJELh1XLHFkqhaHpsIAKiJOL1CBXE004WvthoOmJdO iCJFRus8RmGgRaNsQUlBBPiMuXJ0iFRBLK/zsKX4ubk6MXALxy4p4kp1a+bToE8k l/vEmgrxheva6Bx0Qao1hc/7tYDZXcNvG7ZRDEabSuWSWgsQQqEbqIKQ0sK5L1pw uBmXaj/IrJY2u5MO8liq0c/yUF/R39cLa7Hn9MSpf1eXy9QwBsX+HkedrbW0O4Rk pzFTX9hAre9iIfawghLVxV66hitN0letGG4nmRnROmPOjwjSYgxkhAoF+RVqRBoT anVCFjwOrPUfLXERRN9ELFDJjo7NTnOWQ3VFyr8rnY9TaAqnw+2mMftUhUexSFU= =n2I9 -----END PGP SIGNATURE----- _______________________________________________ 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 |
|
Hi,
That's a great idea. I'd like to contribute some function too. I have rewritten a couple of them while working on project versioned by Git. Cheers, -Nico On Sun, Jun 5, 2011 at 11:02 AM, Quintus <[hidden email]> wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Hi there, > > I'm working on a git-versioned project that I'd like to display it's > version number for development versions like this: > > 1.2.3-dev (commit abc1234 on devel, 12/4/10) > > CMake's FindGit module seems to be quite limited as it just gives me the > path to git's executable file, leaving it on me to invoke the necessary > EXECUTE_PROCESS() commands to find the current git branch and commit. > > After some googling, I found this project which added a function > GIT_TREE_INFO() that provides information on the current commit: > http://trac.evemu.org/browser/trunk/cmake/FindGit.cmake?rev=872 > > Inspired by this, I wrote another function to get the current branch: > > FUNCTION(GIT_BRANCH_INFO DIR PREFIX) > EXECUTE_PROCESS(COMMAND "${GIT_EXECUTABLE}" branch --no-color > WORKING_DIRECTORY "${DIR}" > RESULT_VARIABLE GIT_RESULT > OUTPUT_VARIABLE GIT_FULL_BRANCH > ERROR_VARIABLE GIT_ERROR > OUTPUT_STRIP_TRAILING_WHITESPACE) > > IF(NOT ${GIT_RESULT} EQUAL 0) > MESSAGE(SEND_ERROR "Command '${GIT_EXECUTABLE} branch --no-color' > failed with following output:\n${GIT_ERROR}") > ENDIF(NOT ${GIT_RESULT} EQUAL 0) > > STRING(REGEX MATCH "^\\* *([^ ]*)$" > GIT_ACTIVE_BRANCH > "${GIT_FULL_BRANCH}") > > SET("${PREFIX}_BRANCH" "${CMAKE_MATCH_1}" PARENT_SCOPE) > ENDFUNCTION(GIT_BRANCH_INFO) > > Any chance to get this and the function from the evemu project into > official CMake's FindGit.cmake? I'm not sure about their license, but > the sourcecode seems to be licensed under LGPL -- if that's too > restrictive I can write another function providing the same functionality. > > Marvin > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.11 (GNU/Linux) > Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ > > iQEcBAEBAgAGBQJN60X/AAoJELh1XLHFkqhaHpsIAKiJOL1CBXE004WvthoOmJdO > iCJFRus8RmGgRaNsQUlBBPiMuXJ0iFRBLK/zsKX4ubk6MXALxy4p4kp1a+bToE8k > l/vEmgrxheva6Bx0Qao1hc/7tYDZXcNvG7ZRDEabSuWSWgsQQqEbqIKQ0sK5L1pw > uBmXaj/IrJY2u5MO8liq0c/yUF/R39cLa7Hn9MSpf1eXy9QwBsX+HkedrbW0O4Rk > pzFTX9hAre9iIfawghLVxV66hitN0letGG4nmRnROmPOjwjSYgxkhAoF+RVqRBoT > anVCFjwOrPUfLXERRN9ELFDJjo7NTnOWQ3VFyr8rnY9TaAqnw+2mMftUhUexSFU= > =n2I9 > -----END PGP SIGNATURE----- > _______________________________________________ > 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 > -- Nicolas Desprès _______________________________________________ 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 |
|
Hi Folks,
This updated version of FindGit supports both git and git-svn. See http://viewvc.slicer.org/viewvc.cgi/Slicer4/trunk/CMake/FindGit.cmake?revision=16492&view=markup Hth Jc 2011/6/5 Nicolas Desprès <[hidden email]> Hi, -- +1 919 869 8849 _______________________________________________ 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 |
|
In reply to this post by Quintus
On 06/05/2011 05:02 AM, Quintus wrote:
> I'm working on a git-versioned project that I'd like to display it's > version number for development versions like this: > > 1.2.3-dev (commit abc1234 on devel, 12/4/10) FYI, consider using "git describe" for versions. > CMake's FindGit module seems to be quite limited as it just gives me the > path to git's executable file, leaving it on me to invoke the necessary > EXECUTE_PROCESS() commands to find the current git branch and commit. Most Find* modules provide only the basic search results. A few of them try to provide some kind of API to simplify use of the package. This saves a lot of boilerplate CMake code in cases that the same thing appears in many projects. Since Git is so flexible and has so many different ways to work I'm not convinced it makes sense in this case. However, I think getting the current branch will be a fairly common use case. > Inspired by this, I wrote another function to get the current branch: I think the proper way to do this is actually git symbolic-ref -q HEAD which prints out "refs/heads/$branch" or returns non-zero in the case of a detached head. This uses git's plumbing which is meant for machine consumption and will always have a stable API. > Any chance to get this and the function from the evemu project into > official CMake's FindGit.cmake? Our policy for module contributions is documented here: http://www.cmake.org/Wiki/CMake:Module_Maintainers > I'm not sure about their license, but the sourcecode seems to be > licensed under LGPL That is not compatible with CMake's OSI-approved BSD license. -Brad _______________________________________________ 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 |
|
In reply to this post by Quintus
Hello,
Le Sun, 05 Jun 2011 11:02:00 +0200, Quintus <[hidden email]> a écrit : > I'm working on a git-versioned project that I'd like to display it's > version number for development versions like this: > > 1.2.3-dev (commit abc1234 on devel, 12/4/10) For similar need I did something like : execute_process(COMMAND sh ../getlocalversion OUTPUT_VARIABLE MYPROG_VERSION) add_definitions(-DMYPROG_VERSION="${MYPROG_VERSION}") where getlocalversion is a shell script that does : printf "%s%s" $(git rev-parse --verify --short HEAD) $(if test `git diff-index --name-only HEAD | wc -l` -ne 0 ; then echo "-dirty"; fi) However, I am not very happy with this, because the version is determined at configuration time, and not at compile time. Therefore, if I make some changes and commit them to the Git repository without re-doing the CMake configuration step, the program version isn't changed. Any idea on how to make sure that the version of the program is updated at every compilation ? Thanks, Thomas -- Thomas Petazzoni, Free Electrons Kernel, drivers, real-time and embedded Linux development, consulting, training and support. http://free-electrons.com _______________________________________________ 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 |
|
2011/7/12 Thomas Petazzoni <[hidden email]>:
> Hello, > > Le Sun, 05 Jun 2011 11:02:00 +0200, > Quintus <[hidden email]> a écrit : > >> I'm working on a git-versioned project that I'd like to display it's >> version number for development versions like this: >> >> 1.2.3-dev (commit abc1234 on devel, 12/4/10) > > For similar need I did something like : > > execute_process(COMMAND sh ../getlocalversion OUTPUT_VARIABLE MYPROG_VERSION) > add_definitions(-DMYPROG_VERSION="${MYPROG_VERSION}") > > where getlocalversion is a shell script that does : > > printf "%s%s" $(git rev-parse --verify --short HEAD) $(if test `git > diff-index --name-only HEAD | wc -l` -ne 0 ; then echo "-dirty"; fi) > > However, I am not very happy with this, because the version is > determined at configuration time, and not at compile time. Therefore, > if I make some changes and commit them to the Git repository without > re-doing the CMake configuration step, the program version isn't > changed. Any idea on how to make sure that the version of the program > is updated at every compilation ? If you want to execute **build time** scripts you should use add_custom_command/add_custom_target You'll have to make your script create a header that will be included in the concerned source file(s), something like: add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/version.h COMMAND getlocalversion --output ${CMAKE_CURRENT_BINARY_DIR}/version.h) If the script is smart enough not to re-create the file if the version did not change then it should work without too much overhead. If not this will trigger a undue recompilation. if the version.h concerns a single target you could use: add_custom_command(TARGET versionedTarget PRE_BUILD COMMAND getlocalversion --output ${CMAKE_CURRENT_BINARY_DIR}/version.h) this build of the "versionedTarget" should trigger the command. -- Erk Membre de l'April - « promouvoir et défendre le logiciel libre » - http://www.april.org _______________________________________________ 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 |
|
On 07/12/2011 09:35 AM, Eric Noulard wrote:
> 2011/7/12 Thomas Petazzoni <[hidden email]>: >> Hello, >> >> Le Sun, 05 Jun 2011 11:02:00 +0200, >> Quintus <[hidden email]> a écrit : >> >>> I'm working on a git-versioned project that I'd like to display it's >>> version number for development versions like this: >>> >>> 1.2.3-dev (commit abc1234 on devel, 12/4/10) >> >> For similar need I did something like : >> >> execute_process(COMMAND sh ../getlocalversion OUTPUT_VARIABLE MYPROG_VERSION) >> add_definitions(-DMYPROG_VERSION="${MYPROG_VERSION}") >> >> where getlocalversion is a shell script that does : >> >> printf "%s%s" $(git rev-parse --verify --short HEAD) $(if test `git >> diff-index --name-only HEAD | wc -l` -ne 0 ; then echo "-dirty"; fi) >> >> However, I am not very happy with this, because the version is >> determined at configuration time, and not at compile time. Therefore, >> if I make some changes and commit them to the Git repository without >> re-doing the CMake configuration step, the program version isn't >> changed. Any idea on how to make sure that the version of the program >> is updated at every compilation ? > > If you want to execute **build time** scripts you should use > > add_custom_command/add_custom_target > > You'll have to make your script create a header that will be included > in the concerned source file(s), something like: > > add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/version.h > COMMAND getlocalversion --output > ${CMAKE_CURRENT_BINARY_DIR}/version.h) > > If the script is smart enough not to re-create the file if the version > did not change > then it should work without too much overhead. If not this will trigger > a undue recompilation. For the custom command, use a CMake script which (1) invokes the desired git command via EXECUTE_PROCESS() (2) uses the results to convert a version.h.in template to the final version.h header via CONFIGURE_FILE(... @ONLY). The CONFIGURE_FILE() command does not touch its output file if it already exists and wouldn't change, so there won't be unneccesary recompilations. > if the version.h concerns a single target you could use: > > add_custom_command(TARGET versionedTarget > PRE_BUILD > COMMAND getlocalversion --output > ${CMAKE_CURRENT_BINARY_DIR}/version.h) > > this build of the "versionedTarget" should trigger the command. This doesn't work for Makefiles if the version.h header is to be incorporated in the versiondTarget because PRE_BUILD == PRE_LINK, i.e. all of versiondTarget's compilations have already taken place when the custom command is run and regenerates the version.h header. 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 |
|
2011/7/12 Michael Hertling <[hidden email]>:
> On 07/12/2011 09:35 AM, Eric Noulard wrote: >> 2011/7/12 Thomas Petazzoni <[hidden email]>: >>> Hello, >>> >>> Le Sun, 05 Jun 2011 11:02:00 +0200, >>> Quintus <[hidden email]> a écrit : >>> >>>> I'm working on a git-versioned project that I'd like to display it's >>>> version number for development versions like this: >>>> >>>> 1.2.3-dev (commit abc1234 on devel, 12/4/10) >>> >>> For similar need I did something like : >>> >>> execute_process(COMMAND sh ../getlocalversion OUTPUT_VARIABLE MYPROG_VERSION) >>> add_definitions(-DMYPROG_VERSION="${MYPROG_VERSION}") >>> >>> where getlocalversion is a shell script that does : >>> >>> printf "%s%s" $(git rev-parse --verify --short HEAD) $(if test `git >>> diff-index --name-only HEAD | wc -l` -ne 0 ; then echo "-dirty"; fi) >>> >>> However, I am not very happy with this, because the version is >>> determined at configuration time, and not at compile time. Therefore, >>> if I make some changes and commit them to the Git repository without >>> re-doing the CMake configuration step, the program version isn't >>> changed. Any idea on how to make sure that the version of the program >>> is updated at every compilation ? >> >> If you want to execute **build time** scripts you should use >> >> add_custom_command/add_custom_target >> >> You'll have to make your script create a header that will be included >> in the concerned source file(s), something like: >> >> add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/version.h >> COMMAND getlocalversion --output >> ${CMAKE_CURRENT_BINARY_DIR}/version.h) >> >> If the script is smart enough not to re-create the file if the version >> did not change >> then it should work without too much overhead. If not this will trigger >> a undue recompilation. > > For the custom command, use a CMake script which > > (1) invokes the desired git command via EXECUTE_PROCESS() > (2) uses the results to convert a version.h.in template to > the final version.h header via CONFIGURE_FILE(... @ONLY). > > The CONFIGURE_FILE() command does not touch its output file if it > already exists and wouldn't change, so there won't be unneccesary > recompilations. > >> if the version.h concerns a single target you could use: >> >> add_custom_command(TARGET versionedTarget >> PRE_BUILD >> COMMAND getlocalversion --output >> ${CMAKE_CURRENT_BINARY_DIR}/version.h) >> >> this build of the "versionedTarget" should trigger the command. > > This doesn't work for Makefiles if the version.h header is to be > incorporated in the versiondTarget because PRE_BUILD == PRE_LINK, > i.e. all of versiondTarget's compilations have already taken place > when the custom command is run and regenerates the version.h header. Ok then I didn't remember that point, thank you Michael for fixing my mistake. -- Erk Membre de l'April - « promouvoir et défendre le logiciel libre » - http://www.april.org _______________________________________________ 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 Nabble | Edit this page |
