Skip to content

Commit 85ea841

Browse files
committed
CMake for #736
1 parent d95328f commit 85ea841

File tree

8 files changed

+275
-7
lines changed

8 files changed

+275
-7
lines changed
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# - Returns a version string from Git
2+
#
3+
# These functions force a re-configure on each git commit so that you can
4+
# trust the values of the variables in your build system.
5+
#
6+
# get_git_head_revision(<refspecvar> <hashvar> [<additional arguments to git describe> ...])
7+
#
8+
# Returns the refspec and sha hash of the current head revision
9+
#
10+
# git_describe(<var> [<additional arguments to git describe> ...])
11+
#
12+
# Returns the results of git describe on the source tree, and adjusting
13+
# the output so that it tests false if an error occurs.
14+
#
15+
# git_get_exact_tag(<var> [<additional arguments to git describe> ...])
16+
#
17+
# Returns the results of git describe --exact-match on the source tree,
18+
# and adjusting the output so that it tests false if there was no exact
19+
# matching tag.
20+
#
21+
# Requires CMake 2.6 or newer (uses the 'function' command)
22+
#
23+
# Original Author:
24+
# 2009-2010 Ryan Pavlik <[email protected]> <[email protected]>
25+
# http://academic.cleardefinition.com
26+
# Iowa State University HCI Graduate Program/VRAC
27+
#
28+
# Copyright Iowa State University 2009-2010.
29+
# Distributed under the Boost Software License, Version 1.0.
30+
# (See accompanying file LICENSE_1_0.txt or copy at
31+
# http://www.boost.org/LICENSE_1_0.txt)
32+
33+
if(__get_git_revision_description)
34+
return()
35+
endif()
36+
set(__get_git_revision_description YES)
37+
38+
# We must run the following at "include" time, not at function call time,
39+
# to find the path to this module rather than the path to a calling list file
40+
get_filename_component(_gitdescmoddir ${CMAKE_CURRENT_LIST_FILE} PATH)
41+
42+
function(get_git_head_revision _refspecvar _hashvar)
43+
set(GIT_PARENT_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
44+
set(GIT_DIR "${GIT_PARENT_DIR}/.git")
45+
while(NOT EXISTS "${GIT_DIR}") # .git dir not found, search parent directories
46+
set(GIT_PREVIOUS_PARENT "${GIT_PARENT_DIR}")
47+
get_filename_component(GIT_PARENT_DIR ${GIT_PARENT_DIR} PATH)
48+
if(GIT_PARENT_DIR STREQUAL GIT_PREVIOUS_PARENT)
49+
# We have reached the root directory, we are not in git
50+
set(${_refspecvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
51+
set(${_hashvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
52+
return()
53+
endif()
54+
set(GIT_DIR "${GIT_PARENT_DIR}/.git")
55+
endwhile()
56+
# check if this is a submodule
57+
if(NOT IS_DIRECTORY ${GIT_DIR})
58+
file(READ ${GIT_DIR} submodule)
59+
string(REGEX REPLACE "gitdir: (.*)\n$" "\\1" GIT_DIR_RELATIVE ${submodule})
60+
get_filename_component(SUBMODULE_DIR ${GIT_DIR} PATH)
61+
get_filename_component(GIT_DIR ${SUBMODULE_DIR}/${GIT_DIR_RELATIVE} ABSOLUTE)
62+
endif()
63+
set(GIT_DATA "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/git-data")
64+
if(NOT EXISTS "${GIT_DATA}")
65+
file(MAKE_DIRECTORY "${GIT_DATA}")
66+
endif()
67+
68+
if(NOT EXISTS "${GIT_DIR}/HEAD")
69+
return()
70+
endif()
71+
set(HEAD_FILE "${GIT_DATA}/HEAD")
72+
configure_file("${GIT_DIR}/HEAD" "${HEAD_FILE}" COPYONLY)
73+
74+
configure_file("${_gitdescmoddir}/GetGitRevisionDescription.cmake.in"
75+
"${GIT_DATA}/grabRef.cmake"
76+
@ONLY)
77+
include("${GIT_DATA}/grabRef.cmake")
78+
79+
set(${_refspecvar} "${HEAD_REF}" PARENT_SCOPE)
80+
set(${_hashvar} "${HEAD_HASH}" PARENT_SCOPE)
81+
endfunction()
82+
83+
function(git_describe _var)
84+
if(NOT GIT_FOUND)
85+
find_package(Git QUIET)
86+
endif()
87+
get_git_head_revision(refspec hash)
88+
if(NOT GIT_FOUND)
89+
set(${_var} "GIT-NOTFOUND" PARENT_SCOPE)
90+
return()
91+
endif()
92+
if(NOT hash)
93+
set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE)
94+
return()
95+
endif()
96+
97+
# TODO sanitize
98+
#if((${ARGN}" MATCHES "&&") OR
99+
# (ARGN MATCHES "||") OR
100+
# (ARGN MATCHES "\\;"))
101+
# message("Please report the following error to the project!")
102+
# message(FATAL_ERROR "Looks like someone's doing something nefarious with git_describe! Passed arguments ${ARGN}")
103+
#endif()
104+
105+
#message(STATUS "Arguments to execute_process: ${ARGN}")
106+
107+
execute_process(COMMAND
108+
"${GIT_EXECUTABLE}"
109+
describe
110+
${hash}
111+
${ARGN}
112+
WORKING_DIRECTORY
113+
"${CMAKE_SOURCE_DIR}"
114+
RESULT_VARIABLE
115+
res
116+
OUTPUT_VARIABLE
117+
out
118+
ERROR_QUIET
119+
OUTPUT_STRIP_TRAILING_WHITESPACE)
120+
if(NOT res EQUAL 0)
121+
set(out "${out}-${res}-NOTFOUND")
122+
endif()
123+
124+
set(${_var} "${out}" PARENT_SCOPE)
125+
endfunction()
126+
127+
function(git_get_exact_tag _var)
128+
git_describe(out --exact-match ${ARGN})
129+
set(${_var} "${out}" PARENT_SCOPE)
130+
endfunction()
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#
2+
# Internal file for GetGitRevisionDescription.cmake
3+
#
4+
# Requires CMake 2.6 or newer (uses the 'function' command)
5+
#
6+
# Original Author:
7+
# 2009-2010 Ryan Pavlik <[email protected]> <[email protected]>
8+
# http://academic.cleardefinition.com
9+
# Iowa State University HCI Graduate Program/VRAC
10+
#
11+
# Copyright Iowa State University 2009-2010.
12+
# Distributed under the Boost Software License, Version 1.0.
13+
# (See accompanying file LICENSE_1_0.txt or copy at
14+
# http://www.boost.org/LICENSE_1_0.txt)
15+
16+
set(HEAD_HASH)
17+
18+
file(READ "@HEAD_FILE@" HEAD_CONTENTS LIMIT 1024)
19+
20+
string(STRIP "${HEAD_CONTENTS}" HEAD_CONTENTS)
21+
if(HEAD_CONTENTS MATCHES "ref")
22+
# named branch
23+
string(REPLACE "ref: " "" HEAD_REF "${HEAD_CONTENTS}")
24+
if(EXISTS "@GIT_DIR@/${HEAD_REF}")
25+
configure_file("@GIT_DIR@/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY)
26+
elseif(EXISTS "@GIT_DIR@/logs/${HEAD_REF}")
27+
configure_file("@GIT_DIR@/logs/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY)
28+
set(HEAD_HASH "${HEAD_REF}")
29+
endif()
30+
else()
31+
# detached HEAD
32+
configure_file("@GIT_DIR@/HEAD" "@GIT_DATA@/head-ref" COPYONLY)
33+
endif()
34+
35+
if(NOT HEAD_HASH)
36+
file(READ "@GIT_DATA@/head-ref" HEAD_HASH LIMIT 1024)
37+
string(STRIP "${HEAD_HASH}" HEAD_HASH)
38+
endif()

src/CMake/Modules/Version.cc.in

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
For more information, please see: http://software.sci.utah.edu
3+
4+
The MIT License
5+
6+
Copyright (c) 2012 Scientific Computing and Imaging Institute,
7+
University of Utah.
8+
9+
License for the specific language governing rights and limitations under
10+
Permission is hereby granted, free of charge, to any person obtaining a
11+
copy of this software and associated documentation files (the "Software"),
12+
to deal in the Software without restriction, including without limitation
13+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
14+
and/or sell copies of the Software, and to permit persons to whom the
15+
Software is furnished to do so, subject to the following conditions:
16+
17+
The above copyright notice and this permission notice shall be included
18+
in all copies or substantial portions of the Software.
19+
20+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23+
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26+
DEALINGS IN THE SOFTWARE.
27+
*/
28+
29+
#include <Core/Application/version.h>
30+
31+
const std::string GIT_VERSION_TAG = "@VERSION_TAG@";
32+
const std::string GIT_COMMIT_SHA = "@VERSION_HASHVAR@";

src/CMakeLists.txt

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,37 @@ IF (CMAKE_GENERATOR MATCHES "Unix Makefiles" AND NOT CMAKE_BUILD_TYPE)
7777
SET(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." FORCE)
7878
ENDIF (CMAKE_GENERATOR MATCHES "Unix Makefiles" AND NOT CMAKE_BUILD_TYPE)
7979

80+
########################################################################
81+
# Git revision details
82+
83+
# Appends the cmake/modules path to MAKE_MODULE_PATH variable.
84+
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/CMake/Modules ${CMAKE_MODULE_PATH})
85+
86+
# Make a version file containing the current version from git.
87+
include(GetGitRevisionDescription)
88+
git_describe(VERSION_TAG --tag)
89+
git_describe(VERSION_BRANCH --all)
90+
get_git_head_revision(VERSION_REFSPEC VERSION_HASHVAR)
91+
92+
MESSAGE(STATUS "Git version tag: " "${VERSION_TAG}")
93+
MESSAGE(STATUS "Git version branch: " "${VERSION_BRANCH}")
94+
MESSAGE(STATUS "Git version commit hash: " "${VERSION_HASHVAR}")
95+
96+
#TODO: parse the version information into pieces.
97+
#string(REGEX REPLACE "^v([0-9]+)\\..*" "\\1" VERSION_MAJOR "${VERSION}")
98+
#string(REGEX REPLACE "^v[0-9]+\\.([0-9]+).*" "\\1" VERSION_MINOR "${VERSION}")
99+
#string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" VERSION_PATCH "${VERSION}")
100+
#string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.[0-9]+(.*)" "\\1" VERSION_SHA1 "${VERSION}")
101+
#set(VERSION_SHORT "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
102+
103+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/Version.cc.in
104+
${CMAKE_CURRENT_SOURCE_DIR}/Core/Application/Version.cc)
105+
set(version_file "${CMAKE_CURRENT_SOURCE_DIR}/Core/Application/Version.cc")
106+
80107

81108
########################################################################
82109
# SCIRUN version number.
110+
# TODO: update using parsed tag from above
83111

84112
SET(SCIRUN_VERSION_MAJOR "5")
85113
SET(SCIRUN_VERSION_MINOR "0")
@@ -290,11 +318,12 @@ IF(WITH_TETGEN)
290318
ADD_DEFINITIONS(-DWITH_TETGEN)
291319
ENDIF(WITH_TETGEN)
292320

293-
294321
########################################################################
295322
# Configure CPM and Spire - http://github.com/iauns/cpm
296323
# Configure CPM and Spire - http://github.com/CIBC-Internal/cpm
297324

325+
MESSAGE(STATUS "Configuring CPMs")
326+
298327
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
299328

300329
# CPM Setup.
@@ -316,7 +345,7 @@ endif()
316345
include(${CPM_DIR}/CPM.cmake)
317346

318347
# TODO: Add tags for *all* of the CPM modules. This will allow upstream
319-
# flexibility. Once all versions are appopriately tagged, I will be able
348+
# flexibility. Once all versions are appropriately tagged, I will be able
320349
# to untag upstream and keep it moving forward.
321350

322351
# ++ MODULE: GL Platform
@@ -391,6 +420,8 @@ CPM_AddModule("bserialize"
391420

392421
CPM_Finish()
393422

423+
MESSAGE(STATUS "Done configuring CPMs")
424+
394425
########################################################################
395426
# Copy Spire-SCIRun specific assets and shaders
396427

@@ -775,8 +806,6 @@ ENDIF()
775806
########################################################################
776807
# Custom CMake settings for CPack
777808

778-
SET(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake/Modules")
779-
780809
########################################################################
781810
# CPack
782811

src/Core/Application/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Version.cc

src/Core/Application/Application.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include <Core/IEPlugin/IEPluginInit.h>
4242
#include <Core/Utils/Exception.h>
4343
#include <Core/Application/Session/Session.h>
44+
#include <Core/Application/Version.h>
4445

4546
using namespace SCIRun::Core;
4647
using namespace SCIRun::Core::Logging;
@@ -172,9 +173,7 @@ std::string Application::commandHelpString() const
172173

173174
std::string Application::version() const
174175
{
175-
/// @todo:
176-
///return CORE_APPLICATION_VERSION;
177-
return "5.0.0 developer version";
176+
return GIT_VERSION_TAG.empty() ? "5.0.0 developer version" : GIT_VERSION_TAG;
178177
}
179178

180179
boost::filesystem::path Application::configDirectory() const

src/Core/Application/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@
2828

2929
SET(Core_Application_SRCS
3030
Application.cc
31+
${version_file}
3132
)
3233

3334
SET(Core_Application_HEADERS
3435
Application.h
36+
Version.h
3537
share.h
3638
)
3739

src/Core/Application/Version.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
For more information, please see: http://software.sci.utah.edu
3+
4+
The MIT License
5+
6+
Copyright (c) 2012 Scientific Computing and Imaging Institute,
7+
University of Utah.
8+
9+
License for the specific language governing rights and limitations under
10+
Permission is hereby granted, free of charge, to any person obtaining a
11+
copy of this software and associated documentation files (the "Software"),
12+
to deal in the Software without restriction, including without limitation
13+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
14+
and/or sell copies of the Software, and to permit persons to whom the
15+
Software is furnished to do so, subject to the following conditions:
16+
17+
The above copyright notice and this permission notice shall be included
18+
in all copies or substantial portions of the Software.
19+
20+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23+
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26+
DEALINGS IN THE SOFTWARE.
27+
*/
28+
29+
#ifndef SCIRUN_GIT_VERSION_H
30+
#define SCIRUN_GIT_VERSION_H
31+
32+
#include <string>
33+
34+
extern const std::string GIT_VERSION_TAG;
35+
extern const std::string GIT_COMMIT_SHA;
36+
37+
#endif

0 commit comments

Comments
 (0)